From ccaac9ae012bc46b53c2f9d1713e4690a170e438 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Mar 2023 04:24:27 -0500 Subject: [PATCH 1/2] chore: Update MSRV to 1.64.0 --- .clippy.toml | 2 +- .github/workflows/ci.yml | 6 +++--- .github/workflows/rust-next.yml | 4 ++-- Cargo.toml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 23bf481..23fc604 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.60.0" # MSRV +msrv = "1.64.0" # MSRV diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 323d96b..1a59e4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: No-default features run: cargo test --workspace --no-default-features msrv: - name: "Check MSRV: 1.60.0" + name: "Check MSRV: 1.64.0" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -59,7 +59,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.60.0 # MSRV + toolchain: 1.64.0 # MSRV profile: minimal override: true - uses: Swatinem/rust-cache@v2 @@ -113,7 +113,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.60.0 # MSRV + toolchain: 1.64.0 # MSRV profile: minimal override: true components: clippy diff --git a/.github/workflows/rust-next.yml b/.github/workflows/rust-next.yml index c4af838..28f7c1b 100644 --- a/.github/workflows/rust-next.yml +++ b/.github/workflows/rust-next.yml @@ -59,9 +59,9 @@ jobs: strategy: matrix: rust: - - 1.60.0 # MSRV + - 1.64.0 # MSRV - stable - continue-on-error: ${{ matrix.rust != '1.60.0' }} # MSRV + continue-on-error: ${{ matrix.rust != '1.64.0' }} # MSRV runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/Cargo.toml b/Cargo.toml index cdb3b4c..1823434 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" categories = ["development-tools::testing"] keywords = ["cli", "test", "assert", "command", "duct"] edition = "2021" -rust-version = "1.60.0" # MSRV +rust-version = "1.64.0" # MSRV include = [ "build.rs", "src/**/*", From d98eabc1c4ef5a0bf0230940d2dfc741d8c3cda8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Mar 2023 04:23:54 -0500 Subject: [PATCH 2/2] fix: Improve color output detection --- Cargo.lock | 158 +++++++++++++++++++++++++++++++++----------------- Cargo.toml | 14 ++--- src/assert.rs | 11 ++-- src/color.rs | 63 +++++++++++--------- src/output.rs | 46 ++++++--------- 5 files changed, 171 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 222705c..768ed12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,19 +2,59 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anstyle" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80c697cc33851b02ab0c26b2e8a211684fbe627ff1cc506131f35026dd7686dd" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-stream" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e72365ef034ed9e365d226f6194ae7afa8a7bedc70ca8ea00668b3cddd42fd2a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "assert_cmd" version = "2.0.8" dependencies = [ + "anstyle", + "anstyle-stream", "bstr", - "concolor 0.0.12", "doc-comment", "escargot", "predicates", "predicates-core", "predicates-tree", "wait-timeout", - "yansi", ] [[package]] @@ -48,28 +88,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "concolor" -version = "0.0.8" +name = "concolor-override" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "015267563b1df20adccdd00cb05257b1dfbea70a04928e9cf88ffb850c1a40af" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" [[package]] -name = "concolor" -version = "0.0.12" +name = "concolor-query" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b3e3c41e9488eeda196b6806dbf487742107d61b2e16485bcca6c25ed5755b" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" dependencies = [ - "bitflags", - "concolor-query", - "is-terminal", + "windows-sys 0.45.0", ] -[[package]] -name = "concolor-query" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317" - [[package]] name = "difflib" version = "0.4.0" @@ -123,12 +155,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "io-lifetimes" @@ -137,19 +166,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "is-terminal" -version = "0.4.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ "hermit-abi", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -202,22 +231,21 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "predicates" -version = "2.1.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" +checksum = "1ba7d6ead3e3966038f68caa9fc1f860185d95a793180bbcfe0d0da47b3961ed" dependencies = [ - "concolor 0.0.8", + "anstyle", "difflib", "itertools", "predicates-core", - "yansi", ] [[package]] name = "predicates-core" -version = "1.0.3" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" [[package]] name = "predicates-tree" @@ -264,7 +292,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -327,6 +355,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "wait-timeout" version = "0.2.0" @@ -373,50 +407,68 @@ dependencies = [ "windows_x86_64_msvc", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" - -[[package]] -name = "yansi" -version = "0.5.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" diff --git a/Cargo.toml b/Cargo.toml index 1823434..1a9daf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,21 +32,21 @@ pre-release-replacements = [ ] [features] -color = ["dep:yansi", "dep:concolor", "concolor?/std", "predicates/color"] -color-auto = ["color", "concolor?/auto"] +color = ["dep:anstyle-stream", "predicates/color"] +color-auto = ["color"] [[bin]] name = "bin_fixture" [dependencies] -predicates = { version = "2.1", default-features = false, features = ["diff"] } -predicates-core = "1.0" -predicates-tree = "1.0" +predicates = { version = "3.0.1", default-features = false, features = ["diff"] } +predicates-core = "1.0.6" +predicates-tree = "1.0.1" doc-comment = "0.3" wait-timeout = "0.2.0" bstr = "1.0.1" -yansi = { version = "0.5.1", optional = true } -concolor = { version = "0.0.12", optional = true } +anstyle-stream = { version = "0.2.1", optional = true } +anstyle = "0.3.1" [dev-dependencies] escargot = "0.5" diff --git a/src/assert.rs b/src/assert.rs index ea58309..b167587 100644 --- a/src/assert.rs +++ b/src/assert.rs @@ -6,6 +6,8 @@ use std::fmt; use std::process; use std::str; +#[cfg(feature = "color")] +use anstyle_stream::panic; use predicates::str::PredicateStrExt; use predicates_tree::CaseTreeExt; @@ -482,14 +484,9 @@ impl Assert { impl fmt::Display for Assert { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let palette = crate::Palette::current(); + let palette = crate::Palette::color(); for &(ref name, ref context) in &self.context { - writeln!( - f, - "{}=`{}`", - palette.key.paint(name), - palette.value.paint(context) - )?; + writeln!(f, "{:#}=`{:#}`", palette.key(name), palette.value(context))?; } output_fmt(&self.output, f) } diff --git a/src/color.rs b/src/color.rs index 3a9b96d..0bc4fc5 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,48 +1,59 @@ #[derive(Copy, Clone, Debug, Default)] pub(crate) struct Palette { - pub(crate) key: styled::Style, - pub(crate) value: styled::Style, + key: anstyle::Style, + value: anstyle::Style, } impl Palette { - #[cfg(feature = "color")] - pub(crate) fn current() -> Self { - if concolor::get(concolor::Stream::Either).ansi_color() { + pub(crate) fn color() -> Self { + if cfg!(feature = "color") { Self { - key: styled::Style(yansi::Style::new(yansi::Color::Blue).bold()), - value: styled::Style(yansi::Style::new(yansi::Color::Yellow).bold()), + key: anstyle::AnsiColor::Blue | anstyle::Effects::BOLD, + value: anstyle::AnsiColor::Yellow | anstyle::Effects::BOLD, } } else { - Self::default() + Self::plain() } } - #[cfg(not(feature = "color"))] - pub(crate) fn current() -> Self { + pub(crate) fn plain() -> Self { Self::default() } -} -#[cfg(feature = "color")] -mod styled { - #[derive(Copy, Clone, Debug, Default)] - pub(crate) struct Style(pub(crate) yansi::Style); + pub(crate) fn key(self, display: D) -> Styled { + Styled::new(display, self.key) + } - impl Style { - pub(crate) fn paint(self, item: T) -> impl std::fmt::Display { - self.0.paint(item) - } + pub(crate) fn value(self, display: D) -> Styled { + Styled::new(display, self.value) } } -#[cfg(not(feature = "color"))] -mod styled { - #[derive(Copy, Clone, Debug, Default)] - pub(crate) struct Style; +#[derive(Debug)] +pub(crate) struct Styled { + display: D, + style: anstyle::Style, +} + +impl Styled { + pub(crate) fn new(display: D, style: anstyle::Style) -> Self { + Self { display, style } + } +} - impl Style { - pub(crate) fn paint(self, item: T) -> impl std::fmt::Display { - item +impl std::fmt::Display for Styled { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if f.alternate() { + write!( + f, + "{}{}{}", + self.style.render(), + self.display, + self.style.render_reset() + ) + } else { + self.display.fmt(f) } } } diff --git a/src/output.rs b/src/output.rs index b9b1cea..832fdf9 100644 --- a/src/output.rs +++ b/src/output.rs @@ -241,24 +241,19 @@ impl Error for OutputError {} impl fmt::Display for OutputError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let palette = crate::Palette::current(); + let palette = crate::Palette::color(); if let Some(ref cmd) = self.cmd { - writeln!( - f, - "{}={}", - palette.key.paint("command"), - palette.value.paint(cmd) - )?; + writeln!(f, "{:#}={:#}", palette.key("command"), palette.value(cmd))?; } if let Some(ref stdin) = self.stdin { writeln!( f, - "{}={}", - palette.key.paint("stdin"), - palette.value.paint(DebugBytes::new(stdin)) + "{:#}={:#}", + palette.key("stdin"), + palette.value(DebugBytes::new(stdin)) )?; } - write!(f, "{}", self.cause) + write!(f, "{:#}", self.cause) } } @@ -271,8 +266,8 @@ enum OutputCause { impl fmt::Display for OutputCause { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - OutputCause::Expected(ref e) => write!(f, "{}", e), - OutputCause::Unexpected(ref e) => write!(f, "{}", e), + OutputCause::Expected(ref e) => write!(f, "{:#}", e), + OutputCause::Unexpected(ref e) => write!(f, "{:#}", e), } } } @@ -289,30 +284,25 @@ impl fmt::Display for Output { } pub(crate) fn output_fmt(output: &process::Output, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let palette = crate::Palette::current(); + let palette = crate::Palette::color(); if let Some(code) = output.status.code() { - writeln!( - f, - "{}={}", - palette.key.paint("code"), - palette.value.paint(code) - )?; + writeln!(f, "{:#}={:#}", palette.key("code"), palette.value(code))?; } else { writeln!( f, - "{}={}", - palette.key.paint("code"), - palette.value.paint("") + "{:#}={:#}", + palette.key("code"), + palette.value("") )?; } write!( f, - "{}={}\n{}={}\n", - palette.key.paint("stdout"), - palette.value.paint(DebugBytes::new(&output.stdout)), - palette.key.paint("stderr"), - palette.value.paint(DebugBytes::new(&output.stderr)), + "{:#}={:#}\n{:#}={:#}\n", + palette.key("stdout"), + palette.value(DebugBytes::new(&output.stdout)), + palette.key("stderr"), + palette.value(DebugBytes::new(&output.stderr)), )?; Ok(()) }