Apache-Test
view release on metacpan or search on metacpan
lib/Apache/TestUtil.pm view on Meta::CPAN
: "$count $type entries are";
}
sub t_server_log_is_expected {
print STDERR is_expected_banner(@_);
}
sub t_client_log_is_expected {
my $vars = Apache::Test::config()->{vars};
my $log_file = catfile $vars->{serverroot}, "logs", "error_log";
my $fh = Symbol::gensym();
open $fh, ">>$log_file" or die "Can't open $log_file: $!";
my $oldfh = select($fh); $| = 1; select($oldfh);
print $fh is_expected_banner(@_);
close $fh;
}
sub t_server_log_error_is_expected { t_server_log_is_expected("error", @_);}
sub t_server_log_warn_is_expected { t_server_log_is_expected("warn", @_); }
sub t_client_log_error_is_expected { t_client_log_is_expected("error", @_);}
sub t_client_log_warn_is_expected { t_client_log_is_expected("warn", @_); }
END {
# remove files that were created via this package
for (grep {-e $_ && -f _ } keys %{ $CLEAN{files} } ) {
t_debug("removing file: $_");
unlink $_;
}
# remove dirs that were created via this package
for (grep {-e $_ && -d _ } keys %{ $CLEAN{dirs} } ) {
t_debug("removing dir tree: $_");
t_rmtree($_);
}
}
# essentially File::Spec->catfile, but on Win32
# returns the long path name, if the file is absolute
sub t_catfile {
my $f = catfile(@_);
return $f unless file_name_is_absolute($f);
return Apache::TestConfig::WIN32 && -e $f ?
Win32::GetLongPathName($f) : $f;
}
# Apache uses a Unix-style specification for files, with
# forward slashes for directory separators. This is
# essentially File::Spec::Unix->catfile, but on Win32
# returns the long path name, if the file is absolute
sub t_catfile_apache {
my $f = File::Spec::Unix->catfile(@_);
return $f unless file_name_is_absolute($f);
return Apache::TestConfig::WIN32 && -e $f ?
Win32::GetLongPathName($f) : $f;
}
1;
__END__
=encoding utf8
=head1 NAME
Apache::TestUtil - Utility functions for writing tests
=head1 SYNOPSIS
use Apache::Test;
use Apache::TestUtil;
ok t_cmp("foo", "foo", "sanity check");
t_write_file("filename", @content);
my $fh = t_open_file($filename);
t_mkdir("/foo/bar");
t_rmtree("/foo/bar");
t_is_equal($a, $b);
=head1 DESCRIPTION
C<Apache::TestUtil> automatically exports a number of functions useful
in writing tests.
All the files and directories created using the functions from this
package will be automatically destroyed at the end of the program
execution (via END block). You should not use these functions other
than from within tests which should cleanup all the created
directories and files at the end of the test.
=head1 FUNCTIONS
=over
=item t_cmp()
t_cmp($received, $expected, $comment);
t_cmp() prints the values of I<$comment>, I<$expected> and
I<$received>. e.g.:
t_cmp(1, 1, "1 == 1?");
prints:
# testing : 1 == 1?
# expected: 1
# received: 1
then it returns the result of comparison of the I<$expected> and the
I<$received> variables. Usually, the return value of this function is
fed directly to the ok() function, like this:
ok t_cmp(1, 1, "1 == 1?");
the third argument (I<$comment>) is optional, mostly useful for
telling what the comparison is trying to do.
It is valid to use C<undef> as an expected value. Therefore:
my $foo;
t_cmp(undef, $foo, "undef == undef?");
( run in 1.918 second using v1.01-cache-2.11-cpan-39bf76dae61 )