Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mitsuhiko/insta
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.7.1
Choose a base ref
...
head repository: mitsuhiko/insta
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.7.2
Choose a head ref
  • 11 commits
  • 10 files changed
  • 2 contributors

Commits on Aug 16, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    34a6f8f View commit details
  2. Allow underscore in selectors

    Fixes #189
    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    287d88d View commit details
  3. Added changelog entry

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    d518be3 View commit details
  4. Added craft config

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    868aa7a View commit details
  5. Avoid leaking of paths

    Fixes #185
    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    0fefd60 View commit details
  6. Reformat changelog

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    a109969 View commit details
  7. Added support for INSTA_WORKSPACE_ROOT

    Fixes #180
    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    5702955 View commit details
  8. Fix bump script

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    b3d7fa5 View commit details
  9. Copy the full SHA
    98d4675 View commit details
  10. Remove craft

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    1a25946 View commit details
  11. 1.7.2

    mitsuhiko committed Aug 16, 2021
    Copy the full SHA
    15ad420 View commit details
Showing with 173 additions and 100 deletions.
  1. +82 −73 CHANGELOG.md
  2. +1 −1 Cargo.toml
  3. +4 −2 cargo-insta/Cargo.lock
  4. +2 −2 cargo-insta/Cargo.toml
  5. +5 −0 cargo-insta/src/cli.rs
  6. +1 −1 src/macros.rs
  7. +31 −19 src/runtime.rs
  8. +2 −2 src/select_grammar.pest
  9. +10 −0 tests/snapshots/test_redaction__struct_array_redaction.snap
  10. +35 −0 tests/test_redaction.rs
155 changes: 82 additions & 73 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,154 +2,163 @@

All notable changes to insta and cargo-insta are documented here.

## 1.7.2

- Fixed an issue where selectors could not start with underscore. (#189)
- Allow passing arguments to `cargo test`. (#183)
- Avoid the use of `Box::leak`. (#185)
- When `INSTA_WORKSPACE_ROOT` is set, the value is used as the manifest
directory rather than whatever `CARGO_MANIFEST_DIR` was set to at compile
time. (#180)

## 1.7.1

* Removed an accidental debug print. (#175)
- Removed an accidental debug print. (#175)

## 1.7.0

* Added support for u128/i128. (#169)
* Normalize newlines to unix before before asserting. (#172)
* Switch diffing to patience. (#173)
- Added support for u128/i128. (#169)
- Normalize newlines to unix before before asserting. (#172)
- Switch diffing to patience. (#173)

## 1.6.3

* Fix a bug with empty lines in inline snapshots. (#166)
- Fix a bug with empty lines in inline snapshots. (#166)

## 1.6.2

* Lower Rust support to 1.41.0 (#165)
- Lower Rust support to 1.41.0 (#165)

## 1.6.1

* Bump similar dependency to reintroduce support for Rust 1.43.0 (#162)
* Fixed custom extension support in cargo-insta (#163)
- Bump similar dependency to reintroduce support for Rust 1.43.0 (#162)
- Fixed custom extension support in cargo-insta (#163)

## 1.6.0

* Change CSV serialization format to format multiple structs as
multiple rows. (#156)
* Improvements to diff rendering.
* Detect some snapshot name clashes. (#159)
- Change CSV serialization format to format multiple structs as
multiple rows. (#156)
- Improvements to diff rendering.
- Detect some snapshot name clashes. (#159)

## 1.5.3

* Replace [difference](https://crates.io/crates/difference) with
- Replace [difference](https://crates.io/crates/difference) with
[similar](https://crates.io/crates/similar).

## 1.5.2

* API documentation updates.
- API documentation updates.

## 1.5.1

* Fixed glob not working correctly.
* Fail by default if glob is not returning any matches. Fixes #151.
- Fixed glob not working correctly.
- Fail by default if glob is not returning any matches. Fixes #151.

## 1.5.0

* Add `pending-snapshots` parameter to `cargo-insta`.
* `cargo-insta` now honors ignore files. This can be overridden
- Add `pending-snapshots` parameter to `cargo-insta`.
- `cargo-insta` now honors ignore files. This can be overridden
with `--no-ignore`.
* `cargo-insta` now supports the vscode extension.
- `cargo-insta` now supports the vscode extension.

## 1.4.0

* Add `--delete-unreferenced-snapshots` parameter to `cargo-insta`.
* Switch to the `globset` crate for the `glob` feature.
* When `INSTA_UPDATE` is set to `always` or `unseen` it won't
- Add `--delete-unreferenced-snapshots` parameter to `cargo-insta`.
- Switch to the `globset` crate for the `glob` feature.
- When `INSTA_UPDATE` is set to `always` or `unseen` it won't
fail on execution.
* Changed informational outputs also show on pass.
- Changed informational outputs also show on pass.

## 1.3.0

* Expose more useful methods from `Content`.
* Fixes for latest rustc version.
- Expose more useful methods from `Content`.
- Fixes for latest rustc version.

## 1.2.0

* Fix invalid offset calculation for inline snapshot (#137)
* Added support for newtype variant redactions. (#139)
- Fix invalid offset calculation for inline snapshot (#137)
- Added support for newtype variant redactions. (#139)

## 1.1.0

* Added the `INSTA_SNAPSHOT_REFERENCES_FILE` environment variable to support
- Added the `INSTA_SNAPSHOT_REFERENCES_FILE` environment variable to support
deletions of unreferenced snapshot files. (#136)
* Added support for TOML serializations.
* Avoid diff calculation on large input files. (#135)
* Added `prepend_module_to_snapshot` flag to disable prepending of module
- Added support for TOML serializations.
- Avoid diff calculation on large input files. (#135)
- Added `prepend_module_to_snapshot` flag to disable prepending of module
names to snapshot files. (#133)
* Made `console` dependency optional. The `colors` feature can be disabled now
- Made `console` dependency optional. The `colors` feature can be disabled now
which disables colored output.

## 1.0.0

* Globs now follow links (#132)
* Added CSV Support (#134)
* Changed globs to also include directories not just files.
* Support snapshots outside source folder. (#70)
* Update RON to 0.6.
- Globs now follow links (#132)
- Added CSV Support (#134)
- Changed globs to also include directories not just files.
- Support snapshots outside source folder. (#70)
- Update RON to 0.6.

## 0.16.1

* Add `Settings::bind_async` when the `async` feature is enabled. (#121)
* Bumped `console` dependency to 0.11. (#124)
* Fixed incorrect path handling for `glob!`. (#123)
* Remove `cargo-insta` from workspace and add `Cargo.lock`. (#116)
- Add `Settings::bind_async` when the `async` feature is enabled. (#121)
- Bumped `console` dependency to 0.11. (#124)
- Fixed incorrect path handling for `glob!`. (#123)
- Remove `cargo-insta` from workspace and add `Cargo.lock`. (#116)

## 0.16.0

* Made snapshot names optional for inline snapshots. (#106)
* Remove legacy macros. (#115)
* Made small improvements to cargo-insta's messaging and flags (#114)
* Added new logo.
* Added `glob` support. (#112)
* Made `MetaData` fields internal. (#111)
- Made snapshot names optional for inline snapshots. (#106)
- Remove legacy macros. (#115)
- Made small improvements to cargo-insta's messaging and flags (#114)
- Added new logo.
- Added `glob` support. (#112)
- Made `MetaData` fields internal. (#111)

## 0.15.0

* Added test output control (`INSTA_OUTPUT` envvar). (#103)
- Added test output control (`INSTA_OUTPUT` envvar). (#103)

## 0.14.0

* Dependency bump for `console` (lowers total dependency count)
* Change binary name to `cargo insta` in help pages.
- Dependency bump for `console` (lowers total dependency count)
- Change binary name to `cargo insta` in help pages.

## 0.13.1

* Added support for `INSTA_UPDATE=unseen` to write out unseen snapshots without review (#96)
* Added the `backtrace` feature which adds support for test name (and thus snapshot name)
- Added support for `INSTA_UPDATE=unseen` to write out unseen snapshots without review (#96)
- Added the `backtrace` feature which adds support for test name (and thus snapshot name)
recovery from the backtrace if rust-test is not used in concurrent mode (#94, #98)

## 0.13

* Add support for deep wildcard matches (#92)
* Use module paths for test names (#87)
* Do not emit useless indentations for empty lines (#88)
- Add support for deep wildcard matches (#92)
- Use module paths for test names (#87)
- Do not emit useless indentations for empty lines (#88)

## 0.12

* Improve redactions support (#81)
* Deprecated macros are now hidden
* Reduce number of dependencies further.
* Added support for newtype struct redactions.
* Fixed bugs with recursive content operations (#80)
- Improve redactions support (#81)
- Deprecated macros are now hidden
- Reduce number of dependencies further.
- Added support for newtype struct redactions.
- Fixed bugs with recursive content operations (#80)

## 0.11

* redactions are now an optional feature that must be turned on to be used (`redactions`).
* RON format is now an optional feature that must be turned on to be used (`ron`).
* added support for sorting maps before serialization.
* added settings support.
* added support for overriding the snapshot path.
* correctly handle nested macros that might contain inline snapshots.
* use thread name as snapshot name for inline snapshots.
* use leading whitespace normalization for inline snapshots.
* removed `creator` and `created` field from snapshot metadata.
* removed the `_matches` suffix from all macros.
* added an `--accept` option to `cargo insta test`
* added `--force-update-snapshots` option to `cargo insta test`
* added `--jobs` and `--release` argument to `cargo insta test`.
- redactions are now an optional feature that must be turned on to be used (`redactions`).
- RON format is now an optional feature that must be turned on to be used (`ron`).
- added support for sorting maps before serialization.
- added settings support.
- added support for overriding the snapshot path.
- correctly handle nested macros that might contain inline snapshots.
- use thread name as snapshot name for inline snapshots.
- use leading whitespace normalization for inline snapshots.
- removed `creator` and `created` field from snapshot metadata.
- removed the `_matches` suffix from all macros.
- added an `--accept` option to `cargo insta test`
- added `--force-update-snapshots` option to `cargo insta test`
- added `--jobs` and `--release` argument to `cargo insta test`.

To upgrade to the new insta macros and snapshot formats you can use
[`fastmod`](https://crates.io/crates/fastmod) and `cargo-insta` together:
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.7.1"
version = "1.7.2"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
6 changes: 4 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.7.1"
version = "1.7.2"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
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.7.1", path = "..", features = ["redactions"] }
insta = { version = "1.7.2", path = "..", features = ["redactions"] }
console = "0.14.0"
clap = { version = "2.33.3", default-features = false }
difference = "2.0.0"
5 changes: 5 additions & 0 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
@@ -139,6 +139,10 @@ pub struct TestCommand {
/// Delete unreferenced snapshots after the test run.
#[structopt(long)]
pub delete_unreferenced_snapshots: bool,
/// Options passed to cargo test
// Sets raw to true so that `--` is required
#[structopt(name = "cargo_options", raw(true))]
pub cargo_options: Vec<String>,
}

#[derive(StructOpt, Debug)]
@@ -543,6 +547,7 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {
}
proc.arg("--color");
proc.arg(color);
proc.args(cmd.cargo_options);
proc.arg("--");
proc.arg("-q");

2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
@@ -389,7 +389,7 @@ macro_rules! assert_snapshot {
line!(),
$debug_expr,
)
.unwrap();
.unwrap()
};
($value:expr) => {
$crate::assert_snapshot!($crate::_macro_support::AutoName, $value, stringify!($value))
50 changes: 31 additions & 19 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str;
use std::sync::Mutex;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;

@@ -21,7 +21,7 @@ use crate::snapshot::{MetaData, PendingInlineSnapshot, Snapshot, SnapshotContent
use crate::utils::{is_ci, style};

lazy_static! {
static ref WORKSPACES: Mutex<BTreeMap<String, &'static Path>> = Mutex::new(BTreeMap::new());
static ref WORKSPACES: Mutex<BTreeMap<String, Arc<PathBuf>>> = Mutex::new(BTreeMap::new());
static ref TEST_NAME_COUNTERS: Mutex<BTreeMap<String, usize>> = Mutex::new(BTreeMap::new());
static ref TEST_NAME_CLASH_DETECTION: Mutex<BTreeMap<String, bool>> =
Mutex::new(BTreeMap::new());
@@ -183,27 +183,38 @@ fn get_cargo() -> String {
.unwrap_or_else(|| "cargo".to_string())
}

pub fn get_cargo_workspace(manifest_dir: &str) -> &Path {
pub fn get_cargo_workspace(manifest_dir: &str) -> Arc<PathBuf> {
// we really do not care about poisoning here.
let mut workspaces = WORKSPACES.lock().unwrap_or_else(|x| x.into_inner());
if let Some(rv) = workspaces.get(manifest_dir) {
rv
rv.clone()
} else {
#[derive(Deserialize)]
struct Manifest {
workspace_root: String,
}
let output = std::process::Command::new(get_cargo())
.arg("metadata")
.arg("--format-version=1")
.arg("--no-deps")
.current_dir(manifest_dir)
.output()
.unwrap();
let manifest: Manifest = serde_json::from_slice(&output.stdout).unwrap();
let path = Box::leak(Box::new(PathBuf::from(manifest.workspace_root)));
workspaces.insert(manifest_dir.to_string(), path.as_path());
workspaces.get(manifest_dir).unwrap()
// If INSTA_WORKSPACE_ROOT environment variable is set, use the value
// as-is. This is useful for those users where the compiled in
// CARGO_MANIFEST_DIR points to some transient location. This can easily
// happen if the user builds the test in one directory but then tries to
// run it in another: even if sources are available in the new
// directory, in the past we would always go with the compiled-in value.
// The compiled-in directory may not even exist anymore.
let path = if let Ok(workspace_root) = std::env::var("INSTA_WORKSPACE_ROOT") {
Arc::new(PathBuf::from(workspace_root))
} else {
#[derive(Deserialize)]
struct Manifest {
workspace_root: PathBuf,
}
let output = std::process::Command::new(get_cargo())
.arg("metadata")
.arg("--format-version=1")
.arg("--no-deps")
.current_dir(manifest_dir)
.output()
.unwrap();
let manifest: Manifest = serde_json::from_slice(&output.stdout).unwrap();
Arc::new(manifest.workspace_root)
};
workspaces.insert(manifest_dir.to_string(), path.clone());
path
}
}

@@ -886,6 +897,7 @@ pub fn assert_snapshot(
expr: &str,
) -> Result<(), Box<dyn Error>> {
let cargo_workspace = get_cargo_workspace(manifest_dir);
let cargo_workspace = cargo_workspace.as_path();
let output_behavior = output_snapshot_behavior();

let (snapshot_name, snapshot_file, old, pending_snapshots) = match refval {
Loading