【问题标题】:lintr test passes with devtools::check() and fails with devtools::test()lintr 测试通过 devtools::check() 并通过 devtools::test() 失败
【发布时间】:2019-05-22 10:08:40
【问题描述】:

我是 writing an R package,接受以下 lint 测试:

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::check() 之后运行 devtools::test(),所有其他测试都会运行两次。

如何让devtools::check() 运行lintr 测试?

【问题讨论】:

    标签: r testing lintr


    【解决方案1】:

    这个问题是known issue:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-10-13
      • 2020-02-18
      • 2021-12-23
      • 2017-06-10
      • 2018-03-02
      • 2016-01-22
      • 2020-11-05
      • 2017-04-05
      • 2020-02-29
      相关资源
      最近更新 更多