|
5 | 5 | #' modified snapshot. This is particularly useful for whole file snapshots |
6 | 6 | #' created by `expect_snapshot_file()`. |
7 | 7 | #' |
8 | | -#' @param files Optionally, filter affects to snapshots from specified test |
9 | | -#' files. Can be full path to test (`tests/testthat/test-foo.R`), file name |
10 | | -#' (`test-foo.R`), or test name (`foo`). |
| 8 | +#' @param files Optionally, filter effects to snapshots from specified files. |
| 9 | +#' This can be a snapshot name (e.g. `foo` or `foo.md`), a snapshot file name |
| 10 | +#' (e.g. `testfile/foo.txt`), or a snapshot file directory (e.g. `testfile/`). |
| 11 | +#' |
11 | 12 | #' @param path Path to tests. |
12 | 13 | #' @export |
13 | 14 | snapshot_accept <- function(files = NULL, path = "tests/testthat") { |
@@ -156,7 +157,14 @@ snapshot_meta <- function(files = NULL, path = "tests/testthat") { |
156 | 157 | rownames(out) <- NULL |
157 | 158 |
|
158 | 159 | if (!is.null(files)) { |
159 | | - out <- out[out$name %in% paste0(files, ".md"), , drop = FALSE] |
| 160 | + is_dir <- substr(files, nchar(files), nchar(files)) == "/" |
| 161 | + dirs <- files[is_dir] |
| 162 | + files <- files[!is_dir] |
| 163 | + |
| 164 | + dirs <- substr(dirs, 1, nchar(dirs) - 1) |
| 165 | + files <- ifelse(tools::file_ext(files) == "", paste0(files, ".md"), files) |
| 166 | + |
| 167 | + out <- out[out$name %in% files | out$test %in% dirs, , drop = FALSE] |
160 | 168 | } |
161 | 169 |
|
162 | 170 | out |
|
0 commit comments