Skip to content

Commit ad05cec

Browse files
committed
Auto merge of #10620 - weihanglo:snapbox-cargo-init, r=epage
Migrate tests of `cargo-init` to snapbox ### What does this PR try to resolve? An attempt of migrating tests of `cargo-init` to [snapbox](https://crates.io/crates/snapbox/). ### How should we test and review this PR? To review this PR, you may compare the old and the new version one by one. Files not listed in `<test-name>.out` are not asserted, so please help me make sure we don't miss any essential file to check. Some redundant tests are covered by other tests or renamed. ### Additional information I won't say the process of the migration was pleasant, but overall it results to a higher coverage of output file changes. Here are steps I performed to migrate a test case: 1. Run the old test and observe its output layout. Recommend using a separate worktree to preserve the temporary test output files. 2. Read the test code to arrange its input fixture at `<test-name>.in`. 3. Copy the old output layout or hand-pick the output layout you need. You don't need to fill contents of those files. `snapbox` will do it for you. 4. Run `SNAPSHOTS=overwrite cargo test --test testsuite <your-test-filter>` to assert and generate snapshots. 5. Compare the old layout and the new layout to see if anything missing. Something observations when dealing with the migration: * snapbox hasn't yet support unordered assertion. * snapbox cannot assert inexistence of a file (And probably never?). * No performance hit so far (measured with hyperfine).
2 parents cfb8969 + 20c0c58 commit ad05cec

File tree

193 files changed

+1112
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+1112
-506
lines changed

tests/snapshots/init/auto_git.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
empty-dir
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/Cargo.lock
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "case"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(test)]
2+
mod tests {
3+
#[test]
4+
fn it_works() {
5+
let result = 2 + 2;
6+
assert_eq!(result, 4);
7+
}
8+
}

tests/snapshots/init/auto_git.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Created library package

tests/snapshots/init/auto_git.stdout

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("Check that our file is not overwritten")
3+
}
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "case"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("Check that our file is not overwritten")
3+
}
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Created binary (application) package

0 commit comments

Comments
 (0)