Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created March 17, 2010 12:03
Show Gist options
  • Select an option

  • Save clairvy/335158 to your computer and use it in GitHub Desktop.

Select an option

Save clairvy/335158 to your computer and use it in GitHub Desktop.
str.pl
undef.pl
default : test
expand : undef.pl str.pl
undef.pl : no.pl
perl -pe 's/my \$$res;/my \$$res = undef;/' no.pl > undef.pl
chmod +x undef.pl
str.pl : no.pl
perl -pe 's/my \$$res;/my \$$res = '"''"';/' no.pl > str.pl
chmod +x str.pl
test : expand
prove ./test.pl
#!/usr/bin/env perl
sub test {
local $SIG{ALRM} = sub {
die;
};
alarm 2;
my $res;
eval {
chomp($res = <STDIN>);
};
alarm 0;
return $res;
}
print "1st : ", test(), "\n";
print "2nd : ", test(), "\n";
#!/usr/bin/env perl
sub test {
local $SIG{ALRM} = sub {
die;
};
alarm 2;
my $res = '';
eval {
chomp($res = <STDIN>);
};
alarm 0;
return $res;
}
print "1st : ", test(), "\n";
print "2nd : ", test(), "\n";
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More 'no_plan';
my $expect = <<EOL;
1st : aa
2nd :
EOL
foreach my $base (qw(no undef str)) {
is(`( echo aa; sleep 3; echo bb ) | ./$base.pl`, $expect, "test for $base");
}
#!/usr/bin/env perl
sub test {
local $SIG{ALRM} = sub {
die;
};
alarm 2;
my $res = undef;
eval {
chomp($res = <STDIN>);
};
alarm 0;
return $res;
}
print "1st : ", test(), "\n";
print "2nd : ", test(), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment