Skip to content

Commit

Permalink
Item11324: perltidy them all
Browse files Browse the repository at this point in the history
Forgot UnitTestContrib, which isn't in the root MANIFEST

git-svn-id: http://svn.foswiki.org/branches/Release01x01@13332 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Dec 8, 2011
1 parent c24c791 commit dfe7dbb
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 51 deletions.
4 changes: 2 additions & 2 deletions UnitTestContrib/lib/Foswiki/Contrib/UnitTestContrib.pm
Expand Up @@ -17,7 +17,7 @@ use strict;

use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION );

$VERSION = '$Rev$';
$RELEASE = '1.1';
$VERSION = '$Rev$';
$RELEASE = '1.1';
$SHORTDESCRIPTION = 'Foswiki Unit-Test Framework';

@@ -1,13 +1,11 @@
package Foswiki::Contrib::UnitTestContrib::MissingDependency;


# This module exists only to provide a module with version number
# that includes multiple dots, for the purposes of unit-testing
# extender.pl
#our $VERSION = 'Caught a comment!';
our $VERSION = '$Rev: 1234 (2010-01-19) $'; # Comment
$RELEASE =
"1.23.4"; # Comment
our $VERSION = '$Rev: 1234 (2010-01-19) $'; # Comment
$RELEASE = "1.23.4"; # Comment

require Archive::Missing;

Expand Down
Expand Up @@ -6,5 +6,4 @@ package Foswiki::Contrib::UnitTestContrib::MultiDottedVersion;
our $VERSION = '$Rev: 1234 (2010-01-19) $';
our $RELEASE = "1.23.4";


1;
5 changes: 4 additions & 1 deletion UnitTestContrib/lib/Foswiki/Contrib/UnitTestContrib/build.pl
Expand Up @@ -14,13 +14,16 @@ BEGIN

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';

# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';

# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';

# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build($build->{target});
$build->build( $build->{target} );

