| 1 |
use Test2::V0 -target => 'App::Yath::Command::init'; |
| 2 |
# HARNESS-DURATION-SHORT |
| 3 |
|
| 4 |
use ok $CLASS; |
| 5 |
|
| 6 |
use App::Yath::Tester qw/make_example_dir/; |
| 7 |
|
| 8 |
use Cwd qw/getcwd/; |
| 9 |
my $orig = getcwd(); |
| 10 |
|
| 11 |
subtest run => sub { |
| 12 |
my $dir = make_example_dir(); |
| 13 |
chdir($dir); |
| 14 |
|
| 15 |
unlink('test.pl') or die "Could not unlink test.pl" |
| 16 |
if -e 'test.pl'; |
| 17 |
|
| 18 |
my $stdout = ""; |
| 19 |
{ |
| 20 |
local *STDOUT; |
| 21 |
open(STDOUT, '>', \$stdout); |
| 22 |
is($CLASS->run(), 0, "Exit of 0"); |
| 23 |
ok(-e 'test.pl', "Added test.pl"); |
| 24 |
|
| 25 |
is($CLASS->run(), 0, "Exit of 0 if we are updating a generated one"); |
| 26 |
|
| 27 |
unlink('test.pl') or die "Could not unlink test.pl"; |
| 28 |
|
| 29 |
open(my $fh, '>', 'test.pl') or die "Could not open test.pl"; |
| 30 |
print $fh "xx\n"; |
| 31 |
close($fh); |
| 32 |
} |
| 33 |
|
| 34 |
is( |
| 35 |
$stdout, |
| 36 |
"\nWriting test.pl...\n\n\nWriting test.pl...\n\n", |
| 37 |
"Saw write info both times" |
| 38 |
); |
| 39 |
|
| 40 |
is( |
| 41 |
dies { $CLASS->run() }, |
| 42 |
"'test.pl' already exists, and does not appear to be a yath runner.\n", |
| 43 |
"Cannot override a non-generated test.pl" |
| 44 |
); |
| 45 |
}; |
| 46 |
|
| 47 |
done_testing; |
| 48 |
chdir($orig); |