sourcefrog / cargo-mutants

:zombie: Inject bugs and see if your tests catch them!
https://mutants.rs/
MIT License
577 stars 27 forks source link

Cannot execute cargo mutants after git commit. #32

Closed tobollam closed 2 years ago

tobollam commented 2 years ago

Hi.

I created a simple fizz buzz program as example. Executing 'cargo mutants' leads to the result

$ cargo mutants
Freshen source tree ... ok in 0.184s
Copy source and build products to scratch directory ... 7 MB in 0.326s 
Unmutated baseline ... ok in 1.892s   
Auto-set test timeout to 20.0s   
Found 2 mutations to test   

after executing

git add .
git commit -m "Example"

in a git Bash, executing 'cargo mutants' leads to s different result.

$ cargo mutants
Freshen source tree ... ok in 0.154s
Copy source and build products to scratch directory ... failed
error copying source tree . to C:/Users/Foo~1/AppData/Local/Temp/.tmpfEmxQg: copy source tree to lab directory

Caused by:
    0: writing file: C:\Users\Foo~1\AppData\Local\Temp\.tmpfEmxQg\.git\objects\07\4cf47c98083e4f871d3da4bc11050869ce2ec2: Zugriff verweigert (os error 5)
    1: Zugriff verweigert (os error 5)
Error: copy source tree to lab directory

Caused by:
    0: writing file: C:\Users\Foo~1\AppData\Local\Temp\.tmpfEmxQg\.git\objects\07\4cf47c98083e4f871d3da4bc11050869ce2ec2: Zugriff verweigert (os error 5)
    1: Zugriff verweigert (os error 5)

I tried it with different projects, but the result is always the same. Before committing everything is fine, after committing I get Access Denied (os error 5).

tobollam commented 2 years ago

After deleting the .git dir, cargo mutants can be executed successfully

$ rm -rf .git

$ cargo mutants
Freshen source tree ... ok in 0.107s
Copy source and build products to scratch directory ... 7 MB in 0.216s
Unmutated baseline ... ok in 1.752s
Auto-set test timeout to 20.0s
Found 2 mutations to test
sourcefrog commented 2 years ago

Interesting, thanks! We should probably skip .git and similar directories.

sourcefrog commented 2 years ago

I guess the root cause here is that the file is read-only, and that cp_r is trying to set the mtime, and on Windows that's probably disallowed on readonly files. (I'm surprised I didn't see this, as I have tested on Windows, but maybe it's something about the git shell.)

Anyhow,

sourcefrog commented 2 years ago

@tobollam, could you try https://github.com/sourcefrog/cargo-mutants/tree/exclude-git in the same environment and let me know if it helps?

tobollam commented 2 years ago

@sourcefrog That does solve the problem.

sourcefrog commented 2 years ago

Fixed in e507aefe8140049699635fbe0b1c09363fc51a56 and 8f302e35202ff9aca97faa9239f5dc6cb4283891. There will be a new release soon.