5.15. Move external call into functionExample 5-24. examples/intro/t14_calc.t #!/usr/bin/perl
use strict;
use warnings;
use Test::Simple "no_plan";
open my $fh, "<", "calc.txt" or die $!;
while ( my $line = <$fh> ) {
chomp $line;
next if $line =~ /^\s*(#.*)?$/;
my ( $exp, $res ) = split /\s*=\s*/, $line;
ok( mycalc($exp) == $res, $exp );
}
sub mycalc {
return `./mycalc @_`;
}
See the mycalc() function. use MyCalc;
use Test::Simple tests => 1;
ok(mycalc('2 + 3') == 5);
|
Follow me: