Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chris-morgan opened this issue Oct 17, 2024 · 2 comments
Open

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

chris-morgan opened this issue Oct 17, 2024 · 2 comments

Comments

@chris-morgan
Copy link

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<Self> {
┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈
  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
Copy link
Collaborator

mystor commented Oct 21, 2024

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

cargo-vet/src/main.rs

Lines 2148 to 2167 in 579fb7d

for (from, to) in to_compare {
let output = std::process::Command::new("git")
.arg("-c")
.arg("core.safecrlf=false")
.arg("diff")
.arg(if pager.use_color() {
"--color=always"
} else {
"--color=never"
})
.arg("--no-index")
.arg("--ignore-cr-at-eol")
.arg(&from)
.arg(&to)
.stdout(Stdio::piped())
.output()
.map_err(CommandError::CommandFailed)
.into_diagnostic()?;
io::Write::write_all(&mut pager, &output.stdout).into_diagnostic()?;
}

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants