Skip to content

Run test file addin does not find test file on Windows #2355

@cderv

Description

@cderv

Here is the issue :

Running the addin "Run a test file" will run devtools:::test_active_file() in R Console in the RStudio IDE. But this error

> devtools:::test_active_file()
Error: No test files found
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
No test files found
Backtrace:
    x
 1. \-devtools:::test_active_file()
 2.   \-devtools:::find_test_file(file)

I think this is a Windows specific issue due to the recent switch to fs in #2331 mainly due to the fact the fs HOME dir on Windows is not the same as the R HOME dir. This means that every unexpanded path started with ~/ will not mean the same for R base function or for fs.

Here is what happens:

  • devtools:::test_active_file() => devtools:::find_active_file(): This results in a path starting with ~/. e.g "~/DEV_R/rmarkdown/tests/testthat/test-render.R"
  • Then devtools:::find_test_file() is run on this file and this will error there

    devtools/R/active.R

    Lines 8 to 25 in f5dc632

    find_test_file <- function(path) {
    type <- test_file_type(path)
    if (any(is.na(type))) {
    rlang::abort(c(
    "Don't know how to find tests associated with the active file:",
    path[is.na(type)]
    ))
    }
    is_test <- type == "test"
    path[!is_test] <- paste0("tests/testthat/test-", name_source(path[!is_test]), ".R")
    path <- unique(path[file_exists(path)])
    if (length(path) == 0) {
    rlang::abort("No test files found")
    }
    path
    }

fs::file_exists() is not the same as file.exists() on Windows. (source of change)

file.create(x <- "~/dummy")
#> [1] TRUE
file.exists(x)
#> [1] TRUE
fs::file_exists(x)
#> ~/dummy 
#>   FALSE
unlink(x)

Created on 2021-05-28 by the reprex package (v2.0.0)

I think the change to fs should take into account this HOME directory difference. It must have for the package internal function that are tested as the tests have passed on Windows. So it may be only an issue for this addin function.

As a workaround, I am changing R_FS_HOME for now so that the addin works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions