Skip to content

Recommendations for snapshotting dynamic output? #1484

@MichaelChirico

Description

@MichaelChirico

I'm trying (Issue: MichaelChirico/potools#256 & WIP PR: MichaelChirico/potools#257) to migrate some tests to use expect_snapshot() and it's made the test script way cleaner so I'm quite keen to do so, however I've come across the following issues:

  • The test is run in withr::local_tempdir(), and the function prints a full path
  • The function reads & displays file.mtime() for some files. This is more static if the file is read from the package repo, but as part of setup/teardown, I copy the file to local_tempdir(), meaning the file update time is new every run as well

Is such a situation out of scope for expect_snapshot()? Would you recommend I refactor the code to be able to isolate these dynamic parts, or is there any way to turn this into a feature request?

PS I also noticed it seems expect_snapshot() doesn't catch all of the output from system(), meaning I have a messier terminal:

══ Testing test-translate-package.R ════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 12 ]5 translated messages.
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 15 ]5 translated messages.
5 translated messages.
5 translated messages.
[ FAIL 2 | WARN 0 | SKIP 0 | PASS 20 ]5 translated messages.
...... done.
5 translated messages.
[ FAIL 3 | WARN 0 | SKIP 0 | PASS 20 ]3 translated messages.
..... done.
3 translated messages.
[ FAIL 4 | WARN 0 | SKIP 0 | PASS 31 ]1 translated message.
2 translated messages.
.. done.
..... done.
1 translated message.
2 translated messages.
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 31 ]Generating en@quot translations
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 47 ]Generating en@quot translations
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 54 ]Generating en@quot translations
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 59 ]

Is there anything to do there besides refactor to try & use system2 internally?

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions