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.18.2
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.19.0
Choose a head ref
  • 9 commits
  • 13 files changed
  • 1 contributor

Commits on Aug 8, 2022

  1. Copy the full SHA
    25ef917 View commit details

Commits on Aug 9, 2022

  1. Copy the full SHA
    c27e1cc View commit details

Commits on Aug 10, 2022

  1. Copy the full SHA
    a458a43 View commit details

Commits on Aug 11, 2022

  1. Merge branch 'release/1.18'

    mitsuhiko committed Aug 11, 2022
    Copy the full SHA
    eea3331 View commit details

Commits on Aug 12, 2022

  1. Make clippy happy

    mitsuhiko committed Aug 12, 2022
    Copy the full SHA
    cee5dad View commit details

Commits on Aug 16, 2022

  1. Copy the full SHA
    6808c0e View commit details

Commits on Aug 21, 2022

  1. Copy the full SHA
    0557ab2 View commit details
  2. Added changelog entry

    mitsuhiko committed Aug 21, 2022
    Copy the full SHA
    7e9ab23 View commit details
  3. 1.19.0

    mitsuhiko committed Aug 21, 2022
    Copy the full SHA
    4f5b102 View commit details
Showing with 118 additions and 99 deletions.
  1. +11 −0 CHANGELOG.md
  2. +2 −17 Cargo.toml
  3. +2 −2 cargo-insta/Cargo.lock
  4. +2 −2 cargo-insta/Cargo.toml
  5. +1 −1 cargo-insta/integration-tests/Cargo.toml
  6. +19 −0 cargo-insta/src/cli.rs
  7. +1 −1 src/content/mod.rs
  8. +26 −2 src/glob.rs
  9. +0 −36 src/lib.rs
  10. +23 −23 src/macros.rs
  11. +1 −1 src/redaction.rs
  12. +29 −13 src/runtime.rs
  13. +1 −1 src/snapshot.rs
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,17 @@

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

## 1.19.0

- Removed `backtrace` feature.
- Removed `serialization` feature.
- `assert_json_snapshot!` and `assert_yaml_snapshot!` now require
the `json` and `yaml` feature respectively.
- Doctests now emit a warning that inline snapshot updating is
not supported (#272)
- Added support for `INSTA_GLOB_FILTER` to skip over tests expanded
from a glob. (#274)

## 1.18.2

- Avoid the use of `#[allow(unused)]` in the macro. (#271)
19 changes: 2 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "insta"
version = "1.18.2"
version = "1.19.0"
license = "Apache-2.0"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
description = "A snapshot testing library for Rust"
@@ -19,7 +19,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["colors", "__private_legacy_default_serialization"]
default = ["colors"]

# when the redactions feature is enabled values can be redacted in serialized
# snapshots.
@@ -43,21 +43,6 @@ ron = ["dep_ron", "serde"]
toml = ["dep_toml", "serde"]
yaml = ["serde"]

# legacy support. This is turned on by default for a single release and turns
# on the assert_json_snapshot! and assert_yaml_snapshot! macros by default.
# This will be phased out. Use the "json" and "yaml" features instead.
# If you already want to benefit of the leaner defaults, turn off the default
# features and opt into what you want manually (you probably want to turn on "colors").
__private_legacy_default_serialization = ["serde"]

# This is a deprecated and unused feature. The first feature is what was available
# in teh past and should no longer be used. The second feature exists to hide the
# warning when testing with all features is enabled. Both those features will go
# away soon.
backtrace = []
serialization = []
__private_hide_feature_deprecation_warning = []

[dependencies]
dep_csv = { package = "csv", version = "1.1.4", optional = true }
console = { version = "0.15.1", optional = true, default-features = false }
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.18.2"
version = "1.19.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.18.2", path = "..", features = ["json", "yaml", "redactions"] }
insta = { version = "=1.19.0", path = "..", features = ["json", "yaml", "redactions"] }
console = "0.15.1"
structopt = "0.3.20"
serde = { version = "1.0.117", features = ["derive"] }
2 changes: 1 addition & 1 deletion cargo-insta/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,6 @@ edition = "2018"

[dependencies]
dircpy = "0.3.4"
insta = { version = "1.1.0", path = "../..", features = ["json", "yaml", "redactions", "glob"] }
insta = { path = "../..", features = ["json", "yaml", "redactions", "glob"] }
walkdir = "2.3.1"
serde = { version = "1.0.117", features = ["derive"] }
19 changes: 19 additions & 0 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,
/// Filters to apply to the insta glob feature.
#[structopt(long)]
pub glob_filter: Vec<String>,
/// Do not pass the quiet flag (`-q`) to tests.
#[structopt(short = "Q", long)]
pub no_quiet: bool,
@@ -558,6 +561,22 @@ fn test_run(mut cmd: TestCommand, color: &str) -> Result<(), Box<dyn Error>> {
if cmd.force_update_snapshots {
proc.env("INSTA_FORCE_UPDATE_SNAPSHOTS", "1");
}

let glob_filter =
cmd.glob_filter
.iter()
.map(|x| x.as_str())
.fold(String::new(), |mut s, item| {
if !s.is_empty() {
s.push(';');
}
s.push_str(item);
s
});
if !glob_filter.is_empty() {
proc.env("INSTA_GLOB_FILTER", glob_filter);
}

if cmd.release {
proc.arg("--release");
}
2 changes: 1 addition & 1 deletion src/content/mod.rs
Original file line number Diff line number Diff line change
@@ -207,7 +207,7 @@ impl Content {
/// Returns the value as bytes
pub fn as_bytes(&self) -> Option<&[u8]> {
match self.resolve_inner() {
Content::Bytes(ref b) => Some(&*b),
Content::Bytes(ref b) => Some(b),
_ => None,
}
}
28 changes: 26 additions & 2 deletions src/glob.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
use std::env;
use std::path::Path;

use globset::GlobBuilder;
use globset::{GlobBuilder, GlobMatcher};
use once_cell::sync::Lazy;
use walkdir::WalkDir;

use crate::settings::Settings;

static GLOB_FILTER: Lazy<Vec<GlobMatcher>> = Lazy::new(|| {
env::var("INSTA_GLOB_FILTER")
.unwrap_or_default()
.split(';')
.filter(|x| !x.is_empty())
.filter_map(|filter| {
GlobBuilder::new(filter)
.case_insensitive(true)
.build()
.ok()
.map(|x| x.compile_matcher())
})
.collect()
});

pub fn glob_exec<F: FnMut(&Path)>(base: &Path, pattern: &str, mut f: F) {
let glob = GlobBuilder::new(pattern)
.case_insensitive(true)
@@ -25,10 +42,17 @@ pub fn glob_exec<F: FnMut(&Path)>(base: &Path, pattern: &str, mut f: F) {
continue;
}

glob_found_matches = true;

// if there is a glob filter, skip if it does not match this path
if !GLOB_FILTER.is_empty() && !GLOB_FILTER.iter().any(|x| x.is_match(stripped_path)) {
eprintln!("Skipping {} due to glob filter", stripped_path.display());
continue;
}

settings.set_input_file(&path);
settings.set_snapshot_suffix(path.file_name().unwrap().to_str().unwrap());

glob_found_matches = true;
settings.bind(|| {
f(path);
});
36 changes: 0 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -274,39 +274,3 @@ pub mod _macro_support {
redaction::Redaction, redaction::Selector, serialization::serialize_value_redacted,
};
}

// These are hidden modules that exists to emit a deprecation warning when the
// "backtrace" / "serialization" features are enabled. It's used by the
// `assert_snapshot!` macro.
#[doc(hidden)]
#[cfg_attr(
all(
feature = "backtrace",
not(feature = "__private_hide_feature_deprecation_warning")
),
deprecated(
note = "You are using insta with the deprecated \"backtrace\" feature. \
Remove this feature from your Cargo.toml as it will go away in future insta versions. \
The functionality provided by this feature is now available out of the box."
)
)]
pub mod deprecated_backtrace_support {
pub fn backtrace_dummy() {}
}

#[doc(hidden)]
#[cfg_attr(
all(
feature = "serialization",
not(feature = "__private_hide_feature_deprecation_warning")
),
deprecated(
note = "You are using insta with the deprecated \"serialization\" feature. \
Remove this feature from your Cargo.toml as it will go away in future insta versions. \
The functionality provided by this feature is now available when you use one of the \
serialization features such as \"yaml\", \"json\" or similar."
)
)]
pub mod deprecated_serialization_support {
pub fn serialization_dummy() {}
}
46 changes: 23 additions & 23 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -146,12 +146,7 @@ macro_rules! assert_toml_snapshot {
/// just use an empty string (`@""`).
///
/// The snapshot name is optional but can be provided as first argument.
#[cfg(feature = "serde")]
#[cfg_attr(
not(feature = "yaml"),
deprecated(note = "assert_yaml_snapshot! will require the \"yaml\" feature. \
Add the \"yaml\" feature to your Cargo.toml to silence this warning.")
)]
#[cfg(feature = "yaml")]
#[cfg_attr(docsrs, doc(cfg(feature = "yaml")))]
#[macro_export]
macro_rules! assert_yaml_snapshot {
@@ -239,12 +234,7 @@ macro_rules! assert_ron_snapshot {
/// about redactions refer to the [redactions feature in the guide](https://insta.rs/docs/redactions/).
///
/// The snapshot name is optional but can be provided as first argument.
#[cfg(feature = "serde")]
#[cfg_attr(
not(feature = "json"),
deprecated(note = "assert_json_snapshot! will require the \"json\" feature. \
Add the \"json\" feature to your Cargo.toml to silence this warning.")
)]
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[macro_export]
macro_rules! assert_json_snapshot {
@@ -417,16 +407,6 @@ macro_rules! assert_snapshot {
$crate::assert_snapshot!($name, $value, stringify!($value))
};
($name:expr, $value:expr, $debug_expr:expr) => {{
// This use does not do anything. It exists purely to trigger a deprecation warning
// for the features if enabled. The dummy function calls exist so that we do not
// need to use `#[allow(unused)]` (https://github.com/mitsuhiko/insta/issues/271)
{
use $crate::deprecated_backtrace_support::*;
use $crate::deprecated_serialization_support::*;
backtrace_dummy();
serialization_dummy();
}

$crate::_macro_support::assert_snapshot(
// Creates a ReferenceValue::Named variant
$name.into(),
@@ -487,7 +467,27 @@ macro_rules! with_settings {

/// Executes a closure for all input files matching a glob.
///
/// The closure is passed the path to the file.
/// The closure is passed the path to the file. You can use [`std::fs::read_to_string`]
/// or similar functions to load the file and process it.
///
/// ```
/// # use insta::{assert_snapshot, glob, Settings};
/// # let mut settings = Settings::clone_current();
/// # settings.set_allow_empty_glob(true);
/// # let _dropguard = settings.bind_to_scope();
/// use std::fs;
///
/// glob!("inputs/*.txt", |path| {
/// let input = fs::read_to_string(path).unwrap();
/// assert_snapshot!(input.to_uppercase());
/// });
/// ```
///
/// The `INSTA_GLOB_FILTER` environment variable can be set to only execute certain files.
/// The format of the filter is a semicolon separated filter. For instance by setting
/// `INSTA_GLOB_FILTER` to `foo-*txt;bar-*.txt` only files starting with `foo-` or `bar-`
/// end ending in `.txt` will be executed. When using `cargo-insta` the `--glob-filter`
/// option can be used instead.
#[cfg(feature = "glob")]
#[cfg_attr(docsrs, doc(cfg(feature = "glob")))]
#[macro_export]
2 changes: 1 addition & 1 deletion src/redaction.rs
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ impl PathItem {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Segment<'a> {
DeepWildcard,
Wildcard,
Loading