Skip to content

Adding wrap Parameter to test_dir, test_check, and run_tests #586

Description

@brodieG

@krlmlr, Since 37cc0d0 it is no longer possible to run code with test_dir that involves withCallingHandlers error handling. This is because the default source action now sets wrap=TRUE, which causes all sourced code to be run within test_code.

Since wrap is not exposed in test_dir there is no way to disable this behavior when using test_dir (or test_check).

A simple example of the problem (here we just use test_file since test_file has the argument so we can show both cases):

f <- tempfile()
cat(
  "
  withCallingHandlers(
    stop('This should be handled'),
    error=function(e) cat('handled\n')
  )
  test_that('truth', {expect_true(TRUE)})
  ",
  file=f
)
test_file(f)              # fails
test_file(f, wrap=FALSE)  # works

For reference, more details on the running withCallingHandlers inside try block issue.

I'm happy to submit a PR that addresses this if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementwipwork in progress

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions