#!/usr/bin/perl use Modern::Perl; use Test::More; use Path::Tiny; my $input = "input.txt"; compile("gcc -o c/ch-1 c/ch-1.c"); compile("g++ -o cpp/ch-1 cpp/ch-1.cpp"); compile("fbc basic/ch-1.bas"); for (["opt bat saw tab pot top was" => < < < < "1 -> 2 -> 4 -> 5 -> 6 -> 7 -> 3"], 1 / \ 2 3 / \ 4 5 / \ 6 7 END [<<'END' => "7 -> 5 -> 4 -> 6 -> 8 -> 9"]) { 7 / \ 5 8 / \ \ 4 6 9 END my($in, $out) = @$_; path($input)->spew($in); is capture( "perl perl/ch-2.pl < $input"), "$out\n"; is capture("python python/ch-2.py < $input"), "$out\n"; is capture( "gforth forth/ch-2.fs < $input"), "$out\n"; is capture( "c/ch-2 < $input"), "$out\n"; is capture( "cpp/ch-2 < $input"), "$out\n"; is capture( "basic/ch-2 < $input"), "$out\n"; } unlink $input; done_testing; sub capture { my($cmd) = @_; my $out = `$cmd`; $out =~ s/[ \t\v\f\r]*\n/\n/g; return $out; } sub compile { my($cmd) = @_; 0==system($cmd) or die "Compile failed: $cmd\n"; }