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

Use {withr} more comprehensively in tests to manage state #1646

Merged
merged 5 commits into from
Oct 8, 2022

Conversation

MichaelChirico
Copy link
Collaborator

@MichaelChirico MichaelChirico commented Oct 8, 2022

I couldn't remove all on.exit() usages, here's what remains:

tests/testthat/test-error.R:29:  on.exit(lintr:::reset_lang(old_lang), add = TRUE)
tests/testthat/test-get_source_expressions.R:5:    on.exit(close(con))
tests/testthat/test-object_usage_linter.R:312:  on.exit(utils::globalVariables(old_globals, package = globalenv(), add = FALSE))
tests/testthat/test-settings.R:61:  on.exit(if (is.na(old)) Sys.unsetenv(test_env) else sym_set_env(test_env, old))

Of those

  • test-error.R: can't be removed unless we add a custom unexported local_lang()
  • test-get_source_expressions.R: see Support UTF-8 content in local_tempfile(lines = ) withr#210
  • test-object_usage_linter.R: I support we could use withr::defer(), but on.exit() seems fine here
  • test-settings.R: this may be replaced by withr::local_envvar(), but I was too lazy to play around with it & ensure it works

@MichaelChirico MichaelChirico added the internals Issues related to inner workings of lintr, i.e., not user-visible label Oct 8, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2022

Codecov Report

Merging #1646 (7b0330c) into main (51c63e0) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1646   +/-   ##
=======================================
  Coverage   98.29%   98.29%           
=======================================
  Files         100      100           
  Lines        4397     4397           
=======================================
  Hits         4322     4322           
  Misses         75       75           

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

@IndrajeetPatil IndrajeetPatil self-requested a review October 8, 2022 12:53
Copy link
Collaborator

@IndrajeetPatil IndrajeetPatil left a comment

Choose a reason for hiding this comment

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

Wow, that's a thorough clean-up. Thanks a lot, @MichaelChirico!

As for the remaining instances of on.exit(), we can revisit them later. 🧹

@IndrajeetPatil IndrajeetPatil merged commit 0af31f5 into main Oct 8, 2022
@IndrajeetPatil IndrajeetPatil deleted the on-exit branch October 8, 2022 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Issues related to inner workings of lintr, i.e., not user-visible testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants