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

Renaming tests to follow best practices from Foundry Book #600

Merged
merged 11 commits into from
Sep 17, 2024

Conversation

milosdjurica
Copy link

@milosdjurica milosdjurica commented Sep 4, 2024

This PR puts the forge-std test naming conventions in line with the Best Practices from Foundry Book.

I am looking for a response if I should additionally rename tests as stated here in #599 . After I get the feedback, I will make changes to other test files too.

This PR closes #273 and #599 . Additionally, I could adapt it to fit suggestion on the book best practice test naming changes if this suggestion gets accepted.

test/StdChains.t.sol Outdated Show resolved Hide resolved
test/StdChains.t.sol Outdated Show resolved Hide resolved
@milosdjurica
Copy link
Author

As I mentioned earlier, I have suggested small changes to best practices.

Here is a table overview of methods from this file.
It shows how tests were named before I changed them, how they look now, and how they would look if new best practices are accepted.

Old names Current names New names
test_ChainRpcInitialization() test_ChainRpcInitialization() test_ChainRpcInitialization()
test_ChainNoDefault() test_RevertIf_ChainNotFound() test_GetChain_RevertIf_ChainNotFound()
test_SetChainFirstFails() test_RevertIf_SetChain_ChainIdExist_FirstTest() test_SetChain_RevertIf_ChainIdExist_FirstTest()
test_ChainBubbleUp() test_RevertIf_ChainBubbleUp() test_GetChain_RevertIf_ChainBubbleUp()
test_CannotSetChain_ChainIdExists() test_RevertIf_SetChain_ChainIdExists_SecondTest() test_SetChain_RevertIf_ChainIdExists_SecondTest()
test_SetChain() test_SetChain() test_SetChain_MultipleAssertions()
test_SetNoEmptyAlias() test_RevertIf_SetEmptyAlias() test_SetChain_RevertIf_SetEmptyAlias()
test_SetNoChainId0() test_RevertIf_SetNoChainId0() test_SetChain_RevertIf_ChainId0()
test_GetNoChainId0() test_RevertIf_GetNoChainId0() test_GetChain_RevertIf_ChainId0()
test_GetNoEmptyAlias() test_RevertIf_GetNoEmptyAlias() test_GetChain_RevertIf_EmptyAlias()
test_ChainIdNotFound() test_RevertIf_ChainIdNotFound() test_GetChain_RevertIf_ChainIdNotFound()
test_ChainAliasNotFound() test_RevertIf_ChainAliasNotFound() test_GetChain_RevertIf_ChainAliasNotFound()
test_SetChain_ExistingOne() test_SetChain_ExistingOne() test_SetChain_ChangesChainDataSuccessfully()
test_DontUseDefaultRpcUrl() test_RevertIf_DontUseDefaultRpcUrl() test_GetChain_RevertIf_DontUseDefaultRpcUrl()

I feel that the third approach is most clear and also makes it very easy to search for specific tests, e.g. forge test --mt test_GetChain would run all tests for GetChain method.

@milosdjurica milosdjurica changed the title Added _RevertIf_ in test/StdChains.t.sol Renaming tests to follow best practices from Foundry Book Sep 5, 2024
@milosdjurica milosdjurica requested a review from mds1 September 6, 2024 11:26
Copy link
Collaborator

@mds1 mds1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Per foundry-rs/book#1279 (comment) let's keep the current convention that you have now, this looks great

@mds1 mds1 merged commit beb836e into foundry-rs:master Sep 17, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

Rename the test functions to adhere to the Foundry best practices
2 participants