home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / TestUtil.pm < prev    next >
Encoding:
Perl POD Document  |  2004-07-12  |  20.9 KB  |  764 lines

  1. # Copyright 2001-2004 The Apache Software Foundation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. #     http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. package Apache::TestUtil;
  16.  
  17. use strict;
  18. use warnings FATAL => 'all';
  19.  
  20. use File::Find ();
  21. use File::Path ();
  22. use Exporter ();
  23. use Carp ();
  24. use Config;
  25. use File::Basename qw(dirname);
  26. use File::Spec::Functions qw(catfile file_name_is_absolute);
  27. use Symbol ();
  28.  
  29. use Apache::Test ();
  30. use Apache::TestConfig ();
  31.  
  32. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %CLEAN);
  33.  
  34. $VERSION = '0.01';
  35. @ISA     = qw(Exporter);
  36.  
  37. @EXPORT = qw(t_cmp t_debug t_append_file t_write_file t_open_file
  38.     t_mkdir t_rmtree t_is_equal t_filepath_cmp
  39.     t_server_log_error_is_expected t_server_log_warn_is_expected
  40.     t_client_log_error_is_expected t_client_log_warn_is_expected
  41. );
  42.  
  43. @EXPORT_OK = qw(t_write_perl_script t_write_shell_script t_chown
  44.                t_catfile_apache t_catfile);
  45.  
  46. %CLEAN = ();
  47.  
  48. # 5.005's Data::Dumper has problems to dump certain datastructures
  49. use constant HAS_DUMPER => eval { $] >= 5.6 && require Data::Dumper; };
  50. use constant INDENT     => 4;
  51.  
  52. # because of the prototype and recursive call to itself a forward
  53. # declaration is needed
  54. sub t_is_equal ($$);
  55.  
  56. # compare any two datastructures (must pass references for non-scalars)
  57. # undef()'s are valid args
  58. sub t_is_equal ($$) {
  59.     my ($a, $b) = @_;
  60.     return 0 unless @_ == 2;
  61.  
  62.     # this was added in Apache::Test::VERSION 1.12 - remove deprecated
  63.     # logic sometime around 1.15 or mid September, 2004.
  64.     if (UNIVERSAL::isa($a, 'Regexp')) {
  65.         my @warning = ("WARNING!!! t_is_equal() argument order has changed.",
  66.                        "use of a regular expression as the first argument",
  67.                        "is deprecated.  support will be removed soon.");
  68.         t_debug(@warning);
  69.         ($a, $b) = ($b, $a);
  70.     }
  71.  
  72.     if (defined $a && defined $b) {
  73.         my $ref_a = ref $a;
  74.         my $ref_b = ref $b;
  75.         if (!$ref_a && !$ref_b) {
  76.             return $a eq $b;
  77.         }
  78.         elsif ($ref_a eq 'ARRAY' && $ref_b eq 'ARRAY') {
  79.             return 0 unless @$a == @$b;
  80.             for my $i (0..$#$a) {
  81.                 t_is_equal($a->[$i], $b->[$i]) || return 0;
  82.             }
  83.         }
  84.         elsif ($ref_a eq 'HASH' && $ref_b eq 'HASH') {
  85.             return 0 unless (keys %$a) == (keys %$b);
  86.             for my $key (sort keys %$a) {
  87.                 return 0 unless exists $b->{$key};
  88.                 t_is_equal($a->{$key}, $b->{$key}) || return 0;
  89.             }
  90.         }
  91.         elsif ($ref_b eq 'Regexp') {
  92.             return $a =~ $b;
  93.         }
  94.         else {
  95.             # try to compare the references
  96.             return $a eq $b;
  97.         }
  98.     }
  99.     else {
  100.         # undef == undef! a valid test
  101.         return (defined $a || defined $b) ? 0 : 1;
  102.     }
  103.     return 1;
  104. }
  105.  
  106.  
  107.  
  108. sub t_cmp ($$;$) {
  109.     Carp::carp(join(":", (caller)[1..2]) . 
  110.         ' usage: $res = t_cmp($received, $expected, [$comment])')
  111.             if @_ < 2 || @_ > 3;
  112.  
  113.     my ($received, $expected) = @_;
  114.  
  115.     # this was added in Apache::Test::VERSION 1.12 - remove deprecated
  116.     # logic sometime around 1.15 or mid September, 2004.
  117.     if (UNIVERSAL::isa($_[0], 'Regexp')) {
  118.         my @warning = ("WARNING!!! t_cmp() argument order has changed.",
  119.                        "use of a regular expression as the first argument",
  120.                        "is deprecated.  support will be removed soon.");
  121.         t_debug(@warning);
  122.         ($received, $expected) = ($expected, $received);
  123.     }
  124.  
  125.     t_debug("testing : " . pop) if @_ == 3;
  126.     t_debug("expected: " . struct_as_string(0, $expected));
  127.     t_debug("received: " . struct_as_string(0, $received));
  128.     return t_is_equal($received, $expected);
  129. }
  130.  
  131. # Essentially t_cmp, but on Win32, first converts pathnames
  132. # to their DOS long name.
  133. sub t_filepath_cmp ($$;$) {
  134.     my @a = (shift, shift);
  135.     if (Apache::TestConfig::WIN32) {
  136.         $a[0] = Win32::GetLongPathName($a[0]) if defined $a[0];
  137.         $a[1] = Win32::GetLongPathName($a[1]) if defined $a[1];
  138.     }
  139.     return @_ == 1 ? t_cmp($a[0], $a[1], $_[0]) : t_cmp($a[0], $a[1]);
  140. }
  141.  
  142.  
  143. *expand = HAS_DUMPER ?
  144.     sub { map { ref $_ ? Data::Dumper::Dumper($_) : $_ } @_ } :
  145.     sub { @_ };
  146.  
  147. sub t_debug {
  148.     print map {"# $_\n"} map {split /\n/} grep {defined} expand(@_);
  149. }
  150.  
  151. sub t_open_file {
  152.     my $file = shift;
  153.  
  154.     die "must pass a filename" unless defined $file;
  155.  
  156.     # create the parent dir if it doesn't exist yet
  157.     makepath(dirname $file);
  158.  
  159.     my $fh = Symbol::gensym();
  160.     open $fh, ">$file" or die "can't open $file: $!";
  161.     t_debug("writing file: $file");
  162.     $CLEAN{files}{$file}++;
  163.  
  164.     return $fh;
  165. }
  166.  
  167. sub t_write_file {
  168.     my $file = shift;
  169.  
  170.     die "must pass a filename" unless defined $file;
  171.  
  172.     # create the parent dir if it doesn't exist yet
  173.     makepath(dirname $file);
  174.  
  175.     my $fh = Symbol::gensym();
  176.     open $fh, ">$file" or die "can't open $file: $!";
  177.     t_debug("writing file: $file");
  178.     print $fh join '', @_ if @_;
  179.     close $fh;
  180.     $CLEAN{files}{$file}++;
  181. }
  182.  
  183. sub t_append_file {
  184.     my $file = shift;
  185.  
  186.     die "must pass a filename" unless defined $file;
  187.  
  188.     # create the parent dir if it doesn't exist yet
  189.     makepath(dirname $file);
  190.  
  191.     # add to the cleanup list only if we created it now
  192.     $CLEAN{files}{$file}++ unless -e $file;
  193.  
  194.     my $fh = Symbol::gensym();
  195.     open $fh, ">>$file" or die "can't open $file: $!";
  196.     print $fh join '', @_ if @_;
  197.     close $fh;
  198. }
  199.  
  200. sub t_write_shell_script {
  201.     my $file = shift;
  202.  
  203.     my $code = join '', @_;
  204.     my($ext, $shebang);
  205.  
  206.     if (Apache::TestConfig::WIN32()) {
  207.         $code =~ s/echo$/echo./mg; #required to echo newline
  208.         $ext = 'bat';
  209.         $shebang = "\@echo off\nREM this is a bat";
  210.     }
  211.     else {
  212.         $ext = 'sh';
  213.         $shebang = '#!/bin/sh';
  214.     }
  215.  
  216.     $file .= ".$ext";
  217.     t_write_file($file, "$shebang\n", $code);
  218.     $ext;
  219. }
  220.  
  221. sub t_write_perl_script {
  222.     my $file = shift;
  223.  
  224.     my $shebang = "#!$Config{perlpath}\n";
  225.     my $warning = Apache::TestConfig->thaw->genwarning($file);
  226.     t_write_file($file, $shebang, $warning, @_);
  227.     chmod 0755, $file;
  228. }
  229.  
  230.  
  231. sub t_mkdir {
  232.     my $dir = shift;
  233.     makepath($dir);
  234. }
  235.  
  236. # returns a list of dirs successfully created
  237. sub makepath {
  238.     my($path) = @_;
  239.  
  240.     return if !defined($path) || -e $path;
  241.     my $full_path = $path;
  242.  
  243.     # remember which dirs were created and should be cleaned up
  244.     while (1) {
  245.         $CLEAN{dirs}{$path} = 1;
  246.         $path = dirname $path;
  247.         last if -e $path;
  248.     }
  249.  
  250.     return File::Path::mkpath($full_path, 0, 0755);
  251. }
  252.  
  253. sub t_rmtree {
  254.     die "must pass a dirname" unless defined $_[0];
  255.     File::Path::rmtree((@_ > 1 ? \@_ : $_[0]), 0, 1);
  256. }
  257.  
  258. #chown a file or directory to the test User/Group
  259. #noop if chown is unsupported
  260.  
  261. sub t_chown {
  262.     my $file = shift;
  263.     my $config = Apache::Test::config();
  264.     my($uid, $gid);
  265.  
  266.     eval {
  267.         #XXX cache this lookup
  268.         ($uid, $gid) = (getpwnam($config->{vars}->{user}))[2,3];
  269.     };
  270.  
  271.     if ($@) {
  272.         if ($@ =~ /^The getpwnam function is unimplemented/) {
  273.             #ok if unsupported, e.g. win32
  274.             return 1;
  275.         }
  276.         else {
  277.             die $@;
  278.         }
  279.     }
  280.  
  281.     CORE::chown($uid, $gid, $file) || die "chown $file: $!";
  282. }
  283.  
  284. # $string = struct_as_string($indent_level, $var);
  285. #
  286. # return any nested datastructure via Data::Dumper or ala Data::Dumper
  287. # as a string. undef() is a valid arg.
  288. #
  289. # $indent_level should be 0 (used for nice indentation during
  290. # recursive datastructure traversal)
  291. sub struct_as_string{
  292.     return "???"   unless @_ == 2;
  293.     my $level = shift;
  294.  
  295.     return "undef" unless defined $_[0];
  296.     my $pad  = ' ' x (($level + 1) * INDENT);
  297.     my $spad = ' ' x ($level       * INDENT);
  298.  
  299.     if (HAS_DUMPER) {
  300.         local $Data::Dumper::Terse = 1;
  301.         $Data::Dumper::Terse = $Data::Dumper::Terse; # warn
  302.         my $data = Data::Dumper::Dumper(@_);
  303.         $data =~ s/\n$//; # \n is handled by the caller
  304.         return $data;
  305.     }
  306.     else {
  307.         if (ref($_[0]) eq 'ARRAY') {
  308.             my @data = ();
  309.             for my $i (0..$#{ $_[0] }) {
  310.                 push @data,
  311.                     struct_as_string($level+1, $_[0]->[$i]);
  312.             }
  313.             return join "\n", "[", map({"$pad$_,"} @data), "$spad\]";
  314.         } elsif ( ref($_[0])eq 'HASH') {
  315.             my @data = ();
  316.             for my $key (keys %{ $_[0] }) {
  317.                 push @data,
  318.                     "$key => " .
  319.                     struct_as_string($level+1, $_[0]->{$key});
  320.             }
  321.             return join "\n", "{", map({"$pad$_,"} @data), "$spad\}";
  322.         } else {
  323.             return $_[0];
  324.         }
  325.     }
  326. }
  327.  
  328. my $banner_format = 
  329.     "\n*** The following %s expected and harmless ***\n";
  330.  
  331. sub is_expected_banner {
  332.     my $type  = shift;
  333.     my $count = @_ ? shift : 1;
  334.     sprintf $banner_format, $count == 1
  335.         ? "$type entry is"
  336.         : "$count $type entries are";
  337. }
  338.  
  339. sub t_server_log_is_expected {
  340.     print STDERR is_expected_banner(@_);
  341. }
  342.  
  343. sub t_client_log_is_expected {
  344.     my $vars = Apache::Test::config()->{vars};
  345.     my $log_file = catfile $vars->{serverroot}, "logs", "error_log";
  346.  
  347.     my $fh = Symbol::gensym();
  348.     open $fh, ">>$log_file" or die "Can't open $log_file: $!";
  349.     my $oldfh = select($fh); $| = 1; select($oldfh);
  350.     print $fh is_expected_banner(@_);
  351.     close $fh;
  352. }
  353.  
  354. sub t_server_log_error_is_expected { t_server_log_is_expected("error", @_);}
  355. sub t_server_log_warn_is_expected  { t_server_log_is_expected("warn", @_); }
  356. sub t_client_log_error_is_expected { t_client_log_is_expected("error", @_);}
  357. sub t_client_log_warn_is_expected  { t_client_log_is_expected("warn", @_); }
  358.  
  359. END {
  360.     # remove files that were created via this package
  361.     for (grep {-e $_ && -f _ } keys %{ $CLEAN{files} } ) {
  362.         t_debug("removing file: $_");
  363.         unlink $_;
  364.     }
  365.  
  366.     # remove dirs that were created via this package
  367.     for (grep {-e $_ && -d _ } keys %{ $CLEAN{dirs} } ) {
  368.         t_debug("removing dir tree: $_");
  369.         t_rmtree($_);
  370.     }
  371. }
  372.  
  373. # essentially File::Spec->catfile, but on Win32
  374. # returns the long path name, if the file is absolute
  375. sub t_catfile {
  376.     my $f = catfile(@_);
  377.     return $f unless file_name_is_absolute($f);
  378.     return Apache::TestConfig::WIN32 ?
  379.         Win32::GetLongPathName($f) : $f;
  380. }
  381.  
  382. # Apache uses a Unix-style specification for files, with
  383. # forward slashes for directory separators. This is
  384. # essentially File::Spec::Unix->catfile, but on Win32
  385. # returns the long path name, if the file is absolute
  386. sub t_catfile_apache {
  387.     my $f = File::Spec::Unix->catfile(@_);
  388.     return $f unless file_name_is_absolute($f);
  389.     return Apache::TestConfig::WIN32 ?
  390.         Win32::GetLongPathName($f) : $f;
  391. }
  392.  
  393. 1;
  394. __END__
  395.  
  396.  
  397. =head1 NAME
  398.  
  399. Apache::TestUtil - Utility functions for writing tests
  400.  
  401. =head1 SYNOPSIS
  402.  
  403.   use Apache::Test;
  404.   use Apache::TestUtil;
  405.  
  406.   ok t_cmp("foo", "foo", "sanity check");
  407.   t_write_file("filename", @content);
  408.   my $fh = t_open_file($filename);
  409.   t_mkdir("/foo/bar");
  410.   t_rmtree("/foo/bar");
  411.   t_is_equal($a, $b);
  412.  
  413. =head1 DESCRIPTION
  414.  
  415. C<Apache::TestUtil> automatically exports a number of functions useful
  416. in writing tests.
  417.  
  418. All the files and directories created using the functions from this
  419. package will be automatically destroyed at the end of the program
  420. execution (via END block). You should not use these functions other
  421. than from within tests which should cleanup all the created
  422. directories and files at the end of the test.
  423.  
  424. =head1 FUNCTIONS
  425.  
  426. =over
  427.  
  428. =item t_cmp()
  429.  
  430.   t_cmp($received, $expected, $comment);
  431.  
  432. t_cmp() prints the values of I<$comment>, I<$expected> and
  433. I<$received>. e.g.:
  434.  
  435.   t_cmp(1, 1, "1 == 1?");
  436.  
  437. prints:
  438.  
  439.   # testing : 1 == 1?
  440.   # expected: 1
  441.   # received: 1
  442.  
  443. then it returns the result of comparison of the I<$expected> and the
  444. I<$received> variables. Usually, the return value of this function is
  445. fed directly to the ok() function, like this:
  446.  
  447.   ok t_cmp(1, 1, "1 == 1?");
  448.  
  449. the third argument (I<$comment>) is optional, mostly useful for
  450. telling what the comparison is trying to do.
  451.  
  452. It is valid to use C<undef> as an expected value. Therefore:
  453.  
  454.   my $foo;
  455.   t_cmp(undef, $foo, "undef == undef?");
  456.  
  457. will return a I<true> value.
  458.  
  459. You can compare any two data-structures with t_cmp(). Just make sure
  460. that if you pass non-scalars, you have to pass their references. The
  461. datastructures can be deeply nested. For example you can compare:
  462.  
  463.   t_cmp({1 => [2..3,{5..8}], 4 => [5..6]},
  464.         {1 => [2..3,{5..8}], 4 => [5..6]},
  465.         "hash of array of hashes");
  466.  
  467. You can also compare the second argument against the first as a
  468. regex. Use the C<qr//> function in the second argument. For example:
  469.  
  470.   t_cmp("abcd", qr/^abc/, "regex compare");
  471.  
  472. will do:
  473.  
  474.   "abcd" =~ /^abc/;
  475.  
  476. This function is exported by default.
  477.  
  478. =item t_filepath_cmp()
  479.  
  480. This function is used to compare two filepaths via t_cmp().
  481. For non-Win32, it simply uses t_cmp() for the comparison,
  482. but for Win32, Win32::GetLongPathName() is invoked to convert
  483. the first two arguments to their DOS long pathname. This is useful
  484. when there is a possibility the two paths being compared
  485. are not both represented by their long or short pathname.
  486.  
  487. This function is exported by default.
  488.  
  489. =item t_debug()
  490.  
  491.   t_debug("testing feature foo");
  492.   t_debug("test", [1..3], 5, {a=>[1..5]});
  493.  
  494. t_debug() prints out any datastructure while prepending C<#> at the
  495. beginning of each line, to make the debug printouts comply with
  496. C<Test::Harness>'s requirements. This function should be always used
  497. for debug prints, since if in the future the debug printing will
  498. change (e.g. redirected into a file) your tests won't need to be
  499. changed.
  500.  
  501. This function is exported by default.
  502.  
  503. =item t_write_file()
  504.  
  505.   t_write_file($filename, @lines);
  506.  
  507. t_write_file() creates a new file at I<$filename> or overwrites the
  508. existing file with the content passed in I<@lines>. If only the
  509. I<$filename> is passed, an empty file will be created.
  510.  
  511. If parent directories of C<$filename> don't exist they will be
  512. automagically created.
  513.  
  514. The generated file will be automatically deleted at the end of the
  515. program's execution.
  516.  
  517. This function is exported by default.
  518.  
  519. =item t_append_file()
  520.  
  521.   t_append_file($filename, @lines);
  522.  
  523. t_append_file() is similar to t_write_file(), but it doesn't clobber
  524. existing files and appends C<@lines> to the end of the file. If the
  525. file doesn't exist it will create it.
  526.  
  527. If parent directories of C<$filename> don't exist they will be
  528. automagically created.
  529.  
  530. The generated file will be registered to be automatically deleted at
  531. the end of the program's execution, only if the file was created by
  532. t_append_file().
  533.  
  534. This function is exported by default.
  535.  
  536. =item t_write_shell_script()
  537.  
  538.   Apache::TestUtil::t_write_shell_script($filename, @lines);
  539.  
  540. Similar to t_write_file() but creates a portable shell/batch
  541. script. The created filename is constructed from C<$filename> and an
  542. appropriate extension automatically selected according to the platform
  543. the code is running under.
  544.  
  545. It returns the extension of the created file.
  546.  
  547. =item t_write_perl_script()
  548.  
  549.   Apache::TestUtil::t_write_perl_script($filename, @lines);
  550.  
  551. Similar to t_write_file() but creates a executable Perl script with
  552. correctly set shebang line.
  553.  
  554. =item t_open_file()
  555.  
  556.   my $fh = t_open_file($filename);
  557.  
  558. t_open_file() opens a file I<$filename> for writing and returns the
  559. file handle to the opened file.
  560.  
  561. If parent directories of C<$filename> don't exist they will be
  562. automagically created.
  563.  
  564. The generated file will be automatically deleted at the end of the
  565. program's execution.
  566.  
  567. This function is exported by default.
  568.  
  569. =item t_mkdir()
  570.  
  571.   t_mkdir($dirname);
  572.  
  573. t_mkdir() creates a directory I<$dirname>. The operation will fail if
  574. the parent directory doesn't exist.
  575.  
  576. If parent directories of C<$dirname> don't exist they will be
  577. automagically created.
  578.  
  579. The generated directory will be automatically deleted at the end of
  580. the program's execution.
  581.  
  582. This function is exported by default.
  583.  
  584. =item t_rmtree()
  585.  
  586.   t_rmtree(@dirs);
  587.  
  588. t_rmtree() deletes the whole directories trees passed in I<@dirs>.
  589.  
  590. This function is exported by default.
  591.  
  592. =item t_chown()
  593.  
  594.   Apache::TestUtil::t_chown($file);
  595.  
  596. Change ownership of $file to the test's I<User>/I<Group>.  This
  597. function is noop on platforms where chown(2) is unsupported
  598. (e.g. Win32).
  599.  
  600. =item t_is_equal()
  601.  
  602.   t_is_equal($a, $b);
  603.  
  604. t_is_equal() compares any two datastructures and returns 1 if they are
  605. exactly the same, otherwise 0. The datastructures can be nested
  606. hashes, arrays, scalars, undefs or a combination of any of these.  See
  607. t_cmp() for an example.
  608.  
  609. If C<$b> is a regex reference, the regex comparison C<$a =~ $b> is
  610. performed. For example:
  611.  
  612.   t_is_equal($server_version, qr{^Apache});
  613.  
  614. If comparing non-scalars make sure to pass the references to the
  615. datastructures.
  616.  
  617. This function is exported by default.
  618.  
  619. =item t_server_log_error_is_expected()
  620.  
  621. If the handler's execution results in an error or a warning logged to
  622. the I<error_log> file which is expected, it's a good idea to have a
  623. disclaimer printed before the error itself, so one can tell real
  624. problems with tests from expected errors. For example when testing how
  625. the package behaves under error conditions the I<error_log> file might
  626. be loaded with errors, most of which are expected.
  627.  
  628. For example if a handler is about to generate a run-time error, this
  629. function can be used as:
  630.  
  631.   use Apache::TestUtil;
  632.   ...
  633.   sub handler {
  634.       my $r = shift;
  635.       ...
  636.       t_server_log_error_is_expected();
  637.       die "failed because ...";
  638.   }
  639.  
  640. After running this handler the I<error_log> file will include:
  641.  
  642.   *** The following error entry is expected and harmless ***
  643.   [Tue Apr 01 14:00:21 2003] [error] failed because ...
  644.  
  645. When more than one entry is expected, an optional numerical argument,
  646. indicating how many entries to expect, can be passed. For example:
  647.  
  648.   t_server_log_error_is_expected(2);
  649.  
  650. will generate:
  651.  
  652.   *** The following 2 error entries are expected and harmless ***
  653.  
  654. If the error is generated at compile time, the logging must be done in
  655. the BEGIN block at the very beginning of the file:
  656.  
  657.   BEGIN {
  658.       use Apache::TestUtil;
  659.       t_server_log_error_is_expected();
  660.   }
  661.   use DOES_NOT_exist;
  662.  
  663. After attempting to run this handler the I<error_log> file will
  664. include:
  665.  
  666.   *** The following error entry is expected and harmless ***
  667.   [Tue Apr 01 14:04:49 2003] [error] Can't locate "DOES_NOT_exist.pm"
  668.   in @INC (@INC contains: ...
  669.  
  670. Also see C<t_server_log_warn_is_expected()> which is similar but used
  671. for warnings.
  672.  
  673. This function is exported by default.
  674.  
  675. =item t_server_log_warn_is_expected()
  676.  
  677. C<t_server_log_warn_is_expected()> generates a disclaimer for expected
  678. warnings.
  679.  
  680. See the explanation for C<t_server_log_error_is_expected()> for more
  681. details.
  682.  
  683. This function is exported by default.
  684.  
  685. =item t_client_log_error_is_expected()
  686.  
  687. C<t_client_log_error_is_expected()> generates a disclaimer for
  688. expected errors. But in contrast to
  689. C<t_server_log_error_is_expected()> called by the client side of the
  690. script.
  691.  
  692. See the explanation for C<t_server_log_error_is_expected()> for more
  693. details.
  694.  
  695. For example the following client script fails to find the handler:
  696.  
  697.   use Apache::Test;
  698.   use Apache::TestUtil;
  699.   use Apache::TestRequest qw(GET);
  700.   
  701.   plan tests => 1;
  702.   
  703.   t_client_log_error_is_expected();
  704.   my $url = "/error_document/cannot_be_found";
  705.   my $res = GET($url);
  706.   ok t_cmp(404, $res->code, "test 404");
  707.  
  708. After running this test the I<error_log> file will include an entry
  709. similar to the following snippet:
  710.  
  711.   *** The following error entry is expected and harmless ***
  712.   [Tue Apr 01 14:02:55 2003] [error] [client 127.0.0.1] 
  713.   File does not exist: /tmp/test/t/htdocs/error
  714.  
  715. When more than one entry is expected, an optional numerical argument,
  716. indicating how many entries to expect, can be passed. For example:
  717.  
  718.   t_client_log_error_is_expected(2);
  719.  
  720. will generate:
  721.  
  722.   *** The following 2 error entries are expected and harmless ***
  723.  
  724. This function is exported by default.
  725.  
  726. =item t_client_log_warn_is_expected()
  727.  
  728. C<t_client_log_warn_is_expected()> generates a disclaimer for expected
  729. warnings on the client side.
  730.  
  731. See the explanation for C<t_client_log_error_is_expected()> for more
  732. details.
  733.  
  734. This function is exported by default.
  735.  
  736. =item t_catfile('a', 'b', 'c')
  737.  
  738. This function is essentially C<File::Spec-E<gt>catfile>, but
  739. on Win32 will use C<Win32::GetLongpathName()> to convert the
  740. result to a long path name (if the result is an absolute file).
  741. The function is not exported by default.
  742.  
  743. =item t_catfile_apache('a', 'b', 'c')
  744.  
  745. This function is essentially C<File::Spec::Unix-E<gt>catfile>, but
  746. on Win32 will use C<Win32::GetLongpathName()> to convert the
  747. result to a long path name (if the result is an absolute file).
  748. It is useful when comparing something to that returned by Apache,
  749. which uses a Unix-style specification with forward slashes for
  750. directory separators. The function is not exported by default.
  751.  
  752. =back
  753.  
  754. =head1 AUTHOR
  755.  
  756. Stas Bekman <stas@stason.org>
  757.  
  758. =head1 SEE ALSO
  759.  
  760. perl(1)
  761.  
  762. =cut
  763.  
  764.