Skip to content

Commit 23ac870

Browse files
committed
fix(harness): Make color support optional
1 parent a22ed8e commit 23ac870

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

crates/libtest2-harness/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ pre-release-replacements = [
2525

2626
[features]
2727
default = []
28+
color = ["dep:anstream", "dep:anstyle"]
2829
json = ["dep:serde", "dep:serde_json"]
2930
junit = []
3031
threads = []
3132

3233
[dependencies]
33-
anstream = "0.6.4"
34-
anstyle = "1.0.10"
3534
lexarg-parser = { version = "0.1.0", path = "../lexarg-parser" }
3635
lexarg-error = { version = "0.1.0", path = "../lexarg-error" }
3736
libtest-lexarg = { version = "0.1.0", path = "../libtest-lexarg" }
37+
anstream = { version = "0.6.4", optional = true }
38+
anstyle = { version = "1.0.10", optional = true }
3839
serde = { version = "1.0.160", features = ["derive"], optional = true }
3940
serde_json = { version = "1.0.96", optional = true }
4041

crates/libtest2-harness/src/harness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl Harness {
3737
std::process::exit(1)
3838
});
3939

40+
#[cfg(feature = "color")]
4041
match opts.color {
4142
libtest_lexarg::ColorConfig::AutoColor => anstream::ColorChoice::Auto,
4243
libtest_lexarg::ColorConfig::AlwaysColor => anstream::ColorChoice::Always,
@@ -131,7 +132,10 @@ fn parse<'p>(
131132
}
132133

133134
fn notifier(opts: &libtest_lexarg::TestOpts) -> std::io::Result<Box<dyn notify::Notifier>> {
135+
#[cfg(feature = "color")]
134136
let stdout = anstream::stdout();
137+
#[cfg(not(feature = "color"))]
138+
let stdout = std::io::stdout();
135139
let notifier: Box<dyn notify::Notifier> = match opts.format {
136140
#[cfg(feature = "json")]
137141
OutputFormat::Json => Box::new(notify::JsonNotifier::new(stdout)),

crates/libtest2-harness/src/notify/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
mod json;
33
#[cfg(feature = "junit")]
44
mod junit;
5+
#[cfg(not(feature = "color"))]
6+
mod no_style;
57
mod pretty;
8+
#[cfg(feature = "color")]
69
mod style;
710
mod summary;
811
mod terse;
@@ -11,7 +14,10 @@ mod terse;
1114
pub(crate) use json::*;
1215
#[cfg(feature = "junit")]
1316
pub(crate) use junit::*;
17+
#[cfg(not(feature = "color"))]
18+
pub(crate) use no_style::*;
1419
pub(crate) use pretty::*;
20+
#[cfg(feature = "color")]
1521
pub(crate) use style::*;
1622
pub(crate) use summary::*;
1723
pub(crate) use terse::*;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub(crate) struct Style;
2+
3+
impl std::fmt::Display for Style {
4+
fn fmt(&self, _formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5+
Ok(())
6+
}
7+
}
8+
9+
pub(crate) const FAILED: Style = Style;
10+
pub(crate) const OK: Style = Style;
11+
pub(crate) const IGNORED: Style = Style;

crates/libtest2-mimic/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pre-release-replacements = [
2424
]
2525

2626
[features]
27-
default = ["json", "junit", "threads"]
27+
default = ["color", "json", "junit", "threads"]
28+
color = ["libtest2-harness/color"]
2829
json = ["libtest2-harness/json"]
2930
junit = ["libtest2-harness/junit"]
3031
threads = ["libtest2-harness/threads"]

crates/libtest2/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pre-release-replacements = [
2424
]
2525

2626
[features]
27-
default = ["json", "junit", "threads"]
27+
default = ["color", "json", "junit", "threads"]
28+
color = ["libtest2-harness/color"]
2829
json = ["libtest2-harness/json"]
2930
junit = ["libtest2-harness/junit"]
3031
threads = ["libtest2-harness/threads"]

0 commit comments

Comments
 (0)