diff --git a/.gitignore b/.gitignore index b6bd966..5116fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Generated by Cargo # will have compiled files and executables -/target/ +**/target/ # These are backup files generated by rustfmt **/*.rs.bk \ No newline at end of file diff --git a/rebuild_expected_outputs.sh b/rebuild_expected_outputs.sh index afd6d6a..e57b2a2 100755 --- a/rebuild_expected_outputs.sh +++ b/rebuild_expected_outputs.sh @@ -6,7 +6,8 @@ do if [[ "$f" == 'src/test_inputs/compile_fail.json' ]]; then continue; fi if [[ "$f" == 'src/test_inputs/float_time.json' ]]; then continue; fi if [[ "$f" == 'src/test_inputs/one_suite_no_tests.json' ]]; then continue; fi - cargo run < "$f" > "${f%.json}.out" || ( echo $f | grep "fail" ) + if [[ "$f" == 'src/test_inputs/unknown_type.json' ]]; then continue; fi + cargo run < "$f" > "${f%.json}.out" || true done; mv src/test_inputs/*.out src/expected_outputs/ diff --git a/regenerate_test_inputs.sh b/regenerate_test_inputs.sh new file mode 100755 index 0000000..fd3c530 --- /dev/null +++ b/regenerate_test_inputs.sh @@ -0,0 +1,8 @@ +set -e +set -x + +for f in test_input_generators/*; +do + echo + RUSTC_BOOTSTRAP=1 cargo test --manifest-path $f/Cargo.toml -- -Z unstable-options --format json --report-time > src/test_inputs/"${f##*/}".json || true +done; diff --git a/src/expected_outputs/doctests_edition2024.out b/src/expected_outputs/doctests_edition2024.out new file mode 100644 index 0000000..5101057 --- /dev/null +++ b/src/expected_outputs/doctests_edition2024.out @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + diff --git a/src/main.rs b/src/main.rs index f41d550..94949e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,6 +89,11 @@ enum Event { duration: Option, exec_time: Option, }, + #[serde(rename = "report")] + DoctestsReport { + total_time: f64, + compilation_time: f64, + } } impl Event { @@ -120,7 +125,8 @@ impl Event { }; Duration::nanoseconds(duration_ns) - } + }, + Event::DoctestsReport { .. } => panic!(), } } } @@ -273,6 +279,12 @@ fn parse( } current_suite_maybe = Some(current_suite); + }, + Event::DoctestsReport { .. } => { + // This is an informative event that's emitted after a doctests binary is done executing. + // Aside from a bespoke way of compiling into a single binary, doctests are not special + // and produce all the same events as the regular tests. We thus should have all the required + // information already and can ignore this event. } } } @@ -545,4 +557,14 @@ mod tests { assert!(determine_exit_code(&report).is_ok()); } + + #[test] + fn doctests_edition2024() { + let report = parse_bytes( + include_bytes!("test_inputs/doctests_edition2024.json"), + SYSTEM_OUT_MAX_LEN, + ) + .expect("Could not parse test input"); + assert_output(&report, include_bytes!("expected_outputs/doctests_edition2024.out")); + } } diff --git a/src/test_inputs/doctests_edition2024.json b/src/test_inputs/doctests_edition2024.json new file mode 100644 index 0000000..62ff5d0 --- /dev/null +++ b/src/test_inputs/doctests_edition2024.json @@ -0,0 +1,15 @@ +{ "type": "suite", "event": "started", "test_count": 0 } +{ "type": "suite", "event": "ok", "passed": 0, "failed": 0, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000110368 } +{ "type": "suite", "event": "started", "test_count": 0 } +{ "type": "suite", "event": "ok", "passed": 0, "failed": 0, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000061506 } +{ "type": "suite", "event": "started", "test_count": 4 } +{ "type": "test", "event": "started", "name": "src/lib.rs - foo (line 11)" } +{ "type": "test", "event": "started", "name": "src/lib.rs - foo (line 15)" } +{ "type": "test", "event": "started", "name": "src/lib.rs - foo (line 2)" } +{ "type": "test", "event": "started", "name": "src/lib.rs - foo (line 7)" } +{ "type": "test", "name": "src/lib.rs - foo (line 15)", "event": "ignored" } +{ "type": "test", "name": "src/lib.rs - foo (line 2)", "event": "ok", "exec_time": 0.001401198 } +{ "type": "test", "name": "src/lib.rs - foo (line 7)", "event": "failed", "exec_time": 0.058641184, "stdout": "Test executable failed (exit status: 101).\n\nstderr:\n\nthread 'main' (3272617) panicked at /tmp/rustdoctestzqkU8w/doctest_bundle_2024.rs:24:1:\nassertion `left == right` failed\n left: 1\n right: 2\nstack backtrace:\n 0: __rustc::rust_begin_unwind\n at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5\n 1: core::panicking::panic_fmt\n at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14\n 2: core::panicking::assert_failed_inner\n at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:444:17\n 3: core::panicking::assert_failed\n at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:399:5\n 4: doctest_bundle_2024::__doctest_3::main\n 5: doctest_bundle_2024::__doctest_3::__main_fn\n 6: doctest_runner_2024::__doctest_3::TEST::{{closure}}\n 7: core::ops::function::FnOnce::call_once\n 8: doctest_runner_2024::main\n 9: core::ops::function::FnOnce::call_once\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n\n" } +{ "type": "test", "name": "src/lib.rs - foo (line 11)", "event": "ok", "exec_time": 0.059067266 } +{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": 0.059319241 } +{ "type": "report", "total_time": 0.225519393, "compilation_time": 0.162774902 } diff --git a/test_input_generators/doctests_edition2024/Cargo.lock b/test_input_generators/doctests_edition2024/Cargo.lock new file mode 100644 index 0000000..1ef4445 --- /dev/null +++ b/test_input_generators/doctests_edition2024/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "doctests_edition2024" +version = "0.1.0" diff --git a/test_input_generators/doctests_edition2024/Cargo.toml b/test_input_generators/doctests_edition2024/Cargo.toml new file mode 100644 index 0000000..b2a84f3 --- /dev/null +++ b/test_input_generators/doctests_edition2024/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "doctests_edition2024" +version = "0.1.0" + +# Since Rust edition 2024, rustdoc combines doctests into a single binary: +# https://doc.rust-lang.org/edition-guide/rust-2024/rustdoc-doctests.html +# +# When it does so, it also produces `{ "type": "report" ... }` events after +# the doctests are run. We are using edition 2024 here to generate test input +# that contains such events. +edition = "2024" + +[dependencies] diff --git a/test_input_generators/doctests_edition2024/src/lib.rs b/test_input_generators/doctests_edition2024/src/lib.rs new file mode 100644 index 0000000..25c9c18 --- /dev/null +++ b/test_input_generators/doctests_edition2024/src/lib.rs @@ -0,0 +1,18 @@ +/// Pass: +/// ``` +/// assert_eq!(1, 1) +/// ``` +/// +/// Fail: +/// ``` +/// assert_eq!(1, 2) +/// ``` +/// +/// ```should_panic +/// assert_eq!(2, 1) +/// ``` +/// +/// ```ignore +/// assert_eq!(2, 1) +/// ``` +pub fn foo() {} diff --git a/test_input_generators/doctests_edition2024/src/main.rs b/test_input_generators/doctests_edition2024/src/main.rs new file mode 100644 index 0000000..f328e4d --- /dev/null +++ b/test_input_generators/doctests_edition2024/src/main.rs @@ -0,0 +1 @@ +fn main() {}