Skip to content

Commit

Permalink
Converting to use TieOut.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwern committed Nov 26, 2004
1 parent 7b5ccf5 commit 2e99fec
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions t/diag.t
Expand Up @@ -3,7 +3,10 @@
BEGIN {
if( $ENV{PERL_CORE} ) {
chdir 't';
@INC = '../lib';
@INC = ('../lib', 'lib');
}
else {
unshift @INC, 't/lib';
}
}

Expand All @@ -21,53 +24,38 @@ BEGIN {

use strict;

use Test::More tests => 7;
use Test::More tests => 4;

my $Test = Test::More->builder;

# now make a filehandle where we can send data
my $output;
tie *FAKEOUT, 'FakeOut', \$output;
use TieOut;
my $output = tie *FAKEOUT, 'TieOut';

# force diagnostic output to a filehandle, glad I added this to
# Test::Builder :)
my @lines;
my $ret;
{
local $TODO = 1;
$Test->todo_output(\*FAKEOUT);

diag("a single line");

push @lines, $output;
$output = '';

$ret = diag("multiple\n", "lines");
push @lines, split(/\n/, $output);
}

is( @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\n", ' should send exact message' );
is( $output, "# multiple\n# lines\n", ' should append multi messages');
is( $output->read, <<'DIAG', 'diag() with todo_output set' );
# a single line
# multiple
# lines
DIAG

ok( !$ret, 'diag returns false' );

{
$Test->failure_output(\*FAKEOUT);
$output = '';
$ret = diag("# foo");
}
$Test->failure_output(\*STDERR);
is( $output, "# # foo\n", "diag() adds a # even if there's one already" );
is( $output->read, "# # foo\n", "diag() adds # even if there's one already" );
ok( !$ret, 'diag returns false' );

package FakeOut;

sub TIEHANDLE {
bless( $_[1], $_[0] );
}

sub PRINT {
my $self = shift;
$$self .= join('', @_);
}

0 comments on commit 2e99fec

Please sign in to comment.