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

fix: do not remove snapshots directory before running the test suite #9645

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Jan 8, 2025

Motivation

Ref: #9477 (comment)

Closes: #9477

Solution

Given the feedback we've received on the default behavior of removing the snapshots directory this PR proposes to remove the removal process all together.

This PR intends to be minimally breaking in terms of end user experience.

The effect is that we no longer automatically clean up for the user if they have made a change in the following:

  • A change in the test name
  • A change in the custom group name

These files will now be stained and in turn this means it is the responsibility of the user to clean this up.

forge clean will no longer remove the snapshots directory. It is up to the user to manually delete the snapshots directory if they intend on clearing it out entirely.

Reminder that users can configure the snapshots location to whatever folder they like.

Running a single test will still overwrite the individual snapshot file and only write its single entry in.

…side effect is that any custom group names or file name changes are not reflected - this is delegated to the end user
@zerosnacks
Copy link
Member Author

cc @sakulstra / @smartcontracts

@sakulstra
Copy link
Contributor

sakulstra commented Jan 8, 2025

Running a single test will still overwrite the individual snapshot file and only write its single entry in.

Do i correctly understand that this would "overwrite the whole file", or would it only overwrite/update the affected lines in the snapshot?
I think the latter would be more consistent in regards to staining.

@zerosnacks
Copy link
Member Author

zerosnacks commented Jan 8, 2025

Running a single test will still overwrite the individual snapshot file and only write its single entry in.

Do i correctly understand that this would "overwrite the whole file", or would it only overwrite/update the affected lines in the snapshot? I think the latter would be more consistent in regards to staining.

It would still overwrite the whole file.

I agree that it would be preferable for individual tests to be merged into existing snapshots (overwriting existing keys, leaving the rest intact). This PR does not change the behavior.

I'll tackle that in a follow-up PR as it requires a bit more consideration in terms of resource locking w/ multiple concurrent tests (as different test suites can write to the same file).

@zerosnacks zerosnacks added A-cheatcodes Area: cheatcodes T-feature Type: feature labels Jan 8, 2025
@grandizzy grandizzy added the C-forge Command: forge label Jan 9, 2025
@zerosnacks zerosnacks merged commit 82cf61d into master Jan 9, 2025
22 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/avoid-removing-of-snapshots-directory branch January 9, 2025 09:30
zerosnacks added a commit to foundry-rs/book that referenced this pull request Jan 30, 2025
zerosnacks added a commit to foundry-rs/book that referenced this pull request Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge T-feature Type: feature
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

bug: forge test deletes any existing snapshots directory by design
3 participants