使用lintr::expect_lint_free()的testthat在devtools::check()中失败,但在devtools::test()中正常工作

6

这个在我的程序包中的测试可以通过 devtools::test() 很好地运行。此外,线上的 Travis 构建也正常。

test_that("Package style", {
  lintr::expect_lint_free()
})

然而,使用devtools::check()却失败了。错误信息如下:

   invalid 'path' argument
     Backtrace:
      1. lintr::expect_lint_free()
      2. lintr::lint_package(...)
      3. base::normalizePath(path, mustWork = FALSE)
      4. base::path.expand(path)

我正在Windows上运行R版本3.6.3(2020-02-29),testthat 2.3.2和lintr 2.0.1。

我认为问题在于lintr不知道要lint哪个文件。

请问有人能告诉我解决这个问题的方法吗?

1个回答

0

这是与lintr相关的已知问题。目前,最好的解决方法是用以下代码替换您的代码:

if (requireNamespace("lintr", quietly = TRUE)) {
  library(lintr)

  context("linting package")
  test_that("Package Style", {

    # A duplicate copy of the find_package function from lintr
    find_package <- function(path) {
      path <- normalizePath(path, mustWork = FALSE)

      while (!file.exists(file.path(path, "DESCRIPTION"))) {
        path <- dirname(path)
        if (identical(path, dirname(path))) {
          return(NULL)
        }
      }

      path
    }

    if (!is.null(find_package("."))) {
      expect_lint_free()
      )
    }
  })
}

这个解决方案的源代码在同一个链接中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接