|
NAMETest::Snapshot - test against data stored in automatically-named fileSYNOPSISuse Test::Snapshot; my $got = function_generating_data(); is_deeply_snapshot $got, 'test description'; # 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 DESCRIPTIONNot connected with Test::Snapshots, which is based on a similar concept but for running executables.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 "snapshot testing", hence the module name. These snapshots will be stored in files whose names are automatically generated from:
If that file is not present, it will be treated as though it contains an "undef". FUNCTIONSis_deeply_snapshotExported by default. Takes two mandatory arguments:
Will return the truth value of whether the test passed this time - see below for automatic updating of "expected" data. ENVIRONMENTTo have this module automatically update its "expected" data, set environment variable "TEST_SNAPSHOT_UPDATE" to a true value. If the got and expected data do not match, a test failure will be reported, but the "expected" data will be updated anyway.This means it is safe to always have the variable set to a true value, so long as you are using source control (you are using source control, right?) and check your diffs before committing. FILE FORMATThe "expected" data will be stored in a format generated by "Dumper" in Data::Dumper, with these values set to true, to maximise readability (and to minimise diffs) of the stored data:
AUTHOREd J, "<etj at cpan.org>"LICENSECopyright (C) Ed JThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |