fork(1) download
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use 5.010;
  6.  
  7. use Test::More tests => 10;
  8.  
  9. my $src = q{$_=q{print+($l=($~=<>)=~y///c)%4?$~:"\$_=q{$_};eval"x($l/4)};eval};
  10. my $cmd = qq{perl -e'$src'};
  11.  
  12. is( qx(echo -n | $cmd), '', 'empty input -> empty output' );
  13.  
  14. # Length is not a multiple of 4
  15. foreach my $input ( qw(a ab 123 foobar -1 ~!@#$%^&* ) ) {
  16. is( qx(echo -n '$input' | $cmd), $input, "$input -> $input" );
  17. }
  18.  
  19. # Length is a multiple of 4, 25% bonus
  20. foreach my $length ( (4, 8, 12) ) {
  21. my $input = 'a' x $length;
  22. is( qx(echo -n '$input' | $cmd), $src x ($length/4), "length == $length -> source x ". $length/4 );
  23. }
Success #stdin #stdout #stderr 0.02s 7236KB
stdin
Standard input is empty
stdout
1..10
ok 1 - empty input -> empty output
ok 2 - a -> a
ok 3 - ab -> ab
ok 4 - 123 -> 123
ok 5 - foobar -> foobar
ok 6 - -1 -> -1
ok 7 - ~!@\#$%^&* -> ~!@\#$%^&*
ok 8 - length == 4 -> source x 1
ok 9 - length == 8 -> source x 2
ok 10 - length == 12 -> source x 3
stderr
Possible attempt to put comments in qw() list at prog.pl line 15.