2 changes: 1 addition & 1 deletion UnitTestContrib/lib/Unit/CGIEngine.pm
Expand Up @@ -141,7 +141,7 @@ sub _perform_request {
local *STDOUT;
open STDOUT, '>', \$out or die "Can't redirect STDOUT to \$out: $!";
eval {
local %ENV = (%$env, FOSWIKI_ACTION => 'test' );
local %ENV = ( %$env, FOSWIKI_ACTION => 'test' );
$Foswiki::engine->run();
};

Expand Down
13 changes: 7 additions & 6 deletions UnitTestContrib/lib/Unit/Eavesdrop.pm
Expand Up @@ -40,9 +40,9 @@ sub new {
}

sub finish {
my $this = shift;
my $this = shift;
my $baseName = delete $this->{baseName};
if ( $baseName ) {
if ($baseName) {
local $^W = 0;
eval "untie( *$baseName )";
die $@ if $@;
Expand Down Expand Up @@ -86,13 +86,14 @@ sub PRINT {

my $success;
if ( $this->{principal} ) {
$fh = *{ $this->{principal} };
$fh = *{ $this->{principal} };
$success = print $fh @_;
}
else {
if ($^W) {
# A real print would generate a warning from the perspective of the caller
my ($package, $filename, $line) = caller;

# A real print would generate a warning from the perspective of the caller
my ( $package, $filename, $line ) = caller;
my $message = "print on closed filehandle ";
$message .= $this->{baseName} if defined $this->{baseName};
$message .= " at $filename line $line\n";
Expand All @@ -103,7 +104,7 @@ sub PRINT {
# This module turns one print into many.
# It is not practical to undo prints already completed if one of them fails
# so try to complete the rest of them anyway.
# The return value is set conservatively - all prints must succeed
# The return value is set conservatively - all prints must succeed
# for the result value to indicate success
foreach my $tee ( @{ $this->{tees} } ) {
$fh = *{$tee};
Expand Down
8 changes: 4 additions & 4 deletions UnitTestContrib/lib/Unit/Request.pm
Expand Up @@ -17,12 +17,12 @@ our @ISA = qw( Foswiki::Request );

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
my $this = $class->SUPER::new(@_);

# Taint everything
foreach my $k (@{$this->{param_list}}) {
foreach my $k (@{$this->{param_list}}) {
foreach (@{$this->{param}{$k}}) {
foreach my $k ( @{ $this->{param_list} } ) {
foreach my $k ( @{ $this->{param_list} } ) {
foreach ( @{ $this->{param}{$k} } ) {
$_ = TAINT($_) if defined $_;
}
}
Expand Down
71 changes: 39 additions & 32 deletions UnitTestContrib/lib/Unit/TestCase.pm
Expand Up @@ -135,9 +135,10 @@ our %tests_in;
sub list_tests {
my ( $this, $suite ) = @_;
die "No suite" unless $suite;
# We cache the test list because the test class is modified when we _gen_verification_functions
# and we don't want to list the lambda functions created therein
return @{$tests_in{$suite}} if (defined $tests_in{$suite});

# We cache the test list because the test class is modified when we _gen_verification_functions
# and we don't want to list the lambda functions created therein
return @{ $tests_in{$suite} } if ( defined $tests_in{$suite} );
my @tests;
my @verifies;
my $clz = new Devel::Symdump($suite);
Expand All @@ -150,13 +151,12 @@ sub list_tests {
}
}
my @fgs = $this->fixture_groups();

# Generate a verify method for each combination of the different
# fixture methods
my @setups = ();
push(
@tests,
_gen_verification_functions( \@setups, $suite, \@verifies, @fgs )
);
push( @tests,
_gen_verification_functions( \@setups, $suite, \@verifies, @fgs ) );
$tests_in{$suite} = \@tests;
return @tests;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ Fail the test unless the $condition is true. $message is optional.

sub assert {
my ( $this, $bool, $mess ) = @_;
::TAP($bool, $mess); #lets hack in perl TAP output
::TAP( $bool, $mess ); #lets hack in perl TAP output
return 1 if $bool;
$mess ||= "Assertion failed";
$mess = join( "\n", @{ $this->{annotations} } ) . "\n" . $mess;
Expand All @@ -226,9 +226,8 @@ sub assert_equals {
$this->assert( $expected eq $got,
$mess || "Expected:'$expected'\n But got:'$got'\n" );
}
elsif ( defined ($expected) && !defined($got) ) {
$this->assert( 0,
$mess || "Expected:'$expected'\n But got null\n" );
elsif ( defined($expected) && !defined($got) ) {
$this->assert( 0, $mess || "Expected:'$expected'\n But got null\n" );
}
else {
$this->assert_null($got);
Expand Down Expand Up @@ -258,7 +257,8 @@ Fail the test unless $wot is undef. $message is optional.

sub assert_null {
my ( $this, $wot, $mess ) = @_;
$this->assert( !defined($wot), $mess || (defined($wot) && "Expected null value, got '$wot'") );
$this->assert( !defined($wot),
$mess || ( defined($wot) && "Expected null value, got '$wot'" ) );
}

=begin TML
Expand Down Expand Up @@ -288,7 +288,7 @@ Fail the test if $got eq $expected. $message is optional.

sub assert_str_not_equals {
my ( $this, $expected, $got, $mess ) = @_;
$this->assert_not_null($expected, "Expected value may not be null");
$this->assert_not_null( $expected, "Expected value may not be null" );
$this->assert_not_null( $got,
$mess || "Expected:'$expected'\n But got null value\n" );
$this->assert( $expected ne $got,
Expand Down Expand Up @@ -413,7 +413,8 @@ sub assert_deep_equals {
if ( UNIVERSAL::isa( $expected, 'ARRAY' ) ) {
$this->assert( UNIVERSAL::isa( $got, 'ARRAY' ) );
$this->assert_equals( $#$expected, $#$got, 'Different size arrays: '.($mess||'') );
$this->assert_equals( $#$expected, $#$got,
'Different size arrays: ' . ( $mess || '' ) );
for ( 0 .. $#$expected ) {
$this->assert_deep_equals( $expected->[$_], $got->[$_], $mess,
Expand Down Expand Up @@ -470,7 +471,7 @@ expected.
=cut
sub expect_failure {
my ($this, $reason) = shift;
my ( $this, $reason ) = shift;
if ($reason) {
$this->annotate($reason);
Expand Down Expand Up @@ -500,12 +501,15 @@ sub assert_html_equals {
result => ''
};
$mess ||= "$SEPARATOR_STRING Got as result:\n$a\n$SEPARATOR_STRING (end of result)\n$SEPARATOR_STRING But expected html equal string:\n$e\n$SEPARATOR_STRING (end of expected)";
$mess ||=
"$SEPARATOR_STRING Got as result:\n$a\n$SEPARATOR_STRING (end of result)\n$SEPARATOR_STRING But expected html equal string:\n$e\n$SEPARATOR_STRING (end of expected)";
$this->assert( $e, "$filename:$line\n$mess" );
$this->assert( $a, "$filename:$line\n$mess" );
$differ ||= new Unit::HTMLDiffer();
if ( $differ->diff( $e, $a, $opts ) ) {
$this->assert( 0, "$filename:$line\n$mess\n$SEPARATOR_STRING Diff:\n$opts->{result}\n$SEPARATOR_STRING (end diff)\n" );
$this->assert( 0,
"$filename:$line\n$mess\n$SEPARATOR_STRING Diff:\n$opts->{result}\n$SEPARATOR_STRING (end diff)\n"
);
}
}
Expand All @@ -523,7 +527,8 @@ sub assert_html_matches {
$differ ||= new Unit::HTMLDiffer();
$mess ||= "$SEPARATOR_STRING Got as result:\n$a\n$SEPARATOR_STRING (end of result)\n$SEPARATOR_STRING But expected html match string:\n$e\n$SEPARATOR_STRING (end of expected)";
$mess ||=
"$SEPARATOR_STRING Got as result:\n$a\n$SEPARATOR_STRING (end of result)\n$SEPARATOR_STRING But expected html match string:\n$e\n$SEPARATOR_STRING (end of expected)";
my ( $package, $filename, $line ) = caller(0);
unless ( $differ->html_matches( $e, $a ) ) {
Expand All @@ -540,17 +545,17 @@ The message is optional.
=cut
sub assert_json_equals {
sub assert_json_equals {
my ( $this, $expected, $got, $mess ) = @_;
require JSON;
my $json = JSON->new->allow_nonref;
$this->assert_deep_equals(
$json->decode( $expected ),
$json->decode( $got ),
$this->assert_deep_equals( $json->decode($expected),
$json->decode($got),
$mess || "Expected:'$expected'\n But got:'$got'\n" );
}
}
=begin TML
---+ ObjectMethod captureSTD(\&fn, ...) -> ($stdout, $stderr, $result)
Expand All @@ -569,19 +574,18 @@ sub captureSTD {
my $proc = shift;
require File::Temp;
my %tempDirOptions = (
CLEANUP => 1
);
if ($^O eq 'MSWin32') {
my %tempDirOptions = ( CLEANUP => 1 );
if ( $^O eq 'MSWin32' ) {
#on windows, don't make a big old mess of c:\
$ENV{TEMP} =~ /(.*)/;
$tempDirOptions{DIR} = $1;
}
my $tmpdir = File::Temp::tempdir( %tempDirOptions );
my $tmpdir = File::Temp::tempdir(%tempDirOptions);
my $stdoutfile = "$tmpdir/stdout";
my $stderrfile = "$tmpdir/stderr";

my @params = @_;
my @params = @_;
my $result;

undef $this->{stdout};
Expand All @@ -595,13 +599,16 @@ sub captureSTD {
or die "Can't open temporary STDERR file $stderrfile: $!";

$result = &$proc(@params);
} finally {
}
finally {
my $f;
open($f, '<', $stdoutfile) || die "Capture failed to reopen $stdoutfile";
open( $f, '<', $stdoutfile )
|| die "Capture failed to reopen $stdoutfile";
local $/;
$this->{stdout} = <$f>;
close($f);
open($f, '<', $stderrfile) || die "Capture failed to reopen $stderrfile";
open( $f, '<', $stderrfile )
|| die "Capture failed to reopen $stderrfile";
local $/;
$this->{stderr} = <$f>;
close($f);
Expand Down

0 comments on commit dfe7dbb

Please sign in to comment.