mozilla / cargo-vet

supply-chain security for Rust
Apache License 2.0
665 stars 46 forks source link

Tests failing in 0.10.0 (test-project-diff-output) #638

Open chris-morgan opened 1 week ago

chris-morgan commented 1 week ago

Executing the following on my Arch Linux machine, using the v0.10.0 source tarball:

tar xaf source.tar.gz
cd cargo-vet-0.10.0
cargo fetch --locked --target x86_64-unknown-linux-gnu
export RUSTUP_TOOLCHAIN=stable
export CARGO_TARGET_DIR=target
cargo build --frozen --release
cargo test --frozen

The tests fail in test-project-diff-output/format_diff_outputs.

Detailed output ``` ---- test_project_diff_output stdout ---- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Differences ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot file: tests/snapshots/test_cli__test-project-diff-output.snap Snapshot: test-project-diff-output Source: tests/test-cli.rs:284 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Expression: format_diff_outputs(&output) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -old snapshot +new results ────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 72 72 │ + if input.peek(Lit) { 73 73 │ + let lit = input.parse()?; 74 74 │ + return Ok(GenericMethodArgument::Const(Expr::Lit(lit))); 75 75 │ + } 76 │-+ 77 │-+ if input.peek(token::Brace) { 78 │-+ let block: ExprBlock = input.parse()?; 79 │-+ return Ok(GenericMethodArgument::Const(Expr::Block(block))); 80 │-+ } 81 76 │ 82 77 │ - if input.peek(token::Brace) { 83 78 │ - let block: ExprBlock = input.parse()?; 84 79 │ - return Ok(GenericMethodArgument::Const(Expr::Block(block))); 85 │-+ input.parse().map(GenericMethodArgument::Type) 86 │- } 87 │-+ } 80 │+- } 81 │++ if input.peek(token::Brace) { 82 │++ let block: ExprBlock = input.parse()?; 83 │++ return Ok(GenericMethodArgument::Const(Expr::Block(block))); 84 │++ } 88 85 │ 89 86 │ - input.parse().map(GenericMethodArgument::Type) 87 │++ input.parse().map(GenericMethodArgument::Type) 88 │++ } 89 │++ } 90 │++ 90 91 │ + #[cfg(feature = "full")] 91 92 │ + #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] 92 93 │ + impl Parse for MethodTurbofish { 93 94 │ + fn parse(input: ParseStream) -> Result { ┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ 141 142 │ + ExprType, Type, "expected type ascription expression", 142 143 │ } 143 144 │ 144 145 │ #[cfg(feature = "full")] 145 │-@@ -3346,14 +3358,22 @@ pub(crate) mod printing { 146 │+@@ -3344,16 +3356,24 @@ pub(crate) mod printing { 147 │+ } 148 │+ } 146 149 │ 147 │- #[cfg(feature = "full")] 148 │- #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] 149 │-- impl ToTokens for ExprRange { 150 │++ #[cfg(feature = "full")] 151 │++ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] 150 152 │ + impl ToTokens for RangeLimits { 151 │- fn to_tokens(&self, tokens: &mut TokenStream) { 152 │-- outer_attrs_to_tokens(&self.attrs, tokens); 153 │-- self.from.to_tokens(tokens); 154 │-- match &self.limits { 153 │++ fn to_tokens(&self, tokens: &mut TokenStream) { 155 154 │ + match self { 156 │- RangeLimits::HalfOpen(t) => t.to_tokens(tokens), 157 │- RangeLimits::Closed(t) => t.to_tokens(tokens), 158 │- } 155 │++ RangeLimits::HalfOpen(t) => t.to_tokens(tokens), 156 │++ RangeLimits::Closed(t) => t.to_tokens(tokens), 157 │++ } 159 158 │ + } 160 159 │ + } 161 160 │ + 162 │-+ #[cfg(feature = "full")] 163 │-+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] 164 │-+ impl ToTokens for ExprRange { 165 │-+ fn to_tokens(&self, tokens: &mut TokenStream) { 166 │-+ outer_attrs_to_tokens(&self.attrs, tokens); 167 │-+ self.from.to_tokens(tokens); 161 │+ #[cfg(feature = "full")] 162 │+ #[cfg_attr(doc_cfg, doc(cfg(feature = "printing")))] 163 │+ impl ToTokens for ExprRange { 164 │+ fn to_tokens(&self, tokens: &mut TokenStream) { 165 │+ outer_attrs_to_tokens(&self.attrs, tokens); 166 │+ self.from.to_tokens(tokens); 167 │+- match &self.limits { 168 │+- RangeLimits::HalfOpen(t) => t.to_tokens(tokens), 169 │+- RangeLimits::Closed(t) => t.to_tokens(tokens), 170 │+- } 168 171 │ + self.limits.to_tokens(tokens); 169 172 │ self.to.to_tokens(tokens); 170 173 │ } 171 174 │ } ────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── To update snapshots run `cargo insta review` Stopped on the first failure. Run `cargo insta test` to run all snapshots. thread 'test_project_diff_output' panicked at /home/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/insta-1.16.0/src/runtime.rs:439:9: snapshot assertion for 'test-project-diff-output' failed in line 284 ```
mystor commented 2 days ago

This test is checking the output of cargo vet diff, which is actually the git diff output with a few settings configured:

https://github.com/mozilla/cargo-vet/blob/579fb7d9e4155d4ec5e67f9b6f7f4633cb1a0440/src/main.rs#L2148-L2167

I'm guessing your local git configuration is configured to either use a different diff backend or in some other way ignore whitespace changes when generating diffs. cargo vet diff doesn't end up normalizing that, so the diff output appears different and the test fails.

I don't know of a convenient way off the top of my head to fully ignore user customization of git settings in the test, and diabling all user customizations when running the subcommand seems somewhat undesirable.

chris-morgan commented 15 hours ago

During the test, set the environment variables GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_SYSTEM=/dev/null, and then it succeeds.