]>
Dogcows Code - chaz/git-codeowners/blob - t/app-codeowners.t
5d378416919d4064818aef56cc04c6e9c182817e
7 use Test
::Exit
; # must be first
8 use App
::Codeowners
::Util
qw(run_git);
10 use Capture
::Tiny
qw(capture);
12 use Path
::Tiny
qw(path tempdir);
15 my $can_git = _can_git
();
16 plan skip_all
=> 'Cannot run git' if !$can_git;
18 # Set progname so that pod2usage knows how to find the script after we chdir
19 $0 = path
($Bin)->parent->child('bin/git-codeowners')->absolute;
23 subtest
'basic options' => sub {
24 my $repodir = _setup_git_repo
();
25 my $chdir = pushd
($repodir);
27 my ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main('--help') } };
28 is($exit, 0, 'exited 0 when --help');
29 like
($stdout, qr/Usage:/, 'correct --help output') or diag
$stdout;
31 ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main('--version') } };
32 is($exit, 0, 'exited 0 when --version');
33 like
($stdout, qr/git-codeowners [\d.]+\n/, 'correct --version output') or diag
$stdout;
36 subtest
'bad options' => sub {
37 my $repodir = _setup_git_repo
();
38 my $chdir = pushd
($repodir);
40 my ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main(qw{show --not-an-option}) } };
41 is($exit, 2, 'exited with error on bad option');
42 like
($stderr, qr/Unknown option: not-an-option/, 'correct error message') or diag
$stderr;
45 subtest
'show' => sub {
46 my $repodir = _setup_git_repo
();
47 my $chdir = pushd
($repodir);
49 my ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main(qw{-f %F;%O show}) } };
50 is($exit, 0, 'exited without error');
51 is($stdout, <<'END', 'correct output');
53 a/b/c/bar.txt;@snickers
57 ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main(qw{-f %F;%O;%P show}) } };
58 is($exit, 0, 'exited without error');
59 is($stdout, <<'END', 'correct output');
61 a/b/c/bar.txt;@snickers;peanuts
65 subtest
'format json' => sub {
66 plan skip_all
=> 'No JSON::MaybeXS' if !eval { require JSON
::MaybeXS
};
68 ($stdout, $stderr, $exit) = capture
{ exit_code
{ App
::Codeowners-
>main(qw{-f json show --no-project}) } };
69 is($exit, 0, 'exited without error');
70 my $expect = '[{"File":"CODEOWNERS","Owner":null},{"File":"a/b/c/bar.txt","Owner":["@snickers"]},{"File":"foo.txt","Owner":["@twix"]}]';
71 is($stdout, $expect, 'correct output with json format');
79 my ($version) = run_git
('--version');
84 my $repodir = tempdir
;
86 $repodir->child('foo.txt')->touchpath;
87 $repodir->child('a/b/c/bar.txt')->touchpath;
88 $repodir->child('CODEOWNERS')->spew_utf8([<<'END']);
95 run_git
('-C', $repodir, qw{init});
96 run_git
('-C', $repodir, qw{add .});
97 run_git
('-C', $repodir, qw{commit -m}, 'initial commit');
This page took 0.040251 seconds and 3 git commands to generate.