首页 > 解决方案 > lintr 测试通过 devtools::check() 并通过 devtools::test() 失败

问题描述

我正在编写一个带有以下 lint 测试的 R 包:

context("Require no code style errors")
library(lintr)

test_that("Package has no lintr errors", {
    lintr::expect_lint_free()
})

测试通过 `devtools::check():

$ Rscript -e "devtools::check()"
...
─  checking tests ...
✔  Running ‘testthat.R’ [61s/65s]
...
0 errors ✔ | 0 warnings ✔ | 0 notes ✔

并且无绒测试失败devtools::test()

$ Rscript -e "devtools::test()"
...
Testing PosteriorBootstrap
...
✖ |  0 1     | Require no code style errors [6.2 s]
────────────────────────────────────────────────────────────────────────────────
test_lintr.R:5: failure: Package has no lintr errors
Not lint free
tests/testthat/test_anpl.R:112:1: style: Trailing whitespace is superfluous.

^~
...
OK:       20
Failed:   1
Warnings: 0
Skipped:  0

问题是 Github 和 Travis 被设置为拒绝测试失败的拉取请求,如果我在devtools::test()之后运行devtools::check(),所有其他测试都会运行两次。

我怎样才能devtools::check()运行lintr测试?

标签: rtestinglintr

解决方案


这个问题是一个已知问题

这不是 devtools 中的错误(但可能在 lintr 中)。devtools::check()在临时目录中运行检查,但lint_package()假定它正在包目录中运行,因此没有要检查的源文件。...您可以使用 来确认这一点devtools::check(check_dir = "."),如果确实如此,这应该会产生 linting 失败devtools::test()

2015 年 5 月提出的解决方案不再有效。该问题现已锁定并关闭,因此不太可能得到解决。

我建议运行检查并将测试范围缩小到lintr

Rscript -e "devtools::check();devtools::test_file(file = 'testthat/test_lintr.R')"

推荐阅读