]> Dogcows Code - chaz/git-codeowners/blobdiff - t/app-codeowners.t
fix broken "create" and "update" commands
[chaz/git-codeowners] / t / app-codeowners.t
index e3a1e2ea9afae009084ee1143eaf8f965dce2368..5ec78cb8e9b37295e94b231ea38f4e862cb80b68 100644 (file)
@@ -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 (undef, $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
 }
This page took 0.022789 seconds and 4 git commands to generate.