1Test::Snapshot(3)     User Contributed Perl Documentation    Test::Snapshot(3)
2
3
4

NAME

6       Test::Snapshot - test against data stored in automatically-named file
7

SYNOPSIS

9         use Test::Snapshot;
10         my $got = function_generating_data();
11         is_deeply_snapshot $got, 'test description'; # could also be in a subtest
12
13         # command line:
14         TEST_SNAPSHOT_UPDATE=1 prove -lr t
15         # or
16         TEST_SNAPSHOT_UPDATE=1 make test
17         # if your code means the expected data should change, then inspect with
18         git diff -w
19

DESCRIPTION

21       Not connected with Test::Snapshots, which is based on a similar concept
22       but for running executables.
23
24       Implements a function to automate the storing and updating of expected
25       test outputs. This is based on the idea known in frontend development
26       circles as "snapshot testing", hence the module name.
27
28       These snapshots will be stored in files whose names are automatically
29       generated from:
30
31       the test filename ($0)
32       any subtests' names surrounding and including this one
33       the test description if any
34
35       If that file is not present, it will be treated as though it contains
36       an "undef".
37

FUNCTIONS

39   is_deeply_snapshot
40       Exported by default. Takes two mandatory arguments:
41
42       •   The "got" data (mandatory), a scalar which might be a reference. It
43           will be passed to "is_deeply" in Test::More to be compared to the
44           snapshotted data.
45
46       •   A text description of this test (mandatory). It will be used for
47           reporting results, but also to derive the filename in which the
48           "expected" data is stored.
49
50       Will return the truth value of whether the test passed this time - see
51       below for automatic updating of "expected" data.
52

ENVIRONMENT

54       To have this module automatically update its "expected" data, set
55       environment variable "TEST_SNAPSHOT_UPDATE" to a true value. If the got
56       and expected data do not match, a test failure will be reported, but
57       the "expected" data will be updated anyway.
58
59       This means it is safe to always have the variable set to a true value,
60       so long as you are using source control (you are using source control,
61       right?) and check your diffs before committing.
62

FILE FORMAT

64       The "expected" data will be stored in a format generated by "Dumper" in
65       Data::Dumper, with these values set to true, to maximise readability
66       (and to minimise diffs) of the stored data:
67
68       Sortkeys
69       Indent
70       Terse
71

AUTHOR

73       Ed J, "<etj at cpan.org>"
74

LICENSE

76       Copyright (C) Ed J
77
78       This library is free software; you can redistribute it and/or modify it
79       under the same terms as Perl itself.
80
81
82
83perl v5.34.0                      2022-01-21                 Test::Snapshot(3)
Impressum