Skip to content

Commit 2c2d594

Browse files
committed
Add test test_discovery_logfile_format().
1 parent 046451b commit 2c2d594

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

library/test/src/tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::PathBuf;
55
use super::*;
66

77
use crate::{
8+
console::list_tests_console,
89
console::OutputLocation,
910
formatters::PrettyFormatter,
1011
test::{
@@ -957,6 +958,46 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() {
957958
assert_eq!(result, TrFailed);
958959
}
959960

961+
#[test]
962+
fn test_discovery_logfile_format() {
963+
let desc = TestDescAndFn {
964+
desc: TestDesc {
965+
name: StaticTestName("whatever"),
966+
ignore: false,
967+
ignore_message: None,
968+
source_file: "",
969+
start_line: 0,
970+
start_col: 0,
971+
end_line: 0,
972+
end_col: 0,
973+
should_panic: ShouldPanic::No,
974+
compile_fail: false,
975+
no_run: false,
976+
test_type: TestType::Unknown,
977+
},
978+
testfn: DynTestFn(Box::new(move || Ok(()))),
979+
};
980+
981+
let tmpdir = tmpdir();
982+
let output_path = &tmpdir.join("output.txt");
983+
984+
let opts = TestOpts {
985+
run_tests: true,
986+
logfile: Some(output_path.clone()),
987+
format: OutputFormat::Pretty,
988+
list: true,
989+
..TestOpts::new()
990+
};
991+
list_tests_console(&opts, vec![desc]).unwrap();
992+
993+
let contents = fs::read_to_string(output_path).expect("`--logfile` did not create file");
994+
995+
// Split output at line breaks to make the comparison platform-agnostic regarding newline style.
996+
let contents_lines = contents.as_str().lines().collect::<Vec<&str>>();
997+
998+
assert_eq!(contents_lines, vec!["test whatever"]);
999+
}
1000+
9601001
#[test]
9611002
fn test_logfile_format() {
9621003
let desc = TestDescAndFn {

0 commit comments

Comments
 (0)