Skip to content

Avoid implicit assignments in expectations #1879

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

Merged
merged 17 commits into from
Apr 4, 2023
Merged

Conversation

IndrajeetPatil
Copy link
Collaborator

Closes #1820

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2022

Codecov Report

Merging #1879 (bfae8af) into main (4f12a43) will not change coverage.
The diff coverage is n/a.

❗ Current head bfae8af differs from pull request most recent head 951b913. Consider uploading reports for the commit 951b913 to get more accurate results

@@           Coverage Diff           @@
##             main    #1879   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files         112      112           
  Lines        4857     4857           
=======================================
  Hits         4801     4801           
  Misses         56       56           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@IndrajeetPatil
Copy link
Collaborator Author

@AshesITR Before I continue with this, just wanted to double-check with you if this is what you had in mind for fixing #1820.

@IndrajeetPatil IndrajeetPatil marked this pull request as ready for review January 15, 2023 19:03
@IndrajeetPatil IndrajeetPatil changed the title WIP: Avoid implicit assignments in expectations Avoid implicit assignments in expectations Jan 15, 2023
@IndrajeetPatil IndrajeetPatil requested review from AshesITR and MichaelChirico and removed request for AshesITR January 15, 2023 19:03
@IndrajeetPatil
Copy link
Collaborator Author

I haven't touched the tests for deprecated functions, which also contains some implicit assignment lints.

TBH, I think we should nolint all test files for deprecated functions; we are going to remove them at some point anyway.

@IndrajeetPatil
Copy link
Collaborator Author

The new warning appearing in tests is unrelated to the current PR. I have created an issue to track this: #1905.

@IndrajeetPatil
Copy link
Collaborator Author

@AshesITR This is ready for a review, btw. Tagging just in case you missed the original review request during the holidays.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

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

Looks good. Just wondering if we should commit to the brace-syntax from magrittr or grab the result in an extra supressWarnings() for the xml_nodes_to_lints() tests.

The former would not be compatible with the native pipe once we drop support for R versions without it.

@IndrajeetPatil
Copy link
Collaborator Author

Looks good. Just wondering if we should commit to the brace-syntax from magrittr or grab the result in an extra supressWarnings() for the xml_nodes_to_lints() tests.

The former would not be compatible with the native pipe once we drop support for R versions without it.

Bumping the minimum needed R version to 4.1 should be many years away, so that's not too worrisome.

That said, the brace syntax is not too straightforward to reason about, and so maybe it's better to avoid it. Thus, I have removed the brace-syntax, and have instead used temp variables for the tests in question.

@IndrajeetPatil IndrajeetPatil requested a review from AshesITR March 21, 2023 19:28
@@ -92,10 +92,19 @@ test_that("load_cache returns an empty environment if reading cache file fails",
cache_f1 <- file.path(d1, fhash(f1))
writeLines(character(), cache_f1)

expect_warning(e2 <- lintr:::load_cache(file = f1, path = d1), "Could not load cache file")
expect_warning(
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found myself ready to suggest nesting the expectations instead & then remembered that's basically what we just undid by removing magrittr :)

Someday we'll depend on R>4.1 & then we can use |>....

In the meantime, there may be some cases where 2-nesting looks fine:

expect_warning(
  expect_identical(ls(lintr:::load_cache(file = f1, path = d1), character()),
  "Could not load cache file",
  fixed = TRUE
)

up to you whether / which cases you agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TBH, I personally prefer to keep each expectation separate. Nested expectations are much harder to reason about.

@IndrajeetPatil IndrajeetPatil merged commit c6099d5 into main Apr 4, 2023
@IndrajeetPatil IndrajeetPatil deleted the 1820_tests_assignments branch April 4, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid unnecessary implicit assignments in our own test suite
4 participants