X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=t%2Fapp-codeowners.t;h=af426e69d0f5b43821a1842cc6e2b697dd23f1e0;hb=391901ee321dbab7361e1d63c39215d2deb0f551;hp=8be4287d30487e23e29d1cead3ce4734b153104d;hpb=20d609473454c52a00daa59ff30214890ead4211;p=chaz%2Fgit-codeowners diff --git a/t/app-codeowners.t b/t/app-codeowners.t index 8be4287..af426e6 100644 --- a/t/app-codeowners.t +++ b/t/app-codeowners.t @@ -14,8 +14,8 @@ use Test::More; my $can_git = _can_git(); -# Set progname so that pod2usage knows how to find the script after we chdir -$0 = path($Bin)->parent->child('bin/git-codeowners')->absolute; +# Set progname so that pod2usage knows how to find the script after we chdir. +$0 = path($Bin)->parent->child('bin/git-codeowners')->absolute->stringify; $ENV{NO_COLOR} = 1; @@ -65,18 +65,38 @@ END subtest 'format json' => sub { plan skip_all => 'No JSON::MaybeXS' if !eval { require JSON::MaybeXS }; - ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{-f json show --no-project}) }; + ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{-f json show --no-projects}) }; is($exit, 0, 'exited without error'); my $expect = '[{"File":"CODEOWNERS","Owner":null},{"File":"a/b/c/bar.txt","Owner":["@snickers"]},{"File":"foo.txt","Owner":["@twix"]}]'; is($stdout, $expect, 'correct output with json format'); }; }; +subtest 'create' => sub { + plan skip_all => 'Cannot run git' if !$can_git; + + my $repodir = _setup_git_repo(); + my $chdir = pushd($repodir); + + my $codeowners_filepath = path('CODEOWNERS'); + $codeowners_filepath->remove; + + my ($stdout, $stderr, $exit) = run { App::Codeowners->main(qw{create}) }; + is($exit, 0, 'exited without error'); + is($stderr, "Wrote CODEOWNERS\n", 'reportedly wrote a CODEOWNERS file'); + + ok($codeowners_filepath->is_file, 'did write CODEOWNERS file'); + + my $contents = $codeowners_filepath->slurp_utf8; + like($contents, qr/^# This file shows mappings/, 'correct contents of file') or diag $contents; +}; + done_testing; exit; sub _can_git { - my ($version) = run_git('--version'); + my (undef, $version) = eval { run_git('--version') }; + note $@ if $@; note "Found: $version" if $version; return $version && $version ge 'git version 1.8.5'; # for -C flag } @@ -93,9 +113,9 @@ sub _setup_git_repo { a/ @snickers END - run_git('-C', $repodir, qw{init}); - run_git('-C', $repodir, qw{add .}); - run_git('-C', $repodir, qw{commit -m}, 'initial commit'); + run_git('-C', $repodir, qw{init})->wait; + run_git('-C', $repodir, qw{add .})->wait; + run_git('-C', $repodir, qw{commit -m}, 'initial commit')->wait; return $repodir; }