.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::Snapshot 3pm" .TH Test::Snapshot 3pm "2023-07-12" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::Snapshot \- test against data stored in automatically\-named file .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Test::Snapshot; \& my $got = function_generating_data(); \& is_deeply_snapshot $got, \*(Aqtest description\*(Aq; # could also be in a subtest \& \& # command line: \& TEST_SNAPSHOT_UPDATE=1 prove \-lr t \& # or \& TEST_SNAPSHOT_UPDATE=1 make test \& # if your code means the expected data should change, then inspect with \& git diff \-w .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Not connected with Test::Snapshots, which is based on a similar concept but for running executables. .PP Implements a function to automate the storing and updating of expected test outputs. This is based on the idea known in frontend development circles as \*(L"snapshot testing\*(R", hence the module name. .PP These snapshots will be stored in files whose names are automatically generated from: .ie n .IP "the test filename ($0)" 4 .el .IP "the test filename (\f(CW$0\fR)" 4 .IX Item "the test filename ($0)" .PD 0 .IP "any subtests' names surrounding and including this one" 4 .IX Item "any subtests' names surrounding and including this one" .IP "the test description if any" 4 .IX Item "the test description if any" .PD .PP If that file is not present, it will be treated as though it contains an \f(CW\*(C`undef\*(C'\fR. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "is_deeply_snapshot" .IX Subsection "is_deeply_snapshot" Exported by default. Takes two mandatory arguments: .IP "\(bu" 4 The \*(L"got\*(R" data (mandatory), a scalar which might be a reference. It will be passed to \*(L"is_deeply\*(R" in Test::More to be compared to the snapshotted data. .IP "\(bu" 4 A text description of this test (mandatory). It will be used for reporting results, but also to derive the filename in which the \*(L"expected\*(R" data is stored. .PP Will return the truth value of whether the test passed this time \- see below for automatic updating of \*(L"expected\*(R" data. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" To have this module automatically update its \*(L"expected\*(R" data, set environment variable \f(CW\*(C`TEST_SNAPSHOT_UPDATE\*(C'\fR to a true value. If the got and expected data do not match, a test failure will be reported, but the \*(L"expected\*(R" data will be updated anyway. .PP This means it is safe to always have the variable set to a true value, so long as you are using source control (you \fIare\fR using source control, right?) and check your diffs before committing. .SH "FILE FORMAT" .IX Header "FILE FORMAT" The \*(L"expected\*(R" data will be stored in a format generated by \&\*(L"Dumper\*(R" in Data::Dumper, with these values set to true, to maximise readability (and to minimise diffs) of the stored data: .IP "Sortkeys" 4 .IX Item "Sortkeys" .PD 0 .IP "Indent" 4 .IX Item "Indent" .IP "Terse" 4 .IX Item "Terse" .PD .SH "AUTHOR" .IX Header "AUTHOR" Ed J, \f(CW\*(C`\*(C'\fR .SH "LICENSE" .IX Header "LICENSE" Copyright (C) Ed J .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.