7 # test T::H::_open_spool and _close_spool - these are good examples
8 # of the 'Fragile Test' pattern - messing with I/O primitives breaks
17 # setup replacements for core open and close - breaking these makes everything very fragile
19 $useOrigOpen = $useOrigClose = 1;
21 # taken from http://www.perl.com/pub/a/2002/06/11/threads.html?page=2
23 *CORE::GLOBAL::open = \&my_open;
27 if ( defined( $_[0] ) ) {
29 my $handle = Symbol::qualify( $_[0], (caller)[0] );
32 return CORE::open($handle);
35 return CORE::open( $handle, $_[1] );
38 die "Can't open with more than two args";
47 *CORE::GLOBAL::close = sub (*) {
48 if ($useOrigClose) { return CORE::close(shift) }
61 # coverage tests for the basically untested T::H::_open_spool
63 my @spool = ( 't', 'spool' );
64 $ENV{PERL_TEST_HARNESS_DUMP_TAP} = File::Spec->catfile(@spool);
66 # now given that we're going to be writing stuff to the file system, make sure we have
72 $useOrigOpen = $useOrigClose = 1;
74 # remove the tree if we made it this far
75 rmtree( $ENV{PERL_TEST_HARNESS_DUMP_TAP} )
76 if $ENV{PERL_TEST_HARNESS_DUMP_TAP};
82 local $SIG{__DIE__} = sub { push @die, @_ };
87 TAP::Harness->_open_spool(
88 File::Spec->catfile(qw (source_tests harness )) );
90 # restore universal sanity
94 is @die, 1, 'open failed, die as expected';
96 my $spoolDir = quotemeta(
97 File::Spec->catfile( @spool, qw( source_tests harness ) ) );
99 like pop @die, qr/ Can't write $spoolDir \( /, '...with expected message';
101 # now make close fail
105 my $spoolHandle = gensym;
107 my $tap = <<'END_TAP';
109 ok 1 - input file opened
113 my $parser = TAP::Parser->new(
114 { spool => $spoolHandle,
116 TAP::Parser::IteratorFactory->new( [ split /\n/ => $tap ] )
123 local $SIG{__DIE__} = sub { push @die, @_ };
125 # use the broken CORE::close
128 TAP::Harness->_close_spool($parser);
133 unless ( is @die, 1, 'close failed, die as expected' ) {
134 diag " >>> $_ <<<\n" for @die;
137 like pop @die, qr/ Error closing TAP spool file[(] /,
138 '...with expected message';