Skip to content

Avoid library() in test files#741

Open
MichaelChirico wants to merge 2 commits intoIRkernel:masterfrom
MichaelChirico:patch-1
Open

Avoid library() in test files#741
MichaelChirico wants to merge 2 commits intoIRkernel:masterfrom
MichaelChirico:patch-1

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
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.

3 participants