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.1.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.2.0
Choose a head ref
  • 10 commits
  • 22 files changed
  • 3 contributors

Commits on Nov 6, 2020

  1. Switch to GHA

    mitsuhiko committed Nov 6, 2020
    Copy the full SHA
    321920c View commit details
  2. Fix a workflow name

    mitsuhiko committed Nov 6, 2020
    Copy the full SHA
    9e79c94 View commit details

Commits on Nov 12, 2020

  1. Added support for newtype variant redactions. (#139)

    Co-authored-by: Michel Meyer <mm@cudera.ch>
    zazabe and Michel Meyer authored Nov 12, 2020
    Copy the full SHA
    fcec7d0 View commit details
  2. ref: cargo fmt

    mitsuhiko committed Nov 12, 2020
    Copy the full SHA
    831f59f View commit details

Commits on Nov 15, 2020

  1. Copy the full SHA
    138d173 View commit details
  2. Update changelog

    mitsuhiko committed Nov 15, 2020
    Copy the full SHA
    74f7a01 View commit details
  3. Copy the full SHA
    aa2a91f View commit details
  4. Copy the full SHA
    cfb0837 View commit details
  5. Copy the full SHA
    90f285a View commit details
  6. 1.2.0

    mitsuhiko committed Nov 15, 2020
    Copy the full SHA
    8bb2fdf View commit details
13 changes: 13 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Clippy

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Run clippy
run: make lint
13 changes: 13 additions & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Rustfmt

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Run rustfmt
run: make format-check
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Tests

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Test
run: make test
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.2.0

* 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
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.1.0"
version = "1.2.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -6,9 +6,14 @@ build:
doc:
@cargo doc --all-features

test: cargotest
test: cargotest cargo-insta-tests

cargo-insta-tests:
@echo "CARGO-INSTA INTEGRATION TESTS"
@cd cargo-insta/integration-tests; cargo run

cargotest:
@echo "CARGO TESTS"
@rustup component add rustfmt 2> /dev/null
@cargo test
@cargo test --all-features
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.1.0"
version = "1.2.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"
@@ -11,7 +11,7 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "1.1.0", path = "..", features = ["redactions"] }
insta = { version = "1.2.0", path = "..", features = ["redactions"] }
console = "0.12.0"
clap = "2.33.0"
difference = "2.0.0"
2 changes: 2 additions & 0 deletions cargo-insta/integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/
Cargo.lock
13 changes: 13 additions & 0 deletions cargo-insta/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "integration-tests"
version = "0.1.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dircpy = "0.3.4"
insta = { version = "1.1.0", path = "../..", features = ["redactions", "glob"] }
walkdir = "2.3.1"
serde = { version = "1.0.117", features = ["derive"] }
58 changes: 58 additions & 0 deletions cargo-insta/integration-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;

use dircpy::CopyBuilder;
use insta::{assert_snapshot, Settings};
use walkdir::WalkDir;

fn main() {
// copy new tests over
fs::remove_dir_all("tests").ok();
CopyBuilder::new("test-input", "tests")
.overwrite(true)
.run()
.unwrap();

// delete old build artifacts
Command::new("cargo")
.arg("clean")
.arg("--package=integration-tests")
.status()
.unwrap();

// make sure cargo-insta is built
Command::new("cargo")
.arg("build")
.current_dir("..")
.status()
.unwrap();

// run tests and accept snapshots
Command::new("../target/debug/cargo-insta")
.arg("test")
.arg("--accept")
.status()
.unwrap();

// use insta itself to assert snapshots
for entry in WalkDir::new("test-input") {
let entry = entry.unwrap();
let filename = entry
.path()
.strip_prefix("test-input/")
.unwrap()
.to_str()
.unwrap();
if filename.ends_with(".rs") {
let gen_file = Path::new("tests").join(filename);
let mut settings = Settings::clone_current();
settings.set_input_file(&gen_file);
let snapshot = &filename[..filename.len() - 3];
settings.bind(|| {
assert_snapshot!(snapshot, &fs::read_to_string(gen_file).unwrap());
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: src/main.rs
expression: "&fs::read_to_string(gen_file).unwrap()"
input_file: tests/test_basic_utf8_inline.rs
---
#[test]
#[rustfmt::skip]
fn test_non_basic_plane() {
/* an offset here ❄️ */ insta::assert_snapshot!("a 😀oeu", @"a 😀oeu");
}

#[test]
fn test_remove_existing_value() {
insta::assert_snapshot!("this is the new value", @"this is the new value");
}

#[test]
fn test_remove_existing_value_multiline() {
insta::assert_snapshot!(
"this is the new value",
@"this is the new value"
);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: src/main.rs
expression: "&fs::read_to_string(gen_file).unwrap()"
input_file: tests/test_json_inline.rs
---
use serde::Serialize;

#[derive(Serialize)]
struct User {
id: u64,
email: String,
}

#[test]
fn test_json_snapshot() {
let user = User {
id: 42,
email: "john.doe@example.com".into(),
};
insta::assert_json_snapshot!(&user, {
".id" => "[user_id]",
}, @r###"
{
"id": "[user_id]",
"email": "john.doe@example.com"
}
"###);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: src/main.rs
expression: "&fs::read_to_string(gen_file).unwrap()"
input_file: tests/test_yaml_inline.rs
---
use serde::Serialize;

#[derive(Serialize)]
struct User {
id: u64,
email: String,
}

#[test]
fn test_yaml_snapshot() {
let user = User {
id: 42,
email: "john.doe@example.com".into(),
};
insta::assert_yaml_snapshot!(&user, {
".id" => "[user_id]",
}, @r###"
---
id: "[user_id]"
email: john.doe@example.com
"###);
}

20 changes: 20 additions & 0 deletions cargo-insta/integration-tests/test-input/test_basic_utf8_inline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[test]
#[rustfmt::skip]
fn test_non_basic_plane() {
/* an offset here ❄️ */ insta::assert_snapshot!("a 😀oeu", @"");
}

#[test]
fn test_remove_existing_value() {
insta::assert_snapshot!("this is the new value", @"this is the old value");
}

#[test]
fn test_remove_existing_value_multiline() {
insta::assert_snapshot!(
"this is the new value",
@"this is\
this is the old value\
it really is"
);
}
18 changes: 18 additions & 0 deletions cargo-insta/integration-tests/test-input/test_json_inline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use serde::Serialize;

#[derive(Serialize)]
struct User {
id: u64,
email: String,
}

#[test]
fn test_json_snapshot() {
let user = User {
id: 42,
email: "john.doe@example.com".into(),
};
insta::assert_json_snapshot!(&user, {
".id" => "[user_id]",
}, @"");
}
18 changes: 18 additions & 0 deletions cargo-insta/integration-tests/test-input/test_yaml_inline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use serde::Serialize;

#[derive(Serialize)]
struct User {
id: u64,
email: String,
}

#[test]
fn test_yaml_snapshot() {
let user = User {
id: 42,
email: "john.doe@example.com".into(),
};
insta::assert_yaml_snapshot!(&user, {
".id" => "[user_id]",
}, @"");
}
10 changes: 8 additions & 2 deletions cargo-insta/src/inline.rs
Original file line number Diff line number Diff line change
@@ -75,8 +75,14 @@ impl FilePatcher {
let inline = &mut self.inline_snapshots[id];

// find prefix and suffix on the first and last lines
let prefix = self.lines[inline.start.0][..inline.start.1].to_string();
let suffix = self.lines[inline.end.0][inline.end.1..].to_string();
let prefix: String = self.lines[inline.start.0]
.chars()
.take(inline.start.1)
.collect();
let suffix: String = self.lines[inline.end.0]
.chars()
.skip(inline.end.1)
.collect();

// replace lines
let snapshot_line_contents =
1 change: 1 addition & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ NEW_VERSION="${1}"
echo "Bumping version: ${NEW_VERSION}"
perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" Cargo.toml
perl -pi -e "s/^(insta.*)?version = \".*?\"/\$1version = \"$NEW_VERSION\"/" cargo-insta/Cargo.toml
cd cargo-insta; cargo check
8 changes: 8 additions & 0 deletions src/redaction.rs
Original file line number Diff line number Diff line change
@@ -450,6 +450,14 @@ impl<'a> Selector<'a> {
name,
Box::new(self.redact_impl(*inner, redaction, path)),
),
Content::NewtypeVariant(name, index, variant_name, inner) => {
Content::NewtypeVariant(
name,
index,
variant_name,
Box::new(self.redact_impl(*inner, redaction, path)),
)
}
Content::Some(contents) => {
Content::Some(Box::new(self.redact_impl(*contents, redaction, path)))
}
Loading