testthat icon indicating copy to clipboard operation
testthat copied to clipboard

Silently ignoring syntax error in test file?

Open krlmlr opened this issue 4 years ago • 5 comments

To replicate, run the "numbers" tests in https://github.com/r-lib/pillar/commit/3611c62369a51541137e7d1c584cd3386b40f64b via testthat::test_local(filter = "numbers"). Can't (easily) create a reprex here.

The syntax error is tibble::tibble::tibble, which is rejected by the parser in a clean session.

krlmlr avatar Mar 24 '21 06:03 krlmlr

It is a bug in parallel testthat.

❯ Sys.setenv(TESTTHAT_PARALLEL = "FALSE")
❯ testthat::test_local(filter = "numbers")
✔ |  OK F W S | Context
⠏ |   0       | numbers                                                         
Error in parse(con, n = -1, srcfile = srcfile, encoding = "UTF-8") :
  test-numbers.R:17:19: unexpected '::'
16:     # FIXME: Use fixed digits
17:     tibble::tibble::

gaborcsardi avatar Mar 24 '21 07:03 gaborcsardi

I have a bug where a syntax error in a file causes testthat parallel to hang forever. The issue was a missing parenthesis, and there was no notification in the main process.

Is that the same as this?

billdenney avatar Jan 19 '22 14:01 billdenney

@billdenney Possibly.

gaborcsardi avatar Mar 14 '22 11:03 gaborcsardi

@gaborcsardi , I just tried to make a reprex, and I got this behavior. So, I think that either my issue was the same or it's fixed.

billdenney avatar Mar 15 '22 00:03 billdenney

I have just been bitten by this. It seems that testthat::test_local() ignores all files with syntax errors when running in parallel. To reproduce, run the following in an empty directory:

usethis::create_package(".")
usethis::use_testthat(parallel = TRUE)
usethis::use_test("syntax")

# Whatever to create a syntax error
write("@", "tests/testthat/test-syntax.R", append = TRUE)

# Suceeds
testthat::test_local()

Tested with testthat 3.2.1.

kamilzyla avatar Feb 12 '24 15:02 kamilzyla