testthat with lintr::expect_lint_free() fails with devtools::check() but works with devtools::test()
Asked Answered
T

1

6

This test in my package works fine with devtools::test(). Also the online Travis build is going well.

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

However, with devtools::check() it fails. The error message is

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

I'm running R version 3.6.3 (2020-02-29), testthat 2.3.2 and lintr 2.0.1 on Windows.

I think the problem is that lintr doesn't know which file(s) to lintr.

Could somebody please point out to me what the solution to this problem is?

Trunnion answered 23/6, 2020 at 17:52 Comment(0)
R
0

This is known bug with lintr. Currently, the best workaround for it is replacing your code with:

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()
      )
    }
  })
}

The source for this solution is in that same link.

Ripley answered 2/2, 2022 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.