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_setequal_linter #951

Closed
wants to merge 5 commits into from
Closed

New expect_setequal_linter #951

wants to merge 5 commits into from

Conversation

MichaelChirico
Copy link
Collaborator

Part of #884

@@ -94,6 +94,7 @@ function calls. (#850, #851, @renkun-ken)
+ `expect_true_false_linter()` Require usage of `expect_true(x)` over `expect_equal(x, TRUE)` and similar
+ `expect_named_linter()` Require usage of `expect_named(x, n)` over `expect_equal(names(x), n)` and similar
* `expect_length_linter()` Require usage of `expect_length(x, n)` over `expect_equal(length(x), n)` and similar
* `expect_setequal_lintr()` Require usage of `expect_setequal(x, y)` over `expect_equal(sort(x), sort(y))` and similar
Copy link
Collaborator

Choose a reason for hiding this comment

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

sort(unique(x))and sort(unique(y)), no?


xpath <- glue::glue("//expr[
expr[SYMBOL_FUNCTION_CALL[text() = 'expect_identical' or text() = 'expect_equal']]
and expr[expr[SYMBOL_FUNCTION_CALL[text() = 'sort']]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

sort() doesn't deduplicate, so we can only ascertain the lint for sort(unique()) or unique(sort()).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our sense is that people are using expect_equal(sort()) in cases without dups, hence pointing out in the lint message that dup tests are different. Even with dups, expect_equal(sort(x), sort(y)) smells fishy to me -- a bit hard to imagine when such a test would not be better written in another way.

This linter only caught a handful of cases in practice as is. Maybe we should just exclude this one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine for me.
I can imagine expect_equal(sort(..), ...) to be useful when testing some join like functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense... I wonder if expect_setequal() is maybe itself undesirable -- a better test should probably specify exactly how the sets are equal, right? Maybe expect_setequal() should be replaced with expect_identical(sort(unique(x)), y) 🤔

Anyway, closing for now.

@MichaelChirico MichaelChirico deleted the expect_setequal branch March 20, 2022 05:02
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