[libcode-tidyall-perl] 95/374: fix tests
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:25:55 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit f1197d38a6ec5b08f9afcdbf3b48661d60ea70c0
Author: Jonathan Swartz <swartz at pobox.com>
Date: Mon Jul 16 16:28:11 2012 -0700
fix tests
---
lib/Code/TidyAll/t/SVN.pm | 52 +++++++++++++++++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 6 deletions(-)
diff --git a/lib/Code/TidyAll/t/SVN.pm b/lib/Code/TidyAll/t/SVN.pm
index fbe6b99..e4bd7ed 100644
--- a/lib/Code/TidyAll/t/SVN.pm
+++ b/lib/Code/TidyAll/t/SVN.pm
@@ -1,11 +1,15 @@
package Code::TidyAll::t::SVN;
use Code::TidyAll::Util qw(dirname mkpath read_file realpath tempdir_simple write_file);
use Code::TidyAll;
-use Capture::Tiny qw(capture_stdout);
+use Capture::Tiny qw(capture_stdout capture_stderr capture);
use IPC::System::Simple qw(run);
use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
-my $precommit_hook_template;
+my ( $precommit_hook_template, $tidyall_ini_template );
+
+sub test_basic : Tests {
+ ok(1);
+}
sub test_svn_precommit_hook : Tests {
my ($self) = @_;
@@ -14,6 +18,17 @@ sub test_svn_precommit_hook : Tests {
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");
+ };
run("svnadmin create $repo_dir");
my $hooks_dir = "$repo_dir/hooks";
@@ -22,15 +37,35 @@ sub test_svn_precommit_hook : Tests {
mkpath( $src_dir, 0, 0775 );
write_file( "$src_dir/foo.txt", "abc" );
- run( sprintf( 'svn import %s file://%s/myapp/trunk -m "import"', $src_dir, $repo_dir ) );
- run( sprintf( 'svn checkout -q file://%s/myapp/trunk %s', $repo_dir, $work_dir ) );
+ 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" );
my $precommit_hook_file = "$hooks_dir/pre-commit";
- my $precommit_hook = sprintf( $precommit_hook_template, realpath("lib") );
+ 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 " );
+ run( sprintf( 'svn -q commit -m "changed" %s/foo.txt', $work_dir ) );
+ $log_contains->(qr|could not find 'tidyall.ini' upwards from 'myapp/trunk/foo.txt'|);
+ $clear_log->();
+ write_file( "$work_dir/tidyall.ini", sprintf($tidyall_ini_template) );
+ run( sprintf( 'svn -q add %s/tidyall.ini', $work_dir ) );
+ 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/UpperText.*needs tidying/ );
+
+ write_file( "$work_dir/foo.txt", "ABC" );
+ $stderr =
+ capture_stderr { system( sprintf( 'svn -q commit -m "changed" %s/foo.txt', $work_dir ) ) };
+ ok( $stderr !~ /\S/, "commit ok" );
}
$precommit_hook_template = '#!/usr/bin/perl
@@ -41,9 +76,14 @@ use strict;
use warnings;
Log::Any::Adapter->set( "Dispatch",
- outputs => [ [ "Screen", min_level => "debug", newline => 1 ] ] );
+ outputs => [ [ "File", filename => "%s", mode => ">>", min_level => "debug", newline => 1 ] ] );
Code::TidyAll::SVN::Precommit->check(
extra_conf_files => ["perlcriticrc"],
tidyall_options => { verbose => 1 }
);
';
+
+$tidyall_ini_template = '
+[+Code::TidyAll::Test::Plugin::UpperText]
+select = **/*.txt
+';
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list