On Wed, 19 Dec 2001 05:12:05 -0700, Michael G Schwern wrote:
> On Wed, Dec 19, 2001 at 07:52:03AM -0500, Barrie Slaymaker wrote:
>> I noticed that Test::Builder offers the ability to emit messages with s/^/#
>> /mg, which is very nice. Can/should this capability be exposed via
>> Test::Simple, Test::More, etc?
>
> Its been on the TODO list to toss a diag() into Test::More.
>
> ok( ... ) || diag(...);
>
> for some reason I keep putting it off.
>
> Test::Simple won't get one, it would double the size of the API! ;)
Something like this? diffing against a directory tree is odd... there must be
a better way.
-- c
diff -ur /var/tmp/.cpan/build/Test-Simple-0.36/MANIFEST Test-Simple-0.36/MANIFEST
--- /var/tmp/.cpan/build/Test-Simple-0.36/MANIFEST Thu Nov 29 12:11:49 2001
+++ Test-Simple-0.36/MANIFEST Wed Dec 19 12:17:21 2001
@@ -10,6 +10,7 @@
t/Builder.t
t/More.t
t/buffer.t
+t/diag.t
t/exit.t
t/extra.t
t/fail-like.t
diff -ur /var/tmp/.cpan/build/Test-Simple-0.36/lib/Test/More.pm
Test-Simple-0.36/lib/Test/More.pm
--- /var/tmp/.cpan/build/Test-Simple-0.36/lib/Test/More.pm Tue Nov 27 13:41:34
2001
+++ Test-Simple-0.36/lib/Test/More.pm Wed Dec 19 12:01:26 2001
@@ -28,6 +28,7 @@
$TODO
plan
can_ok isa_ok
+ diag
);
my $Test = Test::Builder->new;
@@ -905,6 +906,21 @@
return eq_array( [sort _bogus_sort @$a1], [sort _bogus_sort @$a2] );
}
+=cut
+
+=item B<diag>
+
+ diag("Uh oh\n", "Something is wrong...\n");
+
+Prints a diagnostic message or messages. These are guaranteed not to interfere
+with test output, and they will be suppressed by any test harness when running
+in quiet mode. They can be very handy otherwise.
+
+=cut
+
+sub diag {
+ $Test->diag(@_);
+}
=back
--- /dev/null Thu Aug 30 03:54:37 2001
+++ Test-Simple-0.36/t/diag.t Wed Dec 19 12:16:18 2001
@@ -0,0 +1,46 @@
+#!perl -w
+use strict;
+
+use Test::More;
+use Test::Builder;
+
+# this is a singleton, easy enough to test this
+my $Test = Test::Builder->new();
+
+# now make a filehandle where we can send data
+my $output;
+tie *FAKEOUT, 'FakeOut', \$output;
+
+# force diagnostic output to a filehandle, glad I added this to Test::Builder :)
+use vars qw( $TODO );
+$TODO = 1;
+$Test->todo_output(\*FAKEOUT);
+
+diag("a single line");
+
+my @lines;
+push @lines, $output;
+$output = '';
+
+diag("multiple\n", "lines");
+push @lines, split(/\n/, $output);
+
+undef $TODO;
+
+plan tests => 4;
+
+is( scalar @lines, 3, 'diag() should send messages to its filehandle' );
+like( $lines[0], '/^#\s+/', '... should add comment mark to all lines' );
+is( $lines[0], "# a single line", '... should send exact message' );
+is( $output, "# multiple\n# lines", '... should append multi messages');
+
+package FakeOut;
+
+sub TIEHANDLE {
+ bless( $_[1], $_[0] );
+}
+
+sub PRINT {
+ my $self = shift;
+ $$self .= join('', @_);
+}