/usr/share/perl5/Code/TidyAll/t/SVN.pm is in libcode-tidyall-perl 0.20-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | package Code::TidyAll::t::SVN;
$Code::TidyAll::t::SVN::VERSION = '0.20';
use Capture::Tiny qw(capture_stdout capture_stderr capture);
use Code::TidyAll::SVN::Precommit;
use Code::TidyAll::SVN::Util qw(svn_uncommitted_files);
use Code::TidyAll::Util qw(dirname mkpath read_file realpath tempdir_simple write_file);
use Code::TidyAll;
use IPC::System::Simple qw(run);
use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
my ( $precommit_hook_template, $tidyall_ini_template );
sub test_svn : Tests {
my ($self) = @_;
my $temp_dir = tempdir_simple;
my $repo_dir = "$temp_dir/repo";
my $src_dir = "$temp_dir/src";
my $work_dir = "$temp_dir/work";
my $hook_log = "$temp_dir/hook.log";
my ( $stdout, $stderr );
my $log_contains = sub {
my $regex = shift;
like( read_file($hook_log), $regex );
};
my $clear_log = sub {
run("cat /dev/null > $hook_log");
};
my $committed = sub {
$stdout = capture_stdout { system( sprintf( 'svn status %s', $work_dir ) ) };
unlike( $stdout, qr/\S/, "committed" );
};
my $uncommitted = sub {
$stdout = capture_stdout { system( sprintf( 'svn status %s', $work_dir ) ) };
like( $stdout, qr/^M/, "uncommitted" );
};
run("svnadmin create $repo_dir");
my $hooks_dir = "$repo_dir/hooks";
ok( -d $hooks_dir, "$hooks_dir exists" );
mkpath( $src_dir, 0, 0775 );
write_file( "$src_dir/foo.txt", "abc" );
run( sprintf( 'svn -q import %s file://%s/myapp/trunk -m "import"', $src_dir, $repo_dir ) );
run( sprintf( 'svn -q checkout file://%s/myapp/trunk %s', $repo_dir, $work_dir ) );
is( read_file("$work_dir/foo.txt"), "abc", "checkout and import ok" );
cmp_deeply( [ svn_uncommitted_files($work_dir) ], [], "no uncommitted files" );
my $precommit_hook_file = "$hooks_dir/pre-commit";
my $precommit_hook = sprintf( $precommit_hook_template, realpath("lib"), $hook_log );
write_file( $precommit_hook_file, $precommit_hook );
chmod( 0775, $precommit_hook_file );
write_file( "$work_dir/foo.txt", "abc " );
mkpath( "$work_dir/bar", 0, 0775 );
run( sprintf( 'svn add %s/bar', $work_dir ) );
cmp_deeply( [ svn_uncommitted_files($work_dir) ], [ re("foo.txt") ], "one uncommitted file" );
$stderr = capture_stderr {
run( sprintf( 'svn -q commit -m "changed" %s/foo.txt %s/bar', $work_dir, $work_dir ) );
};
unlike( $stderr, qr/\S/ );
$log_contains->(qr|could not find.*upwards from 'myapp/trunk/foo.txt'|);
$clear_log->();
$committed->();
cmp_deeply( [ svn_uncommitted_files($work_dir) ], [], "no uncommitted files" );
write_file( "$work_dir/tidyall.ini", sprintf($tidyall_ini_template) );
run( sprintf( 'svn -q add %s/tidyall.ini', $work_dir ) );
cmp_deeply(
[ svn_uncommitted_files($work_dir) ],
[ re("tidyall.ini") ],
"one uncommitted file"
);
run( sprintf( 'svn -q commit -m "added" %s/tidyall.ini', $work_dir ) );
write_file( "$work_dir/foo.txt", "abc" );
$stderr =
capture_stderr { system( sprintf( 'svn -q commit -m "changed" %s/foo.txt', $work_dir ) ) };
like( $stderr, qr/1 file did not pass tidyall check/ );
like( $stderr, qr/needs tidying/ );
$uncommitted->();
write_file( "$work_dir/foo.txt", "ABC" );
write_file( "$work_dir/bar.dat", "123" );
run( sprintf( 'svn -q add %s/bar.dat', $work_dir ) );
$stderr = capture_stderr {
system(
sprintf( 'svn -q commit -m "changed" %s/foo.txt %s/bar.dat', $work_dir, $work_dir ) );
};
unlike( $stderr, qr/\S/ );
$committed->();
write_file( "$work_dir/foo.txt", "def" );
$stderr = capture_stderr {
system( sprintf( 'svn -q commit -m "NO TIDYALL - emergency fix!" %s/foo.txt', $work_dir ) );
};
unlike( $stderr, qr/\S/ );
$committed->();
}
$precommit_hook_template = '#!/usr/bin/perl
use lib qw(%s);
use Code::TidyAll::SVN::Precommit;
use Log::Any::Adapter (File => "%s");
use strict;
use warnings;
Code::TidyAll::SVN::Precommit->check(
extra_conf_files => ["perlcriticrc"],
tidyall_options => { verbose => 1 }
);
';
$tidyall_ini_template = '
[+Code::TidyAll::Test::Plugin::UpperText]
select = **/*.txt
';
|