Skip to content

New expect_identical_linter - #958

Merged
MichaelChirico merged 9 commits into
masterfrom
expect_identical
Mar 21, 2022
Merged

MichaelChirico merged 9 commits into
masterfrom
expect_identical

Conversation

@MichaelChirico

Copy link
Copy Markdown
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.

Comment thread R/expect_identical_linter.R Resolved
Comment thread R/expect_identical_linter.R Resolved
Comment thread R/expect_identical_linter.R Outdated
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
Copy Markdown
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
Copy Markdown
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

@MichaelChirico MichaelChirico mentioned this pull request Mar 20, 2022
38 tasks done
Comment thread R/expect_identical_linter.R 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