Skip to content

Display Snapshot file diff for plain text comparisons #1593

@schloerke

Description

@schloerke

For files that are have a text comparison function, I believe the text difference should be displayed in the testthat output, similar to the typical snapshot difference output.

A proof of concept has been implemented in rstudio/shinytest2#149


Motivating snapshot output:

Failure (test-test-files.R:20:3): runs all tests and records output
Snapshot of `print(df)` has changed:
old[3:9] vs new[3:9]
  "2     test-basic.R                   logical tests ignore attributes  2      0   FALSE FALSE       0      2"
  "3     test-basic.R                                    equality holds  2      0   FALSE FALSE       0      2"
  "4     test-basic.R         can't access variables from other tests 2  1      0    TRUE FALSE       0      0"
- "5     test-basic.R         can't access variables from other tests 1  1      0   FALSE FALSE       0      1"
+ "5     test-basic.R         can't access variables from other tests 1  1      1   FALSE FALSE       0      0"
  "6     test-empty.R                                        empty test  1      0    TRUE FALSE       0      0"
  "7     test-empty.R                             empty test with error  0      0   FALSE  TRUE       0      0"
  "8    test-errors.R                                            simple  0      0   FALSE  TRUE       0      0"

* Run `snapshot_accept('test-files')` to accept the change
* Run `snapshot_review('test-files')` to interactively review the change

Current snapshot file output:

Failure (test-snapshot-file.R:50:3): expect_snapshot_file works with variant
Snapshot of `write_tmp_lines(r_version())` to 'snapshot-file/nickname.txt' has changed
Run `testthat::snapshot_review('snapshot-file/')` to review changes

Desired snapshot file output for any snapshot comparison tested with testthat::compare_file_text():

Failure (test-snapshot-file.R:50:3): expect_snapshot_file works with variant
Snapshot of `write_tmp_lines(r_version())` to 'snapshot-file/nickname.txt' has changed
< old              > new
@@ 1 @@            @@ 1 @@
< Shake and Throw  > R4.0

* Run `testthat::snapshot_review('snapshot-file/')` to review changes

The richly colored diff would be displayed using diffobj::diffFile(old, new)


Is this something that would be useful in {testthat}? I'd be happy to make a PR (and drop support for it in {shinytest2})

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions