Debian Codegraph @

t/utils/find_file_paths.t

raw
1 use v5.42;
2 use utf8;
3 use lib qw(llib);
4
5 use Mojo::File;
6
7 use Test::More;
8
9 my $class = 'Local::CPANSA';
10 my @function_names = qw(
11 find_root
12 get_file_path
13 );
14
15 my $known_root;
16
17 subtest 'known root' => sub {
18 # ~~ root / t / utils
19 $known_root = Mojo::File->curfile->dirname->dirname->dirname;
20 diag "known root is <$known_root>";
21 ok -e $known_root->child('Makefile.PL'), 'Default target file is in root';
22 ok -e $known_root->child('cpansa'), 'cpansa file is in root';
23 };
24
25 subtest 'load' => sub {
26 use_ok $class;
27 can_ok $class, @function_names;
28
29 $class->import( @function_names );
30 ok do { no strict 'refs'; defined &{"$_"} }, "imported $_" for @function_names;
31 };
32
33 subtest 'find_root' => sub {
34 my $method = 'find_root';
35 can_ok __PACKAGE__, $method;
36
37 subtest 'no root' => sub {
38 my $target = join "--", $$, time;
39 my $root = find_root(__FILE__, $target);
40 ok ! -e $known_root->child($target), 'bad target file does not exist';
41 ok ! defined $root, 'root for bad file is undefined';
42 };
43
44 subtest 'root from argument' => sub {
45 my $root = find_root(__FILE__);
46
47 ok defined $root, 'root for this file is defined';
48 is $root, $known_root, 'root matches known root';
49 };
50
51 subtest 'root from default' => sub {
52 my $root = find_root();
53
54 ok defined $root, 'root for default is defined';
55 is $root, $known_root, 'root matches known root';
56 };
57 };
58
59 subtest 'get_file_path' => sub {
60 my $method = 'get_file_path';
61 can_ok __PACKAGE__, $method;
62
63 subtest 'no such file' => sub {
64 my $target = join "--", $$, time;
65 my $paths = get_file_path("$target$target");
66 isa_ok $paths, ref [];
67 is scalar $paths->@*, 0, 'no files found'
68 };
69
70 subtest 'good file' => sub {
71 my $paths = get_file_path('IGNORE_CVEs');
72 isa_ok $paths, ref [];
73 is scalar $paths->@*, 1, 'one file found: ' . $paths->[0];
74 };
75 };
76
77 done_testing;