| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use FindBin '$Bin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Cwd 'getcwd'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use File::Copy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use File::Temp 'tempdir'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use App::LinkSite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # Test that we can pass a custom file parameter | ||||||||||
| 11 | 1 | my $fixture = "$Bin/links.json"; | |||||||||
| 12 | 1 | my $linksite = App::LinkSite->new(file => $fixture); | |||||||||
| 13 | 1 | isa_ok($linksite, 'App::LinkSite', 'Created an App::LinkSite object with file parameter'); | |||||||||
| 14 | |||||||||||
| 15 | # Test that the file parameter is correctly stored | ||||||||||
| 16 | 1 | is($linksite->file, $fixture, 'file parameter is correctly set'); | |||||||||
| 17 | |||||||||||
| 18 | # Test default file parameter | ||||||||||
| 19 | 1 | my $original_dir = getcwd; | |||||||||
| 20 | 1 | my $content_dir = tempdir(CLEANUP => 1); | |||||||||
| 21 | 1 | ▶ | copy $fixture, "$content_dir/links.json" or die "Cannot copy fixture: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 1 | my $completed = eval { | |||||||||
| 24 | 1 | ▶ | chdir $content_dir or die "Cannot enter $content_dir: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 1 | my $linksite_default = App::LinkSite->new(); | |||||||||
| 26 | 1 | is($linksite_default->file, 'links.json', 'default file parameter is "links.json"'); | |||||||||
| 27 | 1 | 1; | |||||||||
| 28 | }; | ||||||||||
| 29 | 1 | my $error = $@; | |||||||||
| 30 | 1 | ▶ | chdir $original_dir or die "Cannot restore $original_dir: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | ▶ | die $error unless $completed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | is(getcwd, $original_dir, 'working directory is restored after the default-file test'); | |||||||||
| 33 | |||||||||||
| 34 | 1 | done_testing; | |||||||||