Created
April 13, 2014 15:02
-
-
Save satetsu888/10587701 to your computer and use it in GitHub Desktop.
競技プログラミング的なことをするときに使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
use Data::Dumper; | |
use Capture::Tiny qw/ capture /; | |
subtest script1 => sub { | |
io_test('script1.pl', "<abc> <xyz>\nhoge<abc>piyo<xyz>", "piyo\n"); | |
io_test('script1.pl', "<abc> <ijk>\n<abc>xxxx<ijk>yyyyyy<abc>zzz<ijk>", "xxxx\nzzz\n"); | |
io_test('script1.pl', "<paiza> <poh>\n<paiza><poh>", "<blank>\n"); | |
io_test('script1.pl', "<Banana> <Cupcake>\nApplePie<Banana>Bread<Cupcake>Apple<Banana><Cupcake>", "Bread\n<blank>\n"); | |
done_testing(); | |
}; | |
done_testing(); | |
sub io_test { | |
my ($script_path, $input, $output) = @_; | |
my ($stdout, $stderr) = capture { | |
open (MAIN_SCRIPT, "| perl $script_path"); | |
print MAIN_SCRIPT $input; | |
close MAIN_SCRIPT; | |
}; | |
warn Dumper $stderr; | |
is($stdout, $output, "case: $input got expected output $output"); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment