* Mark Fowler <[EMAIL PROTECTED]> [2002-07-08 15:59]:
> On Mon, 8 Jul 2002, Andy Wardley wrote:
> 
> > It does now, but few of the stand-alone tests have names.  But all 
> > the tests run by test_expect() do use names, e.g.
> 
> >     ok 4 - template test 1 processed OK: Hello World\nfoo: [% foo %]\n[% DE...
> >     ok 5 - matched expected
> 
> Ah, but that's just the template text isn't it?  I want to have names
> for the tests so I know what they're trying to test (i.e. what the
> *aim* of the test is.)  Am I missing something (I frequently do.)I was
> thinking of a 
> 
> -- test --
> -- name: fred --
> 
> or even 
> 
> -- test: fred --

OK, OK, stop whining. ;)

The attached patch lets you define:

-- name: my test --

and outputs stuff in the form:

ok 1 - 'my test': message

if a name is defined, or

ok 1 - message

if not.

Here's an example:

  $ perl -MTemplate::Test
  test_expect(\*DATA);
  __DATA__
  -- test --
  Hello, world!
  -- expect --
  Hello, world!
  1..5
  ok 1 - running test_expect()
  ok 2 - template processor is engaged
  ok 3 - input read and split into 1 tests
  ok 4 - template test 1 processed OK: Hello, world!
  ok 5 - matched expected

  $ perl -MTemplate::Test
  test_expect(\*DATA);
  __DATA__
  -- test --
  -- name: my test --
  Hello, world!
  -- expect --
  Hello, world!
  1..5
  ok 1 - running test_expect()
  ok 2 - template processor is engaged
  ok 3 - input read and split into 1 tests
  ok 4 - 'my test': template test 1 processed OK: Hello, world!
  ok 5 - 'my test': matched expected

The whole test suite continues to pass.  This, of course, is a quick,
silly bandaid that address your symptom, and gets is no where in terms
of porting the test suite to Test::Builder...

(darren)

-- 
A large number of installed systems work by fiat. That is, they
work by being declared to work.
    -- Anatol Holt
--- Test.pm.orig        Mon Jul  8 16:25:00 2002
+++ Test.pm     Mon Jul  8 16:27:01 2002
@@ -254,6 +254,11 @@
     # the remaining tests are defined in @tests...
     foreach $input (@tests) {
        $count++;
+       my $name = "";
+
+       if ($input =~ s/\s*-- name: (.*?) --\s*\n//im) {
+           $name = sprintf "'%s': ", $1; 
+       }
 
        # split input by a line like "-- expect --"
        ($input, $expect) = 
@@ -280,13 +285,13 @@
        $tproc->process(\$input, $params, \$output) || do {
            warn "Template process failed: ", $tproc->error(), "\n";
            # report failure and automatically fail the expect match
-           ok(0, "template test $count process FAILED: " . subtext($input));
+           ok(0, "${name}template test $count process FAILED: " . subtext($input));
            ok(0, '(obviously did not match expected)');
            next;
        };
 
        # processed OK
-       ok(1, "template test $count processed OK: " . subtext($input));
+       ok(1, "${name}template test $count processed OK: " . subtext($input));
 
        # another hack: if the '-- expect --' section starts with 
        # '-- process --' then we process the expected output 
@@ -328,7 +333,7 @@
                   $copyi, $copye, $copyo);
        }
 
-       ok($match, $match ? "matched expected" : "did not match expected");
+       ok($match, $match ? "${name}matched expected" : "${name}did not match 
+expected");
     };
 }
 

Reply via email to