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

tweak compute_name() to recognize snapshot files #1990

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# usethis (development version)

* `use_test()` and `use_r()` now work when you are in `tests/testthat/_snaps/{foo}.md` (@olivroy, #1988).

* The URLs baked into the badge generated by `use_coverage(type = "codecov")`
no longer specify a branch (#2008).

Expand Down
2 changes: 1 addition & 1 deletion R/r.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ compute_active_name <- function(path, ext, error_call = caller_env()) {
path <- proj_path_prep(path_expand_r(path))

dir <- path_dir(proj_rel_path(path))
if (!dir %in% c("R", "src", "tests/testthat")) {
if (!dir %in% c("R", "src", "tests/testthat", "tests/testthat/_snaps")) {
cli::cli_abort("Open file must be a code or test file.", call = error_call)
olivroy marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-r.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ test_that("compute_active_name() standardises name", {
"bar.R"
)

expect_equal(
compute_active_name(path(dir, "tests/testthat/_snaps/bar.md"), "R"),
"bar.R"
)
# https://github.com/r-lib/usethis/issues/1690
expect_equal(
compute_active_name(path(dir, "R/data.frame.R"), "R"),
Expand Down
Loading