X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgit-codeowners;a=blobdiff_plain;f=t%2Fapp-codeowners.t;h=b5e430e3177919d6a38517d278cea564623372fd;hp=64415394b69acb1e0b01d6ac004d90d789123fb4;hb=a27d001901b781e8a4355073b4b4ea1613ce084b;hpb=db8d6aadf317d912839510afcd05b6d4bce08237 diff --git a/t/app-codeowners.t b/t/app-codeowners.t index 6441539..b5e430e 100644 --- a/t/app-codeowners.t +++ b/t/app-codeowners.t @@ -9,13 +9,13 @@ use App::Codeowners::Util qw(run_git); use App::Codeowners; use Capture::Tiny qw(capture); use File::pushd; -use Path::Tiny qw(path tempdir); +use Path::Tiny 0.089 qw(path tempdir); 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,13 +65,32 @@ 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;