X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgit-codeowners;a=blobdiff_plain;f=lib%2FTest%2FFile%2FCodeowners.pm;fp=lib%2FTest%2FFile%2FCodeowners.pm;h=0000000000000000000000000000000000000000;hp=332b3b7eed3b361540f5dcdaf190bb50d754e1b6;hb=fd8bad44a70558edb1e643ec6f86cad1650700fa;hpb=b94d5acee38ce17d5d4e5fa233cae415d5c9f52c diff --git a/lib/Test/File/Codeowners.pm b/lib/Test/File/Codeowners.pm deleted file mode 100644 index 332b3b7..0000000 --- a/lib/Test/File/Codeowners.pm +++ /dev/null @@ -1,106 +0,0 @@ -package Test::File::Codeowners; -# ABSTRACT: Write tests for CODEOWNERS files - -=head1 SYNOPSIS - - use Test::More; - - eval 'use Test::File::Codeowners'; - plan skip_all => 'Test::File::Codeowners required for testing CODEOWNERS' if $@; - - codeowners_syntax_ok(); - done_testing; - -=head1 DESCRIPTION - -This package has assertion subroutines for testing F files. - -=cut - -use warnings; -use strict; - -use App::Codeowners::Util qw(find_nearest_codeowners git_ls_files git_toplevel); -use Encode qw(encode); -use File::Codeowners; -use Test::Builder; - -our $VERSION = '9999.999'; # VERSION - -my $Test = Test::Builder->new; - -sub import { - my $self = shift; - my $caller = caller; - no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict) - *{$caller.'::codeowners_syntax_ok'} = \&codeowners_syntax_ok; - *{$caller.'::codeowners_git_files_ok'} = \&codeowners_git_files_ok; - - $Test->exported_to($caller); - $Test->plan(@_); -} - -=func codeowners_syntax_ok - - codeowners_syntax_ok(); # search up the tree for a CODEOWNERS file - codeowners_syntax_ok($filepath); - -Check the syntax of a F file. - -=cut - -sub codeowners_syntax_ok { - my $filepath = shift || find_nearest_codeowners(); - - eval { File::Codeowners->parse($filepath) }; - my $err = $@; - - $Test->ok(!$err, "Check syntax: $filepath"); - $Test->diag($err) if $err; -} - -=func codeowners_git_files_ok - - codeowners_git_files_ok(); # search up the tree for a CODEOWNERS file - codeowners_git_files_ok($filepath); - -=cut - -sub codeowners_git_files_ok { - my $filepath = shift || find_nearest_codeowners(); - - $Test->subtest('codeowners_git_files_ok' => sub { - my $codeowners = eval { File::Codeowners->parse($filepath) }; - if (my $err = $@) { - $Test->plan(tests => 1); - $Test->ok(0, "Parse $filepath"); - $Test->diag($err); - return; - } - - my ($proc, @files) = git_ls_files(git_toplevel()); - - $Test->plan($proc->wait == 0 ? (tests => scalar @files) : (skip_all => 'git ls-files failed')); - - for my $filepath (@files) { - my $msg = encode('UTF-8', "Check file: $filepath"); - - my $match = $codeowners->match($filepath); - my $is_unowned = $codeowners->is_unowned($filepath); - - if (!$match && !$is_unowned) { - $Test->ok(0, $msg); - $Test->diag("File is unowned\n"); - } - elsif ($match && $is_unowned) { - $Test->ok(0, $msg); - $Test->diag("File is owned but listed as unowned\n"); - } - else { - $Test->ok(1, $msg); - } - } - }); -} - -1;