Skip to content

Commit

Permalink
Add integration test for channel-based logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
daboross committed Sep 20, 2017
1 parent 2ed6d10 commit 0ef1e21
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,8 @@ before_script:
- export PATH="$PATH:$HOME/.cargo/bin"
script:
- cargo build --verbose
- cargo test --verbose -- --skip test2
- cargo test --verbose -- --skip test2 --skip test3
- cargo test test2
- cargo test test3
- cargo run --example cmd-program
- cargo run --example cmd-program -- --verbose
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 43,12 @@ There aren't many hard guidelines in this repository on how specifically to form

Building fern is as easy as is expected, `cargo build`.

Testing is somewhat more convoluted - mostly because using fern requires initializing a global logger. To test the two "integration" tests separately, you'll need to invoke two commands:
Testing is somewhat more convoluted - mostly because using fern requires initializing a global logger. To test the three "integration" tests separately, you'll need to invoke three commands:

```sh
cargo test -- --skip test2
cargo test -- --skip test2 --skip test3
cargo test test2
cargo test test3
```

To run the example program, use:
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 53,9 @@ install:

test_script:
- cargo build --verbose
- cargo test --verbose -- --skip test2
- cargo test --verbose -- --skip test2 --skip test3
- cargo test test2
- cargo test test3
- cargo run --example cmd-program
- cargo run --example cmd-program -- --verbose

Expand Down
20 changes: 20 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 116,23 @@ fn test2_line_seps() {
.close()
.expect("Failed to clean up temporary directory");
}

#[test]
fn test3_channel_logging() {
use std::sync::mpsc;
// Create the channel
let (send, recv) = mpsc::channel();

fern::Dispatch::new()
.chain(send)
.apply()
.expect("Failed to initialize logger: global logger already set!");

info!("message1");
info!("message2");

log::shutdown_logger().expect("Failed to shutdown logger");

assert_eq!(recv.recv().unwrap(), "message1\n");
assert_eq!(recv.recv().unwrap(), "message2\n");
}

0 comments on commit 0ef1e21

Please sign in to comment.