Skip to content

expanding tests for snapshot-manage.R #2106

@mcol

Description

@mcol

Following the discussion with @hadley started in #2029, I'm generating new tests in snapshot-manage.R. Specifically, there are no tests in which the snapshot files have different extensions. So before continuing with #2029, I'd like to add tests to the main branch against which I can continue developing that PR.

This test passes as I had expected (by the way the use of expect_message is just for ease of exposition here, the real tests use expect_snapshot):

path <- local_snapshot_dir(c("a.md", "a.new.md", "b.txt", "b.new.txt"))
expect_message(snapshot_accept("a", path = path), "Updating snapshots:")
expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.new.txt", "b.txt"))

I'm trying to understand what should the behaviour be in this case, as my expectations below is not satisfied:

path <- local_snapshot_dir(c("a.md", "a.new.md", "b.txt", "b.new.txt"))
expect_message(snapshot_accept("b", path = path), "Updating snapshots:")
## Error: `snapshot_accept("b", path = path)` did not throw the expected message.

expect_equal(dir(file.path(path, "_snaps")), c("a.md", "a.new.md", "b.txt"))
## Error: dir(file.path(path, "_snaps")) (`actual`) not equal to c("a.md", "a.new.md", "b.txt") (`expected`).
## `actual`:   "a.md" "a.new.md" "b.new.txt" "b.txt"
## `expected`: "a.md" "a.new.md"             "b.txt"

This behaviour is due to this line, which hardcodes the .md extension:

snap_test <- ifelse(snap_file, basename(dirname(cur)), gsub("\\.md$", "", basename(cur)))

So is the existing code at fault (and no user has ever noticed)? Or effectively only snapshots with .md extension can be accepted and updated? Can someone advise?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions