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.21.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.21.2
Choose a head ref
  • 5 commits
  • 8 files changed
  • 1 contributor

Commits on Nov 27, 2022

  1. Copy the full SHA
    ef19b21 View commit details
  2. Fixed warning

    mitsuhiko committed Nov 27, 2022
    Copy the full SHA
    780ddc3 View commit details
  3. Copy the full SHA
    92ffb53 View commit details
  4. Added changelog entries

    mitsuhiko committed Nov 27, 2022
    Copy the full SHA
    811c8f4 View commit details
  5. 1.21.2

    mitsuhiko committed Nov 27, 2022
    Copy the full SHA
    1d75511 View commit details
Showing with 104 additions and 8 deletions.
  1. +5 −0 CHANGELOG.md
  2. +1 −1 Cargo.toml
  3. +2 −2 cargo-insta/Cargo.lock
  4. +2 −2 cargo-insta/Cargo.toml
  5. +50 −2 cargo-insta/src/cli.rs
  6. +9 −1 src/content/serialization.rs
  7. +20 −0 tests/snapshots/test_basic__insta_sort_order.snap
  8. +15 −0 tests/test_basic.rs
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@

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

## 1.21.2

- Added missing parameters to `cargo insta test`. (#305)
- Fixed a sorting issue in hash maps for compound keys. (#304)

## 1.21.1

- Fix incorrect handling of extra args to `cargo insta test`.
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.21.1"
version = "1.21.2"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
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.21.1"
version = "1.21.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.21.1", path = "..", features = ["json", "yaml", "redactions"] }
insta = { version = "=1.21.2", path = "..", features = ["json", "yaml", "redactions"] }
console = "0.15.1"
structopt = { version = "0.3.26", default-features = false }
serde = { version = "1.0.117", features = ["derive"] }
52 changes: 50 additions & 2 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
@@ -77,6 +77,9 @@ pub struct TargetArgs {
pub extensions: Vec<String>,
/// Work on all packages in the workspace
#[structopt(long)]
pub workspace: bool,
/// Alias for --workspace (deprecated)
#[structopt(long)]
pub all: bool,
/// Also walk into ignored paths.
#[structopt(long)]
@@ -101,6 +104,27 @@ pub struct ProcessCommand {
pub struct TestCommand {
#[structopt(flatten)]
pub target_args: TargetArgs,
/// Test only this package's library unit tests
#[structopt(long)]
pub lib: bool,
/// Test only the specified binary
#[structopt(long)]
pub bin: Option<String>,
/// Test all binaries
#[structopt(long)]
pub bins: bool,
/// Test only the specified example
#[structopt(long)]
pub example: Option<String>,
/// Test all examples
#[structopt(long)]
pub examples: bool,
/// Test only the specified test target
#[structopt(long)]
pub test: Option<String>,
/// Test all tests
#[structopt(long)]
pub tests: bool,
/// Package to run tests for
#[structopt(short = "p", long)]
pub package: Option<String>,
@@ -320,7 +344,7 @@ fn handle_target_args(target_args: &TargetArgs) -> Result<LocationInfo<'_>, Box<
})
} else {
let metadata = get_package_metadata(manifest_path.as_ref().map(|x| x.as_path()))?;
let packages = find_packages(&metadata, target_args.all)?;
let packages = find_packages(&metadata, target_args.all || target_args.workspace)?;
Ok(LocationInfo {
workspace_root: metadata.workspace_root().to_path_buf(),
packages: Some(packages),
@@ -721,9 +745,33 @@ fn prepare_test_runner<'snapshot_ref>(
} else {
None
};
if cmd.target_args.all {
if cmd.target_args.all || cmd.target_args.workspace {
proc.arg("--all");
}
if cmd.lib {
proc.arg("--lib");
}
if let Some(ref bin) = cmd.bin {
proc.arg("--bin");
proc.arg(bin);
}
if cmd.bins {
proc.arg("--bins");
}
if let Some(ref example) = cmd.example {
proc.arg("--example");
proc.arg(example);
}
if cmd.examples {
proc.arg("--examples");
}
if let Some(ref test) = cmd.test {
proc.arg("--test");
proc.arg(test);
}
if cmd.tests {
proc.arg("--tests");
}
if let Some(ref pkg) = cmd.package {
proc.arg("--package");
proc.arg(pkg);
10 changes: 9 additions & 1 deletion src/content/serialization.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,15 @@ impl Content {
pub(crate) fn sort_maps(&mut self) {
self.walk(&mut |content| {
if let Content::Map(ref mut items) = content {
items.sort_by(|a, b| a.0.as_key().cmp(&b.0.as_key()));
// try to compare by key first, if that fails compare by the
// object value. That way some values normalize, and if we
// can't normalize we still have a stable order.
items.sort_by(|a, b| match (a.0.as_key(), b.0.as_key()) {
(Key::Other, _) | (_, Key::Other) => {
a.0.partial_cmp(&b.0).unwrap_or(Ordering::Equal)
}
(ref a, ref b) => a.cmp(b),
})
}
true
})
20 changes: 20 additions & 0 deletions tests/snapshots/test_basic__insta_sort_order.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: tests/test_basic.rs
expression: m
---
? - 1
- 3
: 4
? - 1
- 4
: 4
? - 2
- 3
: 4
? - 3
- 3
: 4
? - 9
- 3
: 4

15 changes: 15 additions & 0 deletions tests/test_basic.rs
Original file line number Diff line number Diff line change
@@ -89,3 +89,18 @@ fn test_u128_json() {
let x: u128 = u128::from(u64::MAX) * 2;
assert_json_snapshot!(&x, @"36893488147419103230");
}

#[cfg(feature = "yaml")]
#[test]
fn insta_sort_order() {
use std::collections::HashMap;
let mut m = HashMap::new();
m.insert((1, 3), 4);
m.insert((2, 3), 4);
m.insert((1, 4), 4);
m.insert((3, 3), 4);
m.insert((9, 3), 4);
insta::with_settings!({sort_maps =>true}, {
insta::assert_yaml_snapshot!(m);
});
}