6 use App
::Codeowners
::Util
qw(run_git);
7 use Path
::Tiny
qw(path tempdir);
10 can_ok
('App::Codeowners::Util', qw{
12 find_codeowners_in_directory
13 find_nearest_codeowners
24 my $can_git = _can_git
();
26 subtest
'git_ls_files' => sub {
27 plan skip_all
=> 'Cannot run git' if !$can_git;
28 my $repodir =_setup_git_repo
();
30 my (undef, @r) = App
::Codeowners
::Util
::git_ls_files
($repodir);
31 is_deeply
(\
@r, [], 'git ls-files returns [] when no repo files') or diag explain \
@r;
33 run_git
('-C', $repodir, qw{add .})->wait;
34 run_git
('-C', $repodir, qw{commit -m}, 'initial commit')->wait;
36 (undef, @r) = App
::Codeowners
::Util
::git_ls_files
($repodir);
38 qw(a/b/c/bar.txt foo.txt)
39 ], 'git ls-files returns correct repo files') or diag explain \
@r;
42 subtest
'git_toplevel' => sub {
43 plan skip_all
=> 'Cannot run git' if !$can_git;
44 my $repodir =_setup_git_repo
();
46 my $r = App
::Codeowners
::Util
::git_toplevel
($repodir);
47 is($r->canonpath, $repodir->canonpath, 'found toplevel directory from toplevel');
49 $r = App
::Codeowners
::Util
::git_toplevel
($repodir->child('a/b'));
50 is($r->canonpath, $repodir->canonpath, 'found toplevel directory');
53 subtest
'find_nearest_codeowners' => sub {
54 plan skip_all
=> 'Cannot run git' if !$can_git;
55 my $repodir =_setup_git_repo
();
57 $repodir->child('docs')->mkpath;
58 my $filepath = _spew_codeowners
($repodir->child('docs/CODEOWNERS'));
60 my $r = App
::Codeowners
::Util
::find_nearest_codeowners
($repodir->child('a/b/c'));
61 is($r, $filepath, 'found CODEOWNERS file');
64 subtest
'find_codeowners_in_directory' => sub {
65 plan skip_all
=> 'Cannot run git' if !$can_git;
66 my $repodir =_setup_git_repo
();
68 $repodir->child('docs')->mkpath;
69 my $filepath = _spew_codeowners
($repodir->child('docs/CODEOWNERS'));
71 my $r = App
::Codeowners
::Util
::find_codeowners_in_directory
($repodir);
72 is($r, $filepath, 'found CODEOWNERS file in docs');
74 $filepath = _spew_codeowners
($repodir->child('CODEOWNERS'));
75 $r = App
::Codeowners
::Util
::find_codeowners_in_directory
($repodir);
76 is($r, $filepath, 'found CODEOWNERS file in toplevel');
83 my (undef, $version) = eval { run_git
('--version') };
85 note
"Found: $version" if $version;
86 return $version && $version ge 'git version 1.8.5'; # for -C flag
90 my $repodir = tempdir
;
92 run_git
('-C', $repodir, 'init')->wait;
94 $repodir->child('foo.txt')->touchpath;
95 $repodir->child('a/b/c/bar.txt')->touchpath;
100 sub _spew_codeowners
{
101 my $path = path
(shift);
102 $path->spew_utf8(\"foo
.txt \
@twix\n");