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

Avoid library() in test files #741

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MichaelChirico
Copy link
Contributor

This makes tests less hermetic by creating permanent side effects that survive the test file.

Also remove deprecated expect_is() in anticipation of upgrading to {testthat} 3rd edition.

@flying-sheep flying-sheep added this pull request to the merge queue Nov 13, 2023
@flying-sheep
Copy link
Member

Thanks!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 13, 2023
tests/testthat/test_utils.r Outdated Show resolved Hide resolved
expect_is(skipped_stack[[1]], 'call')
# See discussion in #741 about using inherits() here and not
# expect_type(., "language") or expect_true(is.call(.)) or expect_mode(., "call")
expect_true(inherits(skipped_stack[[1]], 'call'))
Copy link

Choose a reason for hiding this comment

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

I think you could make this test more clear by making it more explicit:

expect_equal(skipped_stack[[1]], quote(f(1)))

Or even:

expect_equal(skipped_stack, list(quote(f(1)), quote(stop(x))))

That illustrates a subtle problem somewhere in the stack because if you print skipped_stack you see:

[[1]]
f(1)

[[2]]
function(x) stop(x)

Because the srcref is out of sync with the actual contents of the element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants