GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::Snapshot(3) User Contributed Perl Documentation Test::Snapshot(3)

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

  use 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

Not 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:

the test filename ($0)
any subtests' names surrounding and including this one
the test description if any

If that file is not present, it will be treated as though it contains an "undef".

Exported by default. Takes two mandatory arguments:
  • The "got" data (mandatory), a scalar which might be a reference. It will be passed to "is_deeply" in Test::More to be compared to the snapshotted data.
  • A text description of this test (mandatory). It will be used for reporting results, but also to derive the filename in which the "expected" data is stored.

Will return the truth value of whether the test passed this time - see below for automatic updating of "expected" data.

To 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.

The "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:
Sortkeys
Indent
Terse

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

Copyright (C) Ed J

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2018-02-23 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.