Debian Codegraph @

README.md

raw
1 # NAME
2
3 Test::Snapshot - test against data stored in automatically-named file
4
5 # PROJECT STATUS
6
7 | OS | Build status |
8 |:-------:|--------------:|
9 | Linux | [![Build Status](https://travis-ci.org/mohawk2/Test-Snapshot.svg?branch=master)](https://travis-ci.org/mohawk2/Test-Snapshot) |
10
11 [![CPAN version](https://badge.fury.io/pl/Test-Snapshot.svg)](https://metacpan.org/pod/Test::Snapshot)
12
13 # SYNOPSIS
14
15 use Test::Snapshot;
16 my $got = function_generating_data();
17 is_deeply_snapshot $got, 'test description'; # could also be in a subtest
18
19 # command line:
20 TEST_SNAPSHOT_UPDATE=1 prove -lr t
21 # or
22 TEST_SNAPSHOT_UPDATE=1 make test
23 # if your code means the expected data should change, then inspect with
24 git diff -w
25
26 # DESCRIPTION
27
28 Not connected with [Test::Snapshots](https://metacpan.org/pod/Test%3A%3ASnapshots), which is based on a similar
29 concept but for running executables.
30
31 As of 0.061, supports use under [Test2::V0](https://metacpan.org/pod/Test2%3A%3AV0).
32
33 Implements a function to automate the storing and updating of expected
34 test outputs. This is based on the idea known in frontend development
35 circles as "snapshot testing", hence the module name.
36
37 These snapshots will be stored in files whose names are automatically
38 generated from:
39
40 - the test filename (`$0`)
41 - any subtests' names surrounding and including this one
42 - the test description if any
43
44 If that file is not present, it will be treated as though it contains
45 an `undef`.
46
47 # FUNCTIONS
48
49 ## is\_deeply\_snapshot
50
51 Exported by default. Takes two mandatory arguments:
52
53 - The "got" data (mandatory), a scalar which might be a reference. It will
54 be passed to ["is\_deeply" in Test::More](https://metacpan.org/pod/Test%3A%3AMore#is_deeply) to be compared to the snapshotted
55 data.
56 - A text description of this test (mandatory). It will be used for reporting
57 results, but also to derive the filename in which the "expected" data
58 is stored.
59
60 Will return the truth value of whether the test passed this time -
61 see below for automatic updating of "expected" data.
62
63 # ENVIRONMENT
64
65 To have this module automatically update its "expected" data, set
66 environment variable `TEST_SNAPSHOT_UPDATE` to a true value. If the
67 got and expected data do not match, a test failure will be reported,
68 but the "expected" data will be updated anyway.
69
70 This means it is safe to always have the variable set to a true value,
71 so long as you are using source control (you _are_ using source control,
72 right?) and check your diffs before committing.
73
74 # FILE FORMAT
75
76 The "expected" data will be stored in a format generated by
77 ["Dumper" in Data::Dumper](https://metacpan.org/pod/Data%3A%3ADumper#Dumper), with these values set to true, to maximise
78 readability (and to minimise diffs) of the stored data:
79
80 - Sortkeys
81 - Indent
82 - Terse
83
84 # AUTHOR
85
86 Ed J, `<etj at cpan.org>`
87
88 # LICENSE
89
90 Copyright (C) Ed J
91
92 This library is free software; you can redistribute it and/or modify
93 it under the same terms as Perl itself.