On Saturday, August 3, 2002, at 09:56  pm, Andy Lester wrote:

> I'm adding some tests to Test::HTML::Lint, and one of the things that I
> want to check for is that "html_ok(undef)" fails.  Remember that
> html_ok() is a T::B-based module.
[snip]

Take a look at Test::Builder::Tester. Something like this should do
the trick:

   use Test::Builder::Tester tests => 4;
   use Test::HTML::Lint;
   use Test::More;

   BEGIN { use_ok( 'Test::HTML::Lint' ); }

   my $chunk = "<P>This is a fine chunk of code</P>";

   test_out("not ok 2");
   html_ok(undef);
   test_test("undef should fail");

   html_ok( '' );  # Blank is OK
   html_ok( $chunk );

Or, if you prefer, you could go all retro and use Test and IO::File. For 
example:

   use strict;
   use Test;
   use Test::Builder;
   use Fcntl;
   use IO::File;
   use Test::HTML::Lint;

   plan tests => 2;

   my $io = IO::File->new_tmpfile or die "couldn't create tmp file 
($!)\n";
   my $Test = Test::Builder->new;
   $Test->output($io);
   $Test->failure_output($io);
   $Test->expected_tests(1);
   html_ok(undef);

   seek $io, SEEK_SET, 0;
   while (my $actual = <$io>) {
          chomp($actual);
          my $expected=<DATA>; chomp($expected);
          ok($actual, $expected);
   };

   __DATA__
   1..1
   not ok 1

> I see two problems with this approach:
>
> * It's not really a TODO item.
>
> * If html_ok(undef) unexpectedly succeeds, the results aren't really
> obvious:
[snip]

Personally, I just use TODO, unless I need to check the diagnostic
message output. In that case I use Test::Builder::Tester, unless I
need to check the plan output. In that case, I use Test and IO::File
:-)

Hope this helps.

Cheers,

Adrian

Reply via email to