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

New expect_identical_linter #958

Merged
merged 9 commits into from
Mar 21, 2022
Merged

New expect_identical_linter #958

merged 9 commits into from
Mar 21, 2022

Conversation

MichaelChirico
Copy link
Collaborator

Part of #884

This one has become slightly controversial owing to Hadley's comments here: #910 (comment)

Meaning some divergence between how the testthat maintainers view expect_equal() vs. expect_identical() and how we do internally at Google, where we do want to keep encouraging expect_identical() as the default because we find stricter tests are a better default.

I think that means we want to be careful in wording/documentation not to imply that this linter is enacting the advice of testthat. Hope that makes sense; not sure if I achieved it in the current iteration.

R/expect_identical_linter.R Outdated Show resolved Hide resolved
R/expect_identical_linter.R Show resolved Hide resolved
Comment on lines 68 to 75
"expect_identical(x, y) is the default way of comparing two objects in",
"testthat unit tests. Only use expect_equal() if testing numeric",
"equality (and specifying tolerance= explicitly) or there's a need to",
"ignore some attributes, e.g. with ignore_attr = 'names' for the 3rd",
"edition or check.attributes = FALSE for the second. For testing",
"approximate equality to a whole number, you can also avoid setting",
"tolerance= by including an explicit decimal point, e.g.,",
"expect_equal(x, 1.0), not expect_equal(x, 1)."
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a rather long message compared to other linters.
Maybe shorten to "only use expect_equal() if non-default arguments, e.g. tolerance, are needed"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

put some of the details in the man page, should be more digestible now

tests/testthat/test-expect_identical_linter.R Outdated Show resolved Hide resolved
@MichaelChirico MichaelChirico merged commit dc734b7 into master Mar 21, 2022
@MichaelChirico MichaelChirico deleted the expect_identical branch March 21, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants