#!/usr/bin/perl -w # NOTE IT RELIES ON TIMING AND COULD FAIL IF MACHINE # HEAVILY LOADED WHEN TEST RUNS use strict; use warnings FATAL => 'all', NONFATAL => 'redefine'; use Test::More tests => 19; use Test::Exception; use Dirs qw(CODELIB_DIR MYTMP_DIR); use Path::Class; my $death = file( CODELIB_DIR, 'Test', 'HighlanderTests', 'death.pl' ); my $simple = file( CODELIB_DIR, 'Test', 'HighlanderTests', 'simple.pl' ); use_ok( 'Util', qw(another_instance_running) ); ok( -f $death, "-f $death" ); ok( -f $simple, "-f $simple" ); my $okfile = file( MYTMP_DIR, 'highlander.ok' ); my $PASSES = "&& touch $okfile"; my $FAILS = "|| touch $okfile"; &remove; my $x = "perl $death $FAILS"; print $x; my $rc = system("perl $death $FAILS"); file_present('death is a failure'); &remove; $rc = system("perl $simple $PASSES"); file_present('simple alone'); &remove; $rc = system("(perl $simple&); sleep 1; perl $simple $FAILS"); file_present('double simple short sleep'); &remove; $rc = system("(perl $simple&); sleep 4; perl $simple $PASSES"); file_present('double simple long sleep'); my $rpl = file( CODELIB_DIR, 'Test', 'HighlanderTests', 'reportbuilder.pl' ); ok( -f $simple, "-f $rpl" ); &remove; $rc = system("perl $rpl $PASSES"); file_present('$rpl lives'); sleep(5); # gotta sleep to let previous instance finish &remove; $rc = system("(perl $rpl&); sleep 1; perl $rpl $FAILS"); file_present('double rpl short pause to let the other one load'); sleep(5); # gotta sleep to let previous instance finish &remove; $rc = system("(perl $rpl&); sleep 4; perl $rpl $PASSES"); file_present('double $rpl with a nice pause'); &remove; my $count = 0; sub remove { unlink $okfile; ok( !-f $okfile, $okfile . ' old is now gone' ); } sub file_present { my $msg = shift; ok( -f $okfile, $msg . ', test went as planned' ); }