【问题标题】:testthat with lintr::expect_lint_free() fails with devtools::check() but works with devtools::test()使用 lintr::expect_lint_free() 进行测试失败并使用 devtools::check() 但可以使用 devtools::test()
【发布时间】:2020-10-13 21:00:55
【问题描述】:

我的包中的这个测试适用于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)

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

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

谁能告诉我这个问题的解决方案是什么?

【问题讨论】:

    标签: r testthat lintr


    【解决方案1】:

    这是known bug 与 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()
          )
        }
      })
    }
    

    这个解决方案的来源是same link

    【讨论】:

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