Skip to content

Commit

Permalink
Merge branch 'master' into macros
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Sep 16, 2023
2 parents ba4db8b + 4288333 commit 07faf79
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insta"
version = "1.29.0"
version = "1.31.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
Expand Down
4 changes: 2 additions & 2 deletions cargo-insta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cargo-insta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-insta"
version = "1.29.0"
version = "1.31.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A review tool for the insta snapshot testing library for Rust"
Expand All @@ -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"] }
Expand Down
6 changes: 5 additions & 1 deletion cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,11 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {
}
}

Ok(())
if !success {
Err(QuietExit(1).into())
} else {
Ok(())
}
}

fn handle_unreferenced_snapshots(
Expand Down
3 changes: 3 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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!(),
Expand Down
13 changes: 3 additions & 10 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
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.
Expand Down
4 changes: 2 additions & 2 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clash_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_clash_detection() {

let s1 = err1.downcast_ref::<String>().unwrap();
let s2 = err2.downcast_ref::<String>().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.",
Expand Down

0 comments on commit 07faf79

Please sign in to comment.