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.6.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.6.1
Choose a head ref
  • 10 commits
  • 13 files changed
  • 1 contributor

Commits on Feb 7, 2021

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    ccb9879 View commit details

Commits on Feb 12, 2021

  1. fix: clippy

    mitsuhiko committed Feb 12, 2021

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    2b5fabd View commit details

Commits on Feb 15, 2021

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    96fb3dc View commit details
  2. Partially verified

    This commit is signed with the committer’s verified signature.
    koba1t’s contribution has been verified via GPG key.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    b5d5bb0 View commit details
  3. Copy the full SHA
    e395126 View commit details
  4. Update changelog

    mitsuhiko committed Feb 15, 2021
    Copy the full SHA
    0ca640c View commit details
  5. Copy the full SHA
    b13da14 View commit details
  6. Copy the full SHA
    4efd87c View commit details
  7. Fix another test for 1.43

    mitsuhiko committed Feb 15, 2021
    Copy the full SHA
    d8e4aca View commit details
  8. 1.6.1

    mitsuhiko committed Feb 15, 2021
    Copy the full SHA
    ffed8ed View commit details
Showing with 139 additions and 82 deletions.
  1. +9 −4 .github/workflows/clippy.yml
  2. +9 −4 .github/workflows/rustfmt.yml
  3. +23 −4 .github/workflows/tests.yml
  4. +6 −1 CHANGELOG.md
  5. +2 −2 Cargo.toml
  6. +5 −0 README.md
  7. +4 −4 cargo-insta/Cargo.lock
  8. +2 −2 cargo-insta/Cargo.toml
  9. +39 −39 cargo-insta/src/cargo.rs
  10. +1 −0 clippy.toml
  11. +1 −4 src/content.rs
  12. +36 −16 src/runtime.rs
  13. +2 −2 tests/test_clash_detection.rs
13 changes: 9 additions & 4 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -4,10 +4,15 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Run clippy
run: make lint
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Run clippy
run: make lint
13 changes: 9 additions & 4 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -4,10 +4,15 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Run rustfmt
run: make format-check
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Run rustfmt
run: make format-check
27 changes: 23 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -3,11 +3,30 @@ name: Tests
on: [push]

jobs:
build:
build-latest:
name: Test on Latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Test
run: make test

build-stable:
name: Test on 1.43.0
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Test
run: make test
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.43.0
profile: minimal
override: true
- name: Test
run: make test
7 changes: 6 additions & 1 deletion 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.6.1

* 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
@@ -133,5 +138,5 @@ To upgrade to the new insta macros and snapshot formats you can use

