Skip to content
Merged
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
@@ -1,5 +1,6 @@
# testthat (development version)

* `snapshot_accept(test)` now works when the test file name contains `.` (#1669).
* `local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
* `snapshot_review()` now passes `...` on to `shiny::runApp()` (#1928).
* `expect_named()` now gives more informative errors (#2091).
Expand Down
3 changes: 2 additions & 1 deletion R/snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ snapshot_meta <- function(files = NULL, path = "tests/testthat") {
files <- files[!is_dir]

dirs <- substr(dirs, 1, nchar(dirs) - 1)
files <- ifelse(tools::file_ext(files) == "", paste0(files, ".md"), files)
# Match regardless of whether user include .md or not
files <- c(files, paste0(files, ".md"))

out <- out[out$name %in% files | out$test %in% dirs, , drop = FALSE]
}
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ test_that("can accept files created by expect_snapshot()", {
expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md"))
})

test_that("can accept files created by dotted tests in name", {
# e.g. test-data.frame.R will create _snaps/data.frame.md

# without extension
path <- local_snapshot_dir(c("data.frame.md", "data.frame.new.md"))
suppressMessages(snapshot_accept("data.frame", path = path))
expect_equal(dir(file.path(path, "_snaps")), "data.frame.md")

# with extension
path <- local_snapshot_dir(c("data.frame.md", "data.frame.new.md"))
suppressMessages(snapshot_accept("data.frame.md", path = path))
expect_equal(dir(file.path(path, "_snaps")), "data.frame.md")
})

test_that("can accept files created by expect_snapshot_file()", {
path <- local_snapshot_dir(c("test/a.txt", "test/a.new.txt"))
suppressMessages(snapshot_accept("test/a.txt", path = path))
Expand Down
Loading