测试中的负面条件

Negative conditions in testthat

是否可以在 test_that() 或 expect_XXX() 调用中写入否定条件?具体来说,我想测试一个不包含子字符串的字符串,例如:

expect_that("Apples, Oranges, Banana", !matches('Onion'))

expect_not_match("Apples, Oranges, Banana", 'Onion')

我知道我可以将 expect_true() 与例如grep:

expect_true(length(grep("Onion", "Apples, Oranges, Banana")) == 0)

但这似乎不太可读。

testthat::not怎么样?

expect_that("Apples, Oranges, Banana", not(matches('Onion')))​​​​​​