diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd4c3608..64525682 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,6 +24,8 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: 1.61.0 + - name: Use Cargo.lock.msrv + run: cp Cargo.lock.msrv Cargo.lock - name: Test run: make cargotest diff --git a/cargo-insta/Cargo.lock b/Cargo.lock.msrv similarity index 81% rename from cargo-insta/Cargo.lock rename to Cargo.lock.msrv index 3422c5a4..7774c40c 100644 --- a/cargo-insta/Cargo.lock +++ b/Cargo.lock.msrv @@ -11,6 +11,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bitflags" version = "1.3.2" @@ -32,7 +44,10 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ + "lazy_static", "memchr", + "regex-automata", + "serde", ] [[package]] @@ -129,6 +144,64 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.11" @@ -149,6 +222,28 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa 0.4.8", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "digest" version = "0.10.5" @@ -159,6 +254,23 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dircpy" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8466f8d28ca6da4c9dfbbef6ad4bff6f2fdd5e412d821025b0d3f0a9d74a8c1e" +dependencies = [ + "jwalk", + "log", + "walkdir", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + [[package]] name = "encode_unicode" version = "0.3.6" @@ -273,12 +385,19 @@ name = "insta" version = "1.33.0" dependencies = [ "console", + "csv", + "globset", "lazy_static", "linked-hash-map", "pest", "pest_derive", + "regex", + "ron", "serde", "similar", + "similar-asserts", + "toml", + "walkdir", "yaml-rust", ] @@ -291,6 +410,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "integration-tests" +version = "0.1.0" +dependencies = [ + "dircpy", + "insta", + "serde", + "walkdir", +] + [[package]] name = "io-lifetimes" version = "1.0.11" @@ -302,12 +431,28 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "jwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2735847566356cd2179a2a38264839308f7079fa96e6bd5a42d740460e003c56" +dependencies = [ + "crossbeam", + "rayon", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -347,6 +492,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.14.0" @@ -439,6 +593,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -459,12 +633,29 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "ron" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" +dependencies = [ + "base64", + "bitflags", + "serde", +] + [[package]] name = "rustix" version = "0.37.19" @@ -494,6 +685,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "semver" version = "1.0.19" @@ -529,7 +726,7 @@ version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ - "itoa", + "itoa 1.0.3", "ryu", "serde", ] @@ -550,6 +747,20 @@ name = "similar" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62ac7f900db32bf3fd12e0117dd3dc4da74bc52ebaac97f39668446d89694803" +dependencies = [ + "bstr", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e041bb827d1bfca18f213411d51b665309f1afb37a04a5d1464530e13779fc0f" +dependencies = [ + "console", + "similar", +] [[package]] name = "structopt" @@ -637,6 +848,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + [[package]] name = "typenum" version = "1.15.0" diff --git a/Cargo.toml b/Cargo.toml index 70fec999..8c91d74a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ exclude = [ all-features = true rustdoc-args = ["--cfg", "docsrs"] +[workspace] +members = ["cargo-insta", "cargo-insta/integration-tests"] + [features] default = ["colors"] diff --git a/Makefile b/Makefile index 481af13c..9c2eddf7 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ cargo-insta-tests: @echo "CARGO-INSTA INTEGRATION TESTS" # Turn off CI flag so that cargo insta test behaves as we expect # under normal operation - @cd cargo-insta/integration-tests; CI=0 cargo run + @CI=0 cargo test -p integration-tests cargotest: @echo "CARGO TESTS" @@ -20,7 +20,7 @@ cargotest: @cargo test --all-features @cargo test --no-default-features @cargo test --features redactions -- --test-threads 1 - @cd cargo-insta; cargo test + @cargo test -p cargo-insta check-minver: @echo "MINVER CHECK" @@ -39,6 +39,6 @@ format-check: lint: @rustup component add clippy 2> /dev/null - @cargo clippy + @cargo clippy --all-targets --workspace -- --deny warnings .PHONY: all doc test cargotest format format-check lint update-readme diff --git a/cargo-insta/.gitignore b/cargo-insta/.gitignore deleted file mode 100644 index eb5a316c..00000000 --- a/cargo-insta/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target diff --git a/cargo-insta/integration-tests/.gitignore b/cargo-insta/integration-tests/.gitignore deleted file mode 100644 index c960903e..00000000 --- a/cargo-insta/integration-tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -tests/ -Cargo.lock diff --git a/cargo-insta/integration-tests/src/main.rs b/cargo-insta/integration-tests/src/main.rs index 74a801b1..08ea6011 100644 --- a/cargo-insta/integration-tests/src/main.rs +++ b/cargo-insta/integration-tests/src/main.rs @@ -1,69 +1,81 @@ -use std::env; -use std::fs; -use std::path::Path; -use std::process::{Output, Command}; +fn main() {} -use dircpy::CopyBuilder; -use insta::{assert_snapshot, Settings}; -use walkdir::WalkDir; +#[cfg(test)] +mod tests { + use std::env; + use std::fs; + use std::path::Path; + use std::process::{Command, Output}; -fn main() { - // copy new tests over - fs::remove_dir_all("tests").ok(); - CopyBuilder::new("test-input", "tests") - .overwrite(true) - .run() - .unwrap(); + use dircpy::CopyBuilder; + use insta::{assert_snapshot, Settings}; + use walkdir::WalkDir; - // delete old build artifacts - Command::new("cargo") - .arg("clean") - .arg("--package=integration-tests") - .status() - .unwrap(); + struct OnDrop(Option); - // make sure cargo-insta is built - Command::new("cargo") - .arg("build") - .current_dir("..") - .status() - .unwrap(); + impl Drop for OnDrop { + fn drop(&mut self) { + let Self(f) = self; + f.take().unwrap()(); + } + } - // run tests and accept snapshots - let Output { - status, - stdout, - stderr, - } = Command::new("../target/debug/cargo-insta") - .arg("test") - .arg("--accept") - .arg("--no-ignore") - .output() - .unwrap(); - let stdout = String::from_utf8(stdout); - let stderr = String::from_utf8(stderr); - assert!(status.success(), "stdout={:?}\nstderr={:?}", stdout, stderr); - let stdout = stdout.unwrap(); - let stderr = stderr.unwrap(); - assert!(stdout.contains("accepted:\n"), "{}", stdout); - assert!(stderr.contains("Compiling integration-tests"), "{}", stderr); + #[test] + fn main() { + const NO_RECURSION: &str = "CARGO_INSTA_INTEGRATION_TESTS_NO_RECURSION"; + + if env::var_os(NO_RECURSION).is_some() { + return; + } - // 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() + // copy new tests over + CopyBuilder::new("test-input", "tests") + .overwrite(true) + .run() .unwrap(); - if let Some(snapshot) = filename.strip_suffix(".rs") { - let gen_file = Path::new("tests").join(filename); - let mut settings = Settings::clone_current(); - settings.set_input_file(&gen_file); - settings.bind(|| { - assert_snapshot!(snapshot, &fs::read_to_string(gen_file).unwrap()); - }); + // ensure cargo doesn't try to run these tests on the next invocation + let _on_drop = OnDrop(Some(|| fs::remove_dir_all("tests").unwrap())); + + // run tests and accept snapshots + let Output { + status, + stdout, + stderr, + } = Command::new("cargo") + .env(NO_RECURSION, "this value doesn't matter") + .arg("run") + .arg("--package=cargo-insta") + .arg("--") + .arg("test") + .arg("--accept") + .arg("--no-ignore") + .output() + .unwrap(); + let stdout = String::from_utf8(stdout); + let stderr = String::from_utf8(stderr); + assert!(status.success(), "stdout={:?}\nstderr={:?}", stdout, stderr); + let stdout = stdout.unwrap(); + let stderr = stderr.unwrap(); + assert!(stdout.contains("accepted:\n"), "{}", stdout); + assert!(stderr.contains("Compiling integration-tests"), "{}", stderr); + + // 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 let Some(snapshot) = filename.strip_suffix(".rs") { + let gen_file = Path::new("tests").join(filename); + let mut settings = Settings::clone_current(); + settings.set_input_file(&gen_file); + settings.bind(|| { + assert_snapshot!(snapshot, &fs::read_to_string(gen_file).unwrap()); + }); + } } } } diff --git a/cargo-insta/integration-tests/src/snapshots/integration_tests__test_basic_utf8_inline.snap b/cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_basic_utf8_inline.snap similarity index 100% rename from cargo-insta/integration-tests/src/snapshots/integration_tests__test_basic_utf8_inline.snap rename to cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_basic_utf8_inline.snap diff --git a/cargo-insta/integration-tests/src/snapshots/integration_tests__test_json_inline.snap b/cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_json_inline.snap similarity index 100% rename from cargo-insta/integration-tests/src/snapshots/integration_tests__test_json_inline.snap rename to cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_json_inline.snap diff --git a/cargo-insta/integration-tests/src/snapshots/integration_tests__test_yaml_inline.snap b/cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_yaml_inline.snap similarity index 100% rename from cargo-insta/integration-tests/src/snapshots/integration_tests__test_yaml_inline.snap rename to cargo-insta/integration-tests/src/snapshots/integration_tests__tests__test_yaml_inline.snap diff --git a/cargo-insta/src/cli.rs b/cargo-insta/src/cli.rs index 444729c6..936fd546 100644 --- a/cargo-insta/src/cli.rs +++ b/cargo-insta/src/cli.rs @@ -45,6 +45,7 @@ struct Opts { bin_name = "cargo insta", after_help = "For the online documentation of the latest version, see https://insta.rs/docs/cli/." )] +#[allow(clippy::large_enum_variant)] enum Command { /// Interactively review snapshots #[structopt(name = "review", alias = "verify")] @@ -415,6 +416,7 @@ fn handle_target_args(target_args: &TargetArgs) -> Result, Box< } } +#[allow(clippy::type_complexity)] fn load_snapshot_containers<'a>( loc: &'a LocationInfo, ) -> Result< @@ -775,6 +777,7 @@ fn handle_unreferenced_snapshots( Ok(()) } +#[allow(clippy::type_complexity)] fn prepare_test_runner<'snapshot_ref>( test_runner: TestRunner, unreferenced: UnreferencedSnapshots, diff --git a/cargo-insta/src/inline.rs b/cargo-insta/src/inline.rs index 1142e451..48c43f16 100644 --- a/cargo-insta/src/inline.rs +++ b/cargo-insta/src/inline.rs @@ -104,7 +104,7 @@ impl FilePatcher { // replace lines let snapshot_line_contents = - vec![prefix, snapshot.to_inline(inline.indentation), suffix].join(""); + [prefix, snapshot.to_inline(inline.indentation), suffix].join(""); self.lines.splice( inline.start.0..=inline.end.0, diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index 45317f41..97557c87 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -11,4 +11,4 @@ perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" Cargo.toml perl -pi -e "s/^version = \".*?\"/version = \"$NEW_VERSION\"/" cargo-insta/Cargo.toml perl -pi -e "s/^(insta.*?)version = \".*?\"/\$1version = \"=$NEW_VERSION\"/" cargo-insta/Cargo.toml -cd cargo-insta; cargo check +cargo check -p cargo-insta diff --git a/scripts/publish-all.sh b/scripts/publish-all.sh index 6a49bb18..056840ec 100755 --- a/scripts/publish-all.sh +++ b/scripts/publish-all.sh @@ -5,4 +5,4 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $SCRIPT_DIR/.. cargo publish -p insta -cd cargo-insta && cargo publish +cargo publish -p cargo-insta diff --git a/src/snapshot.rs b/src/snapshot.rs index fe15daa4..573e675d 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -727,7 +727,7 @@ b"[1..]; ); let t = "ab"; - assert_eq!(SnapshotContents(t.to_string()).to_inline(0), r##""ab""##); + assert_eq!(SnapshotContents(t.to_string()).to_inline(0), r#""ab""#); } #[test] diff --git a/tests/test_clash_detection.rs b/tests/test_clash_detection.rs index eeed0899..f65ce18f 100644 --- a/tests/test_clash_detection.rs +++ b/tests/test_clash_detection.rs @@ -44,7 +44,7 @@ fn test_clash_detection() { let s1 = err1.downcast_ref::().unwrap(); let s2 = err2.downcast_ref::().unwrap(); - let mut values = vec![s1.as_str(), s2.as_str()]; + let mut values = [s1.as_str(), s2.as_str()]; values.sort(); 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.",