Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cderv opened this issue May 28, 2021 · 3 comments
Closed

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

cderv opened this issue May 28, 2021 · 3 comments

Comments

@cderv
Copy link

cderv commented May 28, 2021

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

@cderv
Copy link
Author

cderv commented May 28, 2021

Thanks @jimhester !

@jimhester
Copy link
Member

@cderv could you test this change and verify it fixes the problem for you? I believe it should.

@cderv
Copy link
Author

cderv commented May 28, 2021

Oh yeah I did not test because I believe it should fix it.

Now I tried and I confirm it is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants