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

Wrong snapshot_accept() suggestion if period in test file name #1669

Open
moodymudskipper opened this issue Aug 16, 2022 · 2 comments · May be fixed by #2029
Open

Wrong snapshot_accept() suggestion if period in test file name #1669

moodymudskipper opened this issue Aug 16, 2022 · 2 comments · May be fixed by #2029
Labels
feature a feature request or enhancement snapshot 📷

Comments

@moodymudskipper
Copy link

I have a test file called "test-data.frame.R" (notice there are 2 periods in full name)

When running tests with a new output I get the suggestion to run snapshot_accept("data.frame")

When I run it however I get "No snapshots to update"

This is due to testthat:::snapshot_meta where we find :

files <- ifelse(tools::file_ext(files) == "", paste0(files, ".md"))

There "frame" is returned by tools::file_ext() so no suffix is added.

A solution might be to have :

files <- ifelse(tools::file_ext(files) != "md", paste0(files, ".md")

Another solution would be to manage to have the suggestion be snapshot_accept("data.frame.md")

@hadley hadley added feature a feature request or enhancement snapshot 📷 labels Sep 19, 2022
@d-morrison
Copy link

I ran into the same issue; here's a reprex: https://github.com/d-morrison/testthat.suffix.issue

@d-morrison
Copy link

snapshot_accept() (with no arguments) is a possible workaround (but it accepts changes for all snapshots).

mcol added a commit to mcol/testthat that referenced this issue Nov 17, 2024
This changes slightly the logic for matching file names:

- before if a file name was considered to be without extension, we would
add the `.md` and then compare it with the actual file names in the
`_snaps` directory. However, that would fail if the file contained dots,
as they would be considered to be a file extension: for them no `.md` was
added to their name, and therefore they would never match with the actual
files in the `_snaps` directory, so no update could ever succeed

- with this patch, we strip any `.md` or `.txt` extension from the file
names received by `snapshot_manage()`, and compare those with the actual
file names from the `_snaps` directory also without extension
mcol added a commit to mcol/testthat that referenced this issue Dec 21, 2024
This changes slightly the logic for matching file names:

- before if a file name was considered to be without extension, we would
add the `.md` and then compare it with the actual file names in the
`_snaps` directory. However, that would fail if the file contained dots,
as they would be considered to be a file extension: for them no `.md` was
added to their name, and therefore they would never match with the actual
files in the `_snaps` directory, so no update could ever succeed

- with this patch, we strip any `.md` or `.txt` extension from the file
names received by `snapshot_manage()`, and compare those with the actual
file names from the `_snaps` directory also without extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement snapshot 📷
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants