You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by st...@apache.org on 2002/01/06 07:11:57 UTC

cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestUtil.pm

stas        02/01/05 22:11:57

  Modified:    src/docs/2.0/devel/testing testing.pod
               perl-framework/Apache-Test/lib/Apache TestUtil.pm
  Log:
  - document the regex functionality of t_cmp
  - show examples in the user documentation
  
  Revision  Changes    Path
  1.4       +16 -1     modperl-docs/src/docs/2.0/devel/testing/testing.pod
  
  Index: testing.pod
  ===================================================================
  RCS file: /home/cvs/modperl-docs/src/docs/2.0/devel/testing/testing.pod,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testing.pod	2 Jan 2002 09:35:02 -0000	1.3
  +++ testing.pod	6 Jan 2002 06:11:57 -0000	1.4
  @@ -2155,13 +2155,28 @@
         "a bad value",
         "testing feature foo");
   
  -In addition it will handle undef'ined values as well, so you can do:
  +t_cmp() will handle C<undef>'ined values as well, so you can do:
   
  +  my $expected;
     ok t_cmp(undef, $expected, "should be undef");
   
  +Finally you can use t_cmp() for regex comparisons. This feature is
  +mostly useful when there may be more than one valid expected value,
  +which can be described with regex. For example this can be useful to
  +inspect the value of C<$@> when eval() is expected to fail:
   
  +  eval {foo();}
  +  if ($@) {
  +      ok t_cmp(qr/^expecting foo/, $@, "func eval");
  +  }
   
  +which is the same as:
   
  +  eval {foo();}
  +  if ($@) {
  +      t_debug("func eval");
  +      ok $@ =~ /^expecting foo/ ? 1 : 0;
  +  }
   
   =head2 Tie-ing STDOUT to a Response Handler Object
   
  
  
  
  1.25      +15 -4     httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm
  
  Index: TestUtil.pm
  ===================================================================
  RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestUtil.pm,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- TestUtil.pm	21 Dec 2001 12:44:16 -0000	1.24
  +++ TestUtil.pm	6 Jan 2002 06:11:57 -0000	1.25
  @@ -313,13 +313,15 @@
   
     ok t_cmp(1, 1, "1 == 1?");
   
  -the third argument (I<$comment>) is optional, but a nice to use.
  +the third argument (I<$comment>) is optional, mostly useful for
  +telling what the comparison is trying to do.
   
  -It is valid to use I<undef> as an expected value. Therefore:
  +It is valid to use C<undef> as an expected value. Therefore:
   
  -  1 == t_cmp(undef, undef, "undef == undef?");
  +  my $foo;
  +  t_cmp(undef, $foo, "undef == undef?");
   
  -is true.
  +will return a I<true> value.
   
   You can compare any two data-structures with t_cmp(). Just make sure
   that if you pass non-scalars, you have to pass their references. The
  @@ -328,6 +330,15 @@
     t_cmp({1 => [2..3,{5..8}], 4 => [5..6]},
           {1 => [2..3,{5..8}], 4 => [5..6]},
           "hash of array of hashes");
  +
  +You can also compare the second argument against the first as a
  +regex. Use the C<qr//> function in the first argument. For example:
  +
  +  t_cmp(qr/^abc/, "abcd", "regex compare");
  +
  +will do:
  +
  +  "abcd" =~ /^abc/;
   
   This function is exported by default.