Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/testthat/test_utils.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
context('utils')

library(evaluate)

test_that('skip_repeated works', {
stack <- c('foo()', 'f()', 'f()', 'f()', 'f()', 'bar()')
expect_equal(skip_repeated(stack), c('foo()', 'f()', ellip_h, 'f()', 'bar()'))
Expand All @@ -13,10 +11,12 @@ test_that('skip_repeated does not skip three or less consecutive items', {
})

test_that('skip_repeated works on tracebacks', {
err <- try_capture_stack(quote({
err <- evaluate::try_capture_stack(quote({
f <- function(x) stop(x)
f(1)
}), new.env())
skipped_stack <- skip_repeated(err$calls)
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
Copy Markdown

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.

})