]>
Dogcows Code - chaz/git-codeowners/blob - lib/Test/File/Codeowners.pm
1 package Test
::File
::Codeowners
;
2 # ABSTRACT: Write tests for CODEOWNERS files
8 use App
::Codeowners
::Util
qw(find_nearest_codeowners git_ls_files git_toplevel);
13 our $VERSION = '0.43'; # VERSION
15 my $Test = Test
::Builder-
>new;
20 no strict
'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
21 *{$caller.'::codeowners_syntax_ok'} = \
&codeowners_syntax_ok
;
22 *{$caller.'::codeowners_git_files_ok'} = \
&codeowners_git_files_ok
;
24 $Test->exported_to($caller);
29 sub codeowners_syntax_ok
{
30 my $filepath = shift || find_nearest_codeowners
();
32 eval { File
::Codeowners-
>parse($filepath) };
35 $Test->ok(!$err, "Check syntax: $filepath");
36 $Test->diag($err) if $err;
40 sub codeowners_git_files_ok
{
41 my $filepath = shift || find_nearest_codeowners
();
43 $Test->subtest('codeowners_git_files_ok' => sub {
44 my $codeowners = eval { File
::Codeowners-
>parse($filepath) };
46 $Test->plan(tests
=> 1);
47 $Test->ok(0, "Parse $filepath");
52 my ($proc, @files) = git_ls_files
(git_toplevel
());
54 $Test->plan($proc->wait == 0 ? (tests
=> scalar @files) : (skip_all
=> 'git ls-files failed'));
56 for my $filepath (@files) {
57 my $msg = encode
('UTF-8', "Check file: $filepath");
59 my $match = $codeowners->match($filepath);
60 my $is_unowned = $codeowners->is_unowned($filepath);
62 if (!$match && !$is_unowned) {
64 $Test->diag("File is unowned\n");
66 elsif ($match && $is_unowned) {
68 $Test->diag("File is owned but listed as unowned\n");
87 Test::File::Codeowners - Write tests for CODEOWNERS files
97 eval 'use Test::File::Codeowners';
98 plan skip_all => 'Test::File::Codeowners required for testing CODEOWNERS' if $@;
100 codeowners_syntax_ok();
105 This package has assertion subroutines for testing F<CODEOWNERS> files.
109 =head2 codeowners_syntax_ok
111 codeowners_syntax_ok(); # search up the tree for a CODEOWNERS file
112 codeowners_syntax_ok($filepath);
114 Check the syntax of a F<CODEOWNERS> file.
116 =head2 codeowners_git_files_ok
118 codeowners_git_files_ok(); # search up the tree for a CODEOWNERS file
119 codeowners_git_files_ok($filepath);
123 Please report any bugs or feature requests on the bugtracker website
124 L<https://github.com/chazmcgarvey/git-codeowners/issues>
126 When submitting a bug or request, please include a test-file or a
127 patch to an existing test-file that illustrates the bug or desired
132 Charles McGarvey <chazmcgarvey@brokenzipper.com>
134 =head1 COPYRIGHT AND LICENSE
136 This software is copyright (c) 2019 by Charles McGarvey.
138 This is free software; you can redistribute it and/or modify it under
139 the same terms as the Perl 5 programming language system itself.
This page took 0.03916 seconds and 4 git commands to generate.