diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b1d284dc..58546abd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.56.1 + toolchain: 1.60.0 - name: Test run: make cargotest diff --git a/CHANGELOG.md b/CHANGELOG.md index 568c9b20..7d8135a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,15 @@ All notable changes to insta and cargo-insta are documented here. +## 1.31.0 + +- Fixed a bug that caused `cargo insta test` not to report test failures. +- Suppress `needless_raw_string_hashes` clippy lint on inline snapshots. (#390) + ## 1.30.0 +- Resolved a bug on Windows that caused `input_file` not to be written into the + snapshots. (#386) - Snapshots are accepted when running with `--accept` even if a test outside insta fails. (#358) - Mark settings drop guard as `#[must_use]`. diff --git a/Cargo.toml b/Cargo.toml index 204f70e8..7f4c0eb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "insta" -version = "1.29.0" +version = "1.31.0" license = "Apache-2.0" authors = ["Armin Ronacher "] description = "A snapshot testing library for Rust" diff --git a/cargo-insta/Cargo.lock b/cargo-insta/Cargo.lock index bbaa5213..3f755bb5 100644 --- a/cargo-insta/Cargo.lock +++ b/cargo-insta/Cargo.lock @@ -37,7 +37,7 @@ dependencies = [ [[package]] name = "cargo-insta" -version = "1.29.0" +version = "1.31.0" dependencies = [ "console", "ignore", @@ -237,7 +237,7 @@ dependencies = [ [[package]] name = "insta" -version = "1.29.0" +version = "1.31.0" dependencies = [ "console", "lazy_static", diff --git a/cargo-insta/Cargo.toml b/cargo-insta/Cargo.toml index 5ea0e054..357a1502 100644 --- a/cargo-insta/Cargo.toml +++ b/cargo-insta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-insta" -version = "1.29.0" +version = "1.31.0" license = "Apache-2.0" authors = ["Armin Ronacher "] description = "A review tool for the insta snapshot testing library for Rust" @@ -12,7 +12,7 @@ edition = "2018" readme = "README.md" [dependencies] -insta = { version = "=1.29.0", path = "..", features = ["json", "yaml", "redactions", "_cargo_insta_internal"] } +insta = { version = "=1.31.0", path = "..", features = ["json", "yaml", "redactions", "_cargo_insta_internal"] } console = "0.15.4" structopt = { version = "0.3.26", default-features = false } serde = { version = "1.0.117", features = ["derive"] } diff --git a/cargo-insta/src/cli.rs b/cargo-insta/src/cli.rs index a1fa0036..91fdf97c 100644 --- a/cargo-insta/src/cli.rs +++ b/cargo-insta/src/cli.rs @@ -651,7 +651,11 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box> { } } - Ok(()) + if !success { + Err(QuietExit(1).into()) + } else { + Ok(()) + } } fn handle_unreferenced_snapshots( diff --git a/src/macros.rs b/src/macros.rs index a36ffa35..26967712 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -297,6 +297,7 @@ macro_rules! _assert_snapshot_base { (transform=$transform:expr, $value:expr, @$snapshot:literal) => { $crate::_assert_snapshot_base!( transform = $transform, + #[allow(clippy::needless_raw_string_hashes)] $crate::_macro_support::ReferenceValue::Inline($snapshot), $value, stringify!($value) @@ -305,6 +306,7 @@ macro_rules! _assert_snapshot_base { (transform=$transform:expr, $value:expr, $debug_expr:expr, @$snapshot:literal) => { $crate::_assert_snapshot_base!( transform = $transform, + #[allow(clippy::needless_raw_string_hashes)] $crate::_macro_support::ReferenceValue::Inline($snapshot), $value, $debug_expr @@ -316,6 +318,7 @@ macro_rules! _assert_snapshot_base { (transform=$transform:expr, $name:expr, $value:expr, $debug_expr:expr) => { $crate::_macro_support::assert_snapshot( $name.into(), + #[allow(clippy::redundant_closure_call)] &$transform($value), env!("CARGO_MANIFEST_DIR"), $crate::_function_name!(), diff --git a/src/runtime.rs b/src/runtime.rs index 1768179b..c5b88414 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -310,16 +310,9 @@ impl<'a> SnapshotAssertionContext<'a> { /// Given a path returns the local path within the workspace. pub fn localize_path(&self, p: &Path) -> Option { - self.cargo_workspace - .join(p) - .canonicalize() - .ok() - .and_then(|s| { - self.cargo_workspace - .canonicalize() - .ok() - .and_then(|cw| s.strip_prefix(cw).ok().map(|x| x.to_path_buf())) - }) + let workspace = self.cargo_workspace.canonicalize().ok()?; + let p = self.cargo_workspace.join(p).canonicalize().ok()?; + p.strip_prefix(&workspace).ok().map(|x| x.to_path_buf()) } /// Creates the new snapshot from input values. diff --git a/src/snapshot.rs b/src/snapshot.rs index 6167a772..573e675d 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -533,7 +533,7 @@ impl SnapshotContents { ) }) // `lines` removes the final line ending - add back - .chain(Some(format!("\n{:width$}", "", width = indentation)).into_iter()), + .chain(Some(format!("\n{:width$}", "", width = indentation))), ); } else { out.push_str(contents); @@ -727,7 +727,7 @@ b"[1..]; ); let t = "ab"; - assert_eq!(SnapshotContents(t.to_string()).to_inline(0), r##""ab""##); + assert_eq!(SnapshotContents(t.to_string()).to_inline(0), r#""ab""#); } #[test] diff --git a/tests/test_basic.rs b/tests/test_basic.rs index 66e7e73b..bd164222 100644 --- a/tests/test_basic.rs +++ b/tests/test_basic.rs @@ -2,6 +2,7 @@ use insta::assert_json_snapshot; #[cfg(feature = "yaml")] use insta::assert_yaml_snapshot; +#[allow(deprecated)] use insta::{assert_debug_snapshot, assert_display_snapshot}; use std::fmt; @@ -71,12 +72,14 @@ impl fmt::Display for TestDisplay { } #[test] +#[allow(deprecated)] fn test_display() { let td = TestDisplay; assert_display_snapshot!("display", td); } #[test] +#[allow(deprecated)] fn test_unnamed_display() { let td = TestDisplay; assert_display_snapshot!(td); diff --git a/tests/test_clash_detection.rs b/tests/test_clash_detection.rs index eeed0899..f65ce18f 100644 --- a/tests/test_clash_detection.rs +++ b/tests/test_clash_detection.rs @@ -44,7 +44,7 @@ fn test_clash_detection() { let s1 = err1.downcast_ref::().unwrap(); let s2 = err2.downcast_ref::().unwrap(); - let mut values = vec![s1.as_str(), s2.as_str()]; + let mut values = [s1.as_str(), s2.as_str()]; values.sort(); assert_eq!(&values[..], &vec![ "Insta snapshot name clash detected between \'foo_always_missing\' and \'test_foo_always_missing\' in \'test_clash_detection\'. Rename one function.",