$ cargo install fastmod
$ cargo install cargo-insta
$ fastmod '\bassert_([a-z]+_snapshot)_matches!' 'assert_${1}!' -e rs --accept-all
$ fastmod '\bassert_([a-z]+_snapshot)_matches!' 'assert_${`}!' -e rs --accept-all
$ cargo insta test --all --force-update-snapshots --accept
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.6.0"
version = "1.6.1"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
@@ -47,4 +47,4 @@ toml = { version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
uuid = "0.8.1"
similar = "1.1.0"
similar = { version = "1.2.1", features = ["inline"] }
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -45,6 +45,11 @@ marketplace: [view on marketplace](https://marketplace.visualstudio.com/items?it

![jump to definition](https://raw.githubusercontent.com/mitsuhiko/insta/master/vscode-insta/images/jump-to-definition.gif)

## Diffing

Insta uses [`similar`](https://github.com/mitsuhiko/similar) for all its diffing
operations. You can use it independently of insta.

## License and Links

- [Project Website](https://insta.rs/)
8 changes: 4 additions & 4 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.6.0"
version = "1.6.1"
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.6.0", path = "..", features = ["redactions"] }
insta = { version = "1.6.1", path = "..", features = ["redactions"] }
console = "0.14.0"
clap = { version = "2.33.3", default-features = false }
difference = "2.0.0"
78 changes: 39 additions & 39 deletions cargo-insta/src/cargo.rs
Original file line number Diff line number Diff line change
@@ -246,47 +246,47 @@ pub fn find_snapshots<'a>(
extensions: &'a [&'a str],
no_ignore: bool,
) -> impl Iterator<Item = Result<SnapshotContainer, Box<dyn Error>>> + 'a {
WalkBuilder::new(root.clone())
let mut builder = WalkBuilder::new(root.clone());
builder
.hidden(false)
.standard_filters(!no_ignore)
.overrides(
// make sure pending snaps are never ignored
OverrideBuilder::new(&root)
.add("**/.*.pending-snap")
.unwrap()
.add("**/*.snap.new")
.unwrap()
.build()
.unwrap(),
)
.filter_entry(|e| e.file_type().map_or(false, |x| x.is_file()) || !is_hidden(e))
.build()
.filter_map(|e| e.ok())
.filter_map(move |e| {
let fname = e.file_name().to_string_lossy();
if fname.ends_with(".new")
&& extensions.contains(&fname.rsplit('.').nth(1).unwrap_or(""))
{
let new_path = e.into_path();
let mut old_path = new_path.clone();
old_path.set_extension("");
Some(SnapshotContainer::load(
new_path,
old_path,
SnapshotContainerKind::External,
))
} else if fname.starts_with('.') && fname.ends_with(".pending-snap") {
let mut target_path = e.path().to_path_buf();
target_path.set_file_name(&fname[1..fname.len() - 13]);
Some(SnapshotContainer::load(
e.path().to_path_buf(),
target_path,
SnapshotContainerKind::Inline,
))
} else {
None
}
})
.filter_entry(|e| e.file_type().map_or(false, |x| x.is_file()) || !is_hidden(e));

let mut override_builder = OverrideBuilder::new(&root);
override_builder
.add(".*.pending-snap")
.unwrap()
.add("*.snap.new")
.unwrap();

for ext in extensions {
override_builder.add(&format!("*.{}.new", ext)).unwrap();
}

builder.overrides(override_builder.build().unwrap());
builder.build().filter_map(|e| e.ok()).filter_map(move |e| {
let fname = e.file_name().to_string_lossy();
if fname.ends_with(".new") {
let new_path = e.into_path();
let mut old_path = new_path.clone();
old_path.set_extension("");
Some(SnapshotContainer::load(
new_path,
old_path,
SnapshotContainerKind::External,
))
} else if fname.starts_with('.') && fname.ends_with(".pending-snap") {
let mut target_path = e.path().to_path_buf();
target_path.set_file_name(&fname[1..fname.len() - 13]);
Some(SnapshotContainer::load(
e.path().to_path_buf(),
target_path,
SnapshotContainerKind::Inline,
))
} else {
None
}
})
}

impl Package {
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.42.0"
5 changes: 1 addition & 4 deletions src/content.rs
Original file line number Diff line number Diff line change
@@ -192,10 +192,7 @@ impl Content {

/// Returns true if the value is nil.
pub fn is_nil(&self) -> bool {
match self.resolve_inner() {
Content::None | Content::Unit => true,
_ => false,
}
matches!(self.resolve_inner(), Content::None | Content::Unit)
}

pub(crate) fn as_key(&self) -> Key<'_> {
52 changes: 36 additions & 16 deletions src/runtime.rs
Original file line number Diff line number Diff line change
@@ -206,8 +206,9 @@ pub fn get_cargo_workspace(manifest_dir: &str) -> &Path {
}
}

fn print_changeset(diff: &TextDiff<str>, expr: Option<&str>) {
fn print_changeset(old: &str, new: &str, expr: Option<&str>) {
let width = term_width();
let diff = TextDiff::from_lines(old, new);

if let Some(expr) = expr {
println!("{:─^1$}", "", width,);
@@ -220,37 +221,54 @@ fn print_changeset(diff: &TextDiff<str>, expr: Option<&str>) {
println!("┈┈┈┈┈┈┈┈┈┈┈┈┼{:┈^1$}", "", width.saturating_sub(13));
}
for op in group {
for change in diff.iter_changes(&op) {
for change in diff.iter_inline_changes(&op) {
match change.tag() {
ChangeTag::Insert => {
has_changes = true;
println!(
"{:>5} {:>5} │{}{}",
print!(
"{:>5} {:>5} │{}",
"",
style(change.new_index().unwrap()).cyan().dim().bold(),
style("+").green(),
style(change.value().trim_end()).green()
);
for &(emphasized, change) in change.values() {
if emphasized {
print!("{}", style(change).green().underlined());
} else {
print!("{}", style(change).green());
}
}
}
ChangeTag::Delete => {
has_changes = true;
println!(
"{:>5} {:>5} │{}{}",
"{:>5} {:>5} │{}",
style(change.old_index().unwrap()).cyan().dim(),
"",
style("-").red(),
style(change.value().trim_end()).red()
);
for &(emphasized, change) in change.values() {
if emphasized {
print!("{}", style(change).red().underlined());
} else {
print!("{}", style(change).red());
}
}
}
ChangeTag::Equal => {
println!(
"{:>5} {:>5} │ {}",
print!(
"{:>5} {:>5} │ ",
style(change.old_index().unwrap()).cyan().dim(),
style(change.new_index().unwrap()).cyan().dim().bold(),
style(change.value().trim_end()).dim()
);
for &(_, change) in change.values() {
print!("{}", style(change).dim());
}
}
}
if change.missing_newline() {
println!();
}
}
}
}
@@ -346,17 +364,19 @@ pub fn print_snapshot_diff(
line: Option<u32>,
) {
print_snapshot_summary(workspace_root, new, snapshot_file, line);
let diff = TextDiff::from_lines(
old_snapshot.as_ref().map_or("", |x| x.contents_str()),
&new.contents_str(),
);
if old_snapshot.is_some() {
let old_contents = old_snapshot.as_ref().map_or("", |x| x.contents_str());
let new_contents = new.contents_str();
if !old_contents.is_empty() {
println!("{}", style("-old snapshot").red());
println!("{}", style("+new results").green());
} else {
println!("{}", style("+new results").green());
}
print_changeset(&diff, new.metadata().expression.as_deref());
print_changeset(
old_contents,
new_contents,
new.metadata().expression.as_deref(),
);
}

fn print_snapshot_diff_with_title(
4 changes: 2 additions & 2 deletions tests/test_clash_detection.rs
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@ fn test_clash_detection() {
let s2 = err2.downcast_ref::<String>().unwrap();
let mut values = vec![s1.as_str(), s2.as_str()];
values.sort();
assert_eq!(&values[..], vec![
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.",
"snapshot assertion for \'foo_always_missing\' failed in line 14",
]);
][..]);
}