File: 07_util_withdist.t

package info (click to toggle)
libtest-file-sharedir-perl 1.001002-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 496 kB
  • ctags: 58
  • sloc: perl: 603; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

use strict;
use warnings;

use Test::More 0.96;
use Test::Fatal;
use FindBin;

use Test::File::ShareDir qw(with_dist_dir);
use lib "$FindBin::Bin/07_files/lib";
use Example;
use File::ShareDir qw( dist_dir dist_file );

my $distname = "Should-Not-Exist-X" . int( rand() * 255 );
my $ddir;
if ( not exception { $ddir = dist_dir($distname); 1 } ) {
  diag "Found should-not-exist dir at $ddir";
  plan skip_all => "dist_dir($distname) needs to not exist";
}

with_dist_dir(
  { $distname => 't/07_files/share' } => sub {
    is(
      exception {
        note dist_dir($distname);
      },
      undef,
      'dist_dir doesn\'t bail as it finds the dir'
    );

    is(
      exception {
        note dist_file( $distname, 'afile' );
      },
      undef,
      'dist_file doesn\'t bail as it finds the file'
    );
  },
);

isnt(
  exception {
    diag dist_dir($distname);
  },
  undef,
  'dist_dir bails after clear'
);

# Note: This code warns, its a bug in File::ShareDir
# dist_file( 'x', 'y' )
#  -> _dist_dir_new('x') -> Returns undef
#  -> File::Spec->catfile( undef, 'afile' )  # warns about undef in subroutine entry.
isnt(
  exception {
    diag dist_file( $distname, 'afile' );
  },
  undef,
  'dist_file bails after clear'
);

done_testing;