Skip to contents

testthat::expect_true() and testthat::expect_false() exist specifically for testing the TRUE/FALSE value of an object. testthat::expect_equal() and testthat::expect_identical() can also be used for such tests, but it is better to use the tailored function instead.

Usage

expect_true_false_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "expect_equal(x, TRUE)",
  linters = expect_true_false_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_true_false_linter] expect_true(x) is better than expect_equal(x, TRUE)

lint(
  text = "expect_equal(x, FALSE)",
  linters = expect_true_false_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_true_false_linter] expect_false(x) is better than expect_equal(x, FALSE)

# okay
lint(
  text = "expect_true(x)",
  linters = expect_true_false_linter()
)

lint(
  text = "expect_false(x)",
  linters = expect_true_false_linter()
)