| 1 |
use Test::More 0.96; |
| 2 |
use Test::Snapshot; |
| 3 |
use File::Temp qw/ tempfile tempdir /; |
| 4 |
use Capture::Tiny qw(capture); |
| 5 |
use App::Prove; |
| 6 |
|
| 7 |
sub tempcopy { |
| 8 |
my ($text, $dir) = @_; |
| 9 |
my ($tfh, $filename) = tempfile( DIR => $dir ); |
| 10 |
print $tfh $text; |
| 11 |
close $tfh; |
| 12 |
$filename; |
| 13 |
} |
| 14 |
|
| 15 |
$ENV{TEST_SNAPSHOT_UPDATE} = 0; # override to ensure known value |
| 16 |
|
| 17 |
my $dir = tempdir( CLEANUP => 1 ); |
| 18 |
my $filename = tempcopy(<<'EOF', $dir); |
| 19 |
use Test::More 0.96; |
| 20 |
use Test::Snapshot; |
| 21 |
|
| 22 |
is_deeply_snapshot undef, 'desc'; |
| 23 |
|
| 24 |
done_testing; |
| 25 |
EOF |
| 26 |
|
| 27 |
sub do_test { |
| 28 |
my ($filename, $update, $expect, $description) = @_; |
| 29 |
my ($out, $err, $exit) = capture { |
| 30 |
local $ENV{TEST_SNAPSHOT_UPDATE} = $update; |
| 31 |
my $app = App::Prove->new; |
| 32 |
$app->process_args(qw(-b), $filename); |
| 33 |
$app->run ? 0 : 1; |
| 34 |
}; |
| 35 |
is $exit, $expect, $description |
| 36 |
or diag 'Output was: ', $out, 'Error was: ', $err; |
| 37 |
} |
| 38 |
|
| 39 |
do_test($filename, '', 0, 'no snapshot = undef'); |
| 40 |
|
| 41 |
done_testing; |