From d8c2a863aa98bbb252b410b8589b913345178141 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 11 Sep 2025 10:17:43 -0500 Subject: [PATCH] fix(harness)!: Always include json support --- crates/libtest2-harness/Cargo.toml | 3 +-- crates/libtest2-harness/src/harness.rs | 20 ++++--------------- crates/libtest2-harness/src/lib.rs | 2 +- crates/libtest2-harness/src/notify/mod.rs | 2 -- crates/libtest2-mimic/Cargo.toml | 3 +-- .../tests/testsuite/mixed_bag.rs | 3 --- crates/libtest2/Cargo.toml | 3 +-- crates/libtest2/tests/testsuite/mixed_bag.rs | 3 --- 8 files changed, 8 insertions(+), 31 deletions(-) diff --git a/crates/libtest2-harness/Cargo.toml b/crates/libtest2-harness/Cargo.toml index 4b47223..b5c4e1e 100644 --- a/crates/libtest2-harness/Cargo.toml +++ b/crates/libtest2-harness/Cargo.toml @@ -26,7 +26,6 @@ pre-release-replacements = [ [features] default = [] color = ["dep:anstream", "dep:anstyle"] -json = ["libtest-json/json"] threads = [] [dependencies] @@ -35,7 +34,7 @@ lexarg-error = { version = "0.0.1", path = "../lexarg-error" } libtest-lexarg = { version = "0.0.1", path = "../libtest-lexarg" } anstream = { version = "0.6.4", optional = true } anstyle = { version = "1.0.10", optional = true } -libtest-json = { version = "0.0.1", path = "../libtest-json" } +libtest-json = { version = "0.0.1", path = "../libtest-json", features = ["json"] } [dev-dependencies] diff --git a/crates/libtest2-harness/src/harness.rs b/crates/libtest2-harness/src/harness.rs index 60e384f..3a4e325 100644 --- a/crates/libtest2-harness/src/harness.rs +++ b/crates/libtest2-harness/src/harness.rs @@ -68,10 +68,7 @@ impl Harness { } .write_global(); - let notifier = notifier(&opts).unwrap_or_else(|err| { - eprintln!("{err}"); - std::process::exit(1) - }); + let notifier = notifier(&opts); Ok(Harness { state: StateParsed { @@ -228,26 +225,17 @@ fn parse_argfile(path: &std::path::Path) -> std::io::Result std::io::Result> { +fn notifier(opts: &libtest_lexarg::TestOpts) -> Box { #[cfg(feature = "color")] let stdout = anstream::stdout(); #[cfg(not(feature = "color"))] let stdout = std::io::stdout(); - let notifier: Box = match opts.format { - #[cfg(feature = "json")] + match opts.format { OutputFormat::Json => Box::new(notify::JsonNotifier::new(stdout)), - #[cfg(not(feature = "json"))] - OutputFormat::Json => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "`--format=json` is not supported", - )); - } _ if opts.list => Box::new(notify::TerseListNotifier::new(stdout)), OutputFormat::Pretty => Box::new(notify::PrettyRunNotifier::new(stdout)), OutputFormat::Terse => Box::new(notify::TerseRunNotifier::new(stdout)), - }; - Ok(notifier) + } } fn discover( diff --git a/crates/libtest2-harness/src/lib.rs b/crates/libtest2-harness/src/lib.rs index 196b2bb..4f6e57b 100644 --- a/crates/libtest2-harness/src/lib.rs +++ b/crates/libtest2-harness/src/lib.rs @@ -1,7 +1,7 @@ //! An experimental replacement for the core of libtest #![cfg_attr(docsrs, feature(doc_auto_cfg))] -// #![warn(clippy::print_stderr)] +#![warn(clippy::print_stderr)] // #![warn(clippy::print_stdout)] mod case; diff --git a/crates/libtest2-harness/src/notify/mod.rs b/crates/libtest2-harness/src/notify/mod.rs index d387368..23c4a91 100644 --- a/crates/libtest2-harness/src/notify/mod.rs +++ b/crates/libtest2-harness/src/notify/mod.rs @@ -1,4 +1,3 @@ -#[cfg(feature = "json")] mod json; #[cfg(not(feature = "color"))] mod no_style; @@ -8,7 +7,6 @@ mod style; mod summary; mod terse; -#[cfg(feature = "json")] pub(crate) use json::*; #[cfg(not(feature = "color"))] pub(crate) use no_style::*; diff --git a/crates/libtest2-mimic/Cargo.toml b/crates/libtest2-mimic/Cargo.toml index 0cdda45..0d0b301 100644 --- a/crates/libtest2-mimic/Cargo.toml +++ b/crates/libtest2-mimic/Cargo.toml @@ -24,9 +24,8 @@ pre-release-replacements = [ ] [features] -default = ["color", "json", "threads"] +default = ["color", "threads"] color = ["libtest2-harness/color"] -json = ["libtest2-harness/json"] threads = ["libtest2-harness/threads"] [dependencies] diff --git a/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs b/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs index 9ca3ceb..1d124ee 100644 --- a/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs +++ b/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs @@ -698,7 +698,6 @@ test result: FAILED. 1 passed; 1 failed; 0 ignored; 6 filtered out; finished in } #[test] -#[cfg(feature = "json")] fn list_json() { check( &["-Zunstable-options", "--format=json", "--list", "a"], @@ -827,7 +826,6 @@ fn list_json() { } #[test] -#[cfg(feature = "json")] fn test_json() { check( &["-Zunstable-options", "--format=json", "a"], @@ -1102,7 +1100,6 @@ test result: FAILED. 1 passed; 1 failed; 2 ignored; 0 filtered out; finished in } #[test] -#[cfg(feature = "json")] fn fail_fast_json() { check( &["-Zunstable-options", "--format=json", "--fail-fast"], diff --git a/crates/libtest2/Cargo.toml b/crates/libtest2/Cargo.toml index dbcbf5d..4367e15 100644 --- a/crates/libtest2/Cargo.toml +++ b/crates/libtest2/Cargo.toml @@ -24,9 +24,8 @@ pre-release-replacements = [ ] [features] -default = ["color", "json", "threads"] +default = ["color", "threads"] color = ["libtest2-harness/color"] -json = ["libtest2-harness/json"] threads = ["libtest2-harness/threads"] [dependencies] diff --git a/crates/libtest2/tests/testsuite/mixed_bag.rs b/crates/libtest2/tests/testsuite/mixed_bag.rs index 8c9658e..054b762 100644 --- a/crates/libtest2/tests/testsuite/mixed_bag.rs +++ b/crates/libtest2/tests/testsuite/mixed_bag.rs @@ -705,7 +705,6 @@ test result: FAILED. 1 passed; 1 failed; 0 ignored; 6 filtered out; finished in } #[test] -#[cfg(feature = "json")] fn list_json() { check( &["-Zunstable-options", "--format=json", "--list", "a"], @@ -834,7 +833,6 @@ fn list_json() { } #[test] -#[cfg(feature = "json")] fn test_json() { check( &["-Zunstable-options", "--format=json", "a"], @@ -1109,7 +1107,6 @@ test result: FAILED. 1 passed; 1 failed; 2 ignored; 0 filtered out; finished in } #[test] -#[cfg(feature = "json")] fn fail_fast_json() { check( &["-Zunstable-options", "--format=json", "--fail-fast"],