Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `load_all()` now errors if called recursively, i.e. if you accidentally include a `load_all()` call in one of your R source files (#2617).
* `release()` is deprecated in favour of `usethis::use_release_issue()`.
* `show_news()` now looks for NEWS files in the same locations as `utils::news()`: `inst/NEWS.Rd`, `NEWS.md`, `NEWS`, and `inst/NEWS` (@arcresu, #2499).
* `test_active_file()` now works when the active file is a snapshot file.

# devtools 2.4.6

Expand Down
3 changes: 3 additions & 0 deletions R/active.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ find_test_file <- function(path, call = parent.frame()) {

test_file_type <- function(path) {
dir <- path_file(path_dir(path))
parent_dir <- path_file(path_dir(path_dir(path)))
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name parent_dir is misleading. This variable contains the name of the parent directory (e.g., '_snaps'), not the parent directory path itself. Consider renaming it to parent_dir_name or grandparent_dir_name to clarify that it represents the directory name, not the path.

Copilot uses AI. Check for mistakes.
name <- path_file(path)
ext <- tolower(path_ext(path))

Expand All @@ -46,6 +47,8 @@ test_file_type <- function(path) {
type[dir == "R" & ext == "r"] <- "R"
type[dir == "testthat" & ext == "r" & grepl("^test", name)] <- "test"
type[dir == "src" & ext %in% src_ext] <- "src"
type[dir == "_snaps" & ext == "md"] <- "snap"
type[parent_dir == "_snaps" & ext == "md"] <- "snap"
type
}

Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-active.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ test_that("fails if can't find tests", {
})
})

test_that("find_test_file() works with snapshot files", {
dir <- local_package_create()
withr::local_dir(dir)
dir_create("tests/testthat/_snaps")
file_create("tests/testthat/test-foo.R")
file_create("tests/testthat/_snaps/foo.md")

path <- find_test_file("tests/testthat/_snaps/foo.md")
expect_equal(path_file(path), "test-foo.R")
})

test_that("find_test_file() works with snapshot variant files", {
dir <- local_package_create()

withr::local_dir(dir)
dir_create("tests/testthat/_snaps/variant")
file_create("tests/testthat/test-foo.R")
file_create("tests/testthat/_snaps/variant/foo.md")

path <- find_test_file("tests/testthat/_snaps/variant/foo.md")
expect_equal(path_file(path), "test-foo.R")
})

test_that("can determine file type", {
expect_equal(test_file_type("R/foo.R"), "R")
expect_equal(test_file_type("R/foo.c"), NA_character_)
Expand All @@ -23,5 +46,9 @@ test_that("can determine file type", {
expect_equal(test_file_type("tests/testthat/test-foo.c"), NA_character_)
expect_equal(test_file_type("tests/testthat/foo.R"), NA_character_)

expect_equal(test_file_type("tests/testthat/_snaps/foo.md"), "snap")
expect_equal(test_file_type("tests/testthat/_snaps/variant/foo.md"), "snap")
expect_equal(test_file_type("tests/testthat/_snaps/foo.R"), NA_character_)

expect_equal(test_file_type("DESCRIPTION"), NA_character_)
})
Loading