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.15.0
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.16.0
Choose a head ref
  • 7 commits
  • 25 files changed
  • 2 contributors

Commits on Jul 16, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    gyaneshgouraw-okta Gyanesh Gouraw
    Copy the full SHA
    56675f2 View commit details
  2. Copy the full SHA
    ca62ee7 View commit details

Commits on Jul 17, 2022

  1. Update RON (#240)

    mitsuhiko authored Jul 17, 2022
    Copy the full SHA
    2878012 View commit details

Commits on Jul 21, 2022

  1. Fix typos (#241)

    kianmeng authored Jul 21, 2022
    Copy the full SHA
    1fff8b0 View commit details
  2. Copy the full SHA
    a8d516e View commit details
  3. Added info and description fields (#239)

    This also refactors the internals for modifying settings via macros so
    it's a perfect match to the public interface and adds a new omit_expression
    flag to the settings to prevent the default expression to be written.
    mitsuhiko authored Jul 21, 2022
    Copy the full SHA
    cac38e1 View commit details
  4. 1.16.0

    mitsuhiko committed Jul 21, 2022
    Copy the full SHA
    8f659ec View commit details
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@
"rust-analyzer.cargo.allFeatures": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"rust-analyzer.checkOnSave.command": "clippy",
}
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,18 @@

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

## 1.16.0

- Added `--no-quiet`/`-Q` flag to `cargo insta test` to suppress the
quiet flag. This works around limitations with custom test harnesses
such as cucumber.
- Update RON to 0.7.1.
- Improved ergonomics around `with_settings!`. It's now a perfect match to
the settings object's setter methods.
- Added `description` and `info` to snapshots. (#239)
- Added `omit_expression` setting. (#239)
- Added improved support for running insta from doctests. (#243)

## 1.15.0

- Bump minimum version of Rust to 1.56.1. This was done because the used
@@ -33,7 +45,7 @@ All notable changes to insta and cargo-insta are documented here.
**Upgrade Notes:**

Insta used to detect the current test name by using the current thread name. This
appeared to work well but unfortunatley ran into various limitations. In particular
appeared to work well but unfortunately ran into various limitations. In particular
in some cases the thread name was truncated, missing or did not point to the current
test name. To better support different platforms and situations insta now uses the
function name instead.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insta"
version = "1.15.0"
version = "1.16.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
@@ -44,7 +44,7 @@ console = { version = "0.15.0", optional = true, default-features = false }
serde_json = "1.0.59"
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
ron = { version = "0.7.0", optional = true }
ron = { version = "0.7.1", optional = true }
toml = { version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
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.15.0"
version = "1.16.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"
@@ -12,7 +12,7 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "1.15.0", path = "..", features = ["redactions"] }
insta = { version = "1.16.0", path = "..", features = ["redactions"] }
console = "0.15.0"
structopt = "0.3.20"
serde = { version = "1.0.117", features = ["derive"] }
99 changes: 61 additions & 38 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
@@ -140,6 +140,9 @@ pub struct TestCommand {
/// Delete unreferenced snapshots after the test run.
#[structopt(long)]
pub delete_unreferenced_snapshots: bool,
/// Do not pass the quiet flag (`-q`) to tests.
#[structopt(short = "Q", long)]
pub no_quiet: bool,
/// Options passed to cargo test
// Sets raw to true so that `--` is required
#[structopt(name = "cargo_options", raw(true))]
@@ -167,46 +170,61 @@ fn query_snapshot(
i: usize,
n: usize,
snapshot_file: Option<&Path>,
show_info: &mut bool,
) -> Result<Operation, Box<dyn Error>> {
term.clear_screen()?;
println!(
"{}{}{}",
style("Reviewing [").bold(),
style(format!("{}/{}", i, n)).yellow().bold(),
style("]:").bold(),
);
loop {
term.clear_screen()?;
let (pkg_name, pkg_version) = if let Some(pkg) = pkg {
(pkg.name(), pkg.version())
} else {
("unknown package", "unknown version")
};

if let Some(pkg) = pkg {
println!("Package: {} ({})", style(pkg.name()).dim(), pkg.version());
} else {
println!();
}
println!(
"{}{}{} {}@{}:",
style("Reviewing [").bold(),
style(format!("{}/{}", i, n)).yellow().bold(),
style("]").bold(),
pkg_name,
pkg_version,
);

print_snapshot_diff(workspace_root, new, old, snapshot_file, line);
print_snapshot_diff(workspace_root, new, old, snapshot_file, line, *show_info);

println!();
println!(
" {} accept {}",
style("a").green().bold(),
style("keep the new snapshot").dim()
);
println!(
" {} reject {}",
style("r").red().bold(),
style("keep the old snapshot").dim()
);
println!(
" {} skip {}",
style("s").yellow().bold(),
style("keep both for now").dim()
);

loop {
match term.read_key()? {
Key::Char('a') | Key::Enter => break Ok(Operation::Accept),
Key::Char('r') | Key::Escape => break Ok(Operation::Reject),
Key::Char('s') | Key::Char(' ') => break Ok(Operation::Skip),
_ => {}
println!();
println!(
" {} accept {}",
style("a").green().bold(),
style("keep the new snapshot").dim()
);
println!(
" {} reject {}",
style("r").red().bold(),
style("keep the old snapshot").dim()
);
println!(
" {} skip {}",
style("s").yellow().bold(),
style("keep both for now").dim()
);
println!(
" {} {} info {}",
style("i").cyan().bold(),
if *show_info { "hide" } else { "show" },
style("toggles extended snapshot info").dim()
);

loop {
match term.read_key()? {
Key::Char('a') | Key::Enter => return Ok(Operation::Accept),
Key::Char('r') | Key::Escape => return Ok(Operation::Reject),
Key::Char('s') | Key::Char(' ') => return Ok(Operation::Skip),
Key::Char('i') => {
*show_info = !*show_info;
break;
}
_ => {}
}
}
}
}
@@ -337,6 +355,7 @@ fn process_snapshots(cmd: ProcessCommand, op: Option<Operation>) -> Result<(), B
let mut rejected = vec![];
let mut skipped = vec![];
let mut num = 0;
let mut show_info = true;

for (snapshot_container, package) in snapshot_containers.iter_mut() {
let target_file = snapshot_container.target_file().to_path_buf();
@@ -368,6 +387,7 @@ fn process_snapshots(cmd: ProcessCommand, op: Option<Operation>) -> Result<(), B
num,
snapshot_count,
snapshot_file.as_ref().map(|x| x.as_path()),
&mut show_info,
)?,
};
match op {
@@ -557,8 +577,11 @@ 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");

if !cmd.no_quiet {
proc.arg("--");
proc.arg("-q");
}

if !cmd.keep_pending {
process_snapshots(
2 changes: 1 addition & 1 deletion src/content.rs
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ impl Content {
Content::I128(val) => Key::I128(val),
Content::F32(val) => Key::F64(val.into()),
Content::F64(val) => Key::F64(val),
Content::String(ref val) => Key::Str(&val.as_str()),
Content::String(ref val) => Key::Str(val.as_str()),
Content::Bytes(ref val) => Key::Bytes(&val[..]),
_ => Key::Other,
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
//!
//! # Writing Tests
//!
//! ```no_run
//! ```
//! use insta::assert_debug_snapshot;
//!
//! #[test]
@@ -47,7 +47,7 @@
//!
//! The recommended flow is to run the tests once, have them fail and check
//! if the result is okay. By default the new snapshots are stored next
//! to the old ones with the extra `.new` extension. Once you are satisifed
//! to the old ones with the extra `.new` extension. Once you are satisfied
//! move the new files over. To simplify this workflow you can use
//! `cargo insta review` which will let you interactively review them:
//!
25 changes: 19 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ macro_rules! assert_toml_snapshot {
/// snapshot variant the type of the value does not appear in the output.
/// You can however use the `assert_ron_snapshot!` macro to dump out
/// the value in [RON](https://github.com/ron-rs/ron/) format which retains some
/// type information for more accurate comparisions.
/// type information for more accurate comparisons.
///
/// Example:
///
@@ -170,7 +170,7 @@ macro_rules! assert_yaml_snapshot {
///
/// This works exactly like [`assert_yaml_snapshot!`]
/// but serializes in [RON](https://github.com/ron-rs/ron/) format instead of
/// YAML which retains some type information for more accurate comparisions.
/// YAML which retains some type information for more accurate comparisons.
///
/// Example:
///
@@ -416,22 +416,35 @@ macro_rules! assert_snapshot {

/// Settings configuration macro.
///
/// This macro lets you bind some settings temporarily. The first argument
/// This macro lets you bind some [`Settings`](crate::Settings) temporarily. The first argument
/// takes key value pairs that should be set, the second is the block to
/// execute. All settings can be set (`sort_maps => value` maps roughly
/// to `set_sort_maps(value)`).
/// execute. All settings can be set (`sort_maps => value` maps to `set_sort_maps(value)`).
/// The exception are redactions which can only be set to a vector this way.
///
/// This example:
///
/// ```rust
/// insta::with_settings!({sort_maps => true}, {
/// // run snapshot test here
/// });
/// ```
///
/// Is equivalent to the following:
///
/// ```rust
/// # use insta::Settings;
/// let mut settings = Settings::new();
/// settings.set_sort_maps(true);
/// settings.bind(|| {
/// // run snapshot test here
/// });
/// ```
#[macro_export]
macro_rules! with_settings {
({$($k:ident => $v:expr),*$(,)?}, $body:block) => {{
let mut settings = $crate::Settings::new();
$(
settings._private_inner_mut().$k = $v.into();
settings._private_inner_mut().$k($v);
)*
settings.bind(|| $body)
}}
Loading