-
Notifications
You must be signed in to change notification settings - Fork 152
Preserve cached mutation results on rerun of unchanged source #471
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
Open
percy-raskova
wants to merge
2
commits into
boxed:main
Choose a base branch
from
percy-raskova:fix/preserve-cached-mutation-results
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import shutil | ||
| from pathlib import Path | ||
|
|
||
| from tests.e2e.e2e_utils import change_cwd, read_all_stats_for_project, write_json_file, read_json_file | ||
|
|
||
| import mutmut | ||
| from mutmut.__main__ import _run | ||
|
|
||
|
|
||
| def test_rerun_preserves_cached_results(): | ||
| """Rerunning mutmut on unchanged source must not reset cached exit codes to None. | ||
|
|
||
| Strategy: run mutmut once, then inject a sentinel exit code (99) into the | ||
| meta file. If the second run preserves the cache, the sentinel survives. | ||
| If it resets and re-tests, 99 gets replaced with a real exit code. | ||
| """ | ||
| project_path = Path("..").parent / "e2e_projects" / "my_lib" | ||
| mutants_path = project_path / "mutants" | ||
| shutil.rmtree(mutants_path, ignore_errors=True) | ||
|
|
||
| # First run: generate and test all mutants | ||
| mutmut._reset_globals() | ||
| with change_cwd(project_path): | ||
| _run([], None) | ||
|
|
||
| # Inject sentinel exit code (99) into every mutant result | ||
| meta_files = list(mutants_path.rglob("*.meta")) | ||
| assert meta_files, "Expected .meta files after first run" | ||
|
|
||
| sentinel = 99 | ||
| for meta_file in meta_files: | ||
| meta = read_json_file(meta_file) | ||
| for key in meta["exit_code_by_key"]: | ||
| meta["exit_code_by_key"][key] = sentinel | ||
| write_json_file(meta_file, meta) | ||
|
|
||
| # Second run: source unchanged, sentinel values should survive | ||
| mutmut._reset_globals() | ||
| with change_cwd(project_path): | ||
| _run([], None) | ||
|
|
||
| second_run_stats = read_all_stats_for_project(project_path) | ||
|
|
||
| # Every result should still be the sentinel — not None, not a real exit code | ||
| for meta_path, results in second_run_stats.items(): | ||
| for mutant_name, exit_code in results.items(): | ||
| assert exit_code == sentinel, ( | ||
| f"Cached result for {mutant_name} in {meta_path} was not preserved. " | ||
| f"Expected sentinel {sentinel}, got {exit_code}." | ||
| ) | ||
|
|
||
| # Cleanup | ||
| shutil.rmtree(mutants_path, ignore_errors=True) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.