| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| |
| |
|
|
| require 5.003; |
| use strict; |
|
|
| (my $program_name = $0) =~ s|.*/||; |
|
|
| my $prog = 'comm'; |
|
|
| |
| @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; |
|
|
| my @inputs = ({IN=>{a=>"1\n3\n3\n3"}}, {IN=>{b=>"2\n2\n3\n3\n3"}}); |
| my @zinputs = ({IN=>{za=>"1\0003\0003\0003"}}, |
| {IN=>{zb=>"2\0002\0003\0003\0003"}}); |
|
|
| my @Tests = |
| ( |
| |
| ['basic', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n"} ], |
| ['zbasic', '-z', @zinputs, {OUT=>"1\0\t2\0\t2\0\t\t3\0\t\t3\0\t\t3\0"} ], |
|
|
| |
| ['opt-1', '-1', @inputs, {OUT=>"2\n2\n\t3\n\t3\n\t3\n"} ], |
| ['zopt-1', '-z', '-1', @zinputs, {OUT=>"2\0002\000\t3\000\t3\000\t3\000"} ], |
|
|
| |
| ['opt-2', '-2', @inputs, {OUT=>"1\n\t3\n\t3\n\t3\n"} ], |
| ['zopt-2', '-z', '-2', @zinputs, {OUT=>"1\000\t3\000\t3\000\t3\000"} ], |
|
|
| |
| ['opt-3', '-3', @inputs, {OUT=>"1\n\t2\n\t2\n"} ], |
| ['zopt-3', '-z', '-3', @zinputs, {OUT=>"1\000\t2\000\t2\000"} ], |
|
|
| |
| ['opt-12', '-1', '-2', @inputs, {OUT=>"3\n3\n3\n"} ], |
| ['zopt-12', '-12z', @zinputs, {OUT=>"3\0003\0003\000"} ], |
|
|
| |
| ['opt-13', '-1', '-3', @inputs, {OUT=>"2\n2\n"} ], |
| ['zopt-13', '-13z', @zinputs, {OUT=>"2\0002\000"} ], |
|
|
| |
| ['opt-23', '-2', '-3', @inputs, {OUT=>"1\n"} ], |
| ['zopt-23', '-23z', @zinputs, {OUT=>"1\000"} ], |
|
|
| |
| ['opt-123', '-1', '-2', '-3', @inputs, {OUT=>""} ], |
|
|
| |
| ['total-all', '--total', @inputs, {OUT=>"1\n\t2\n\t2\n\t\t3\n\t\t3\n\t\t3\n" |
| . "1\t2\t3\ttotal\n"} ], |
|
|
| |
| ['total-123', '--total', '-123', @inputs, {OUT=>"1\t2\t3\ttotal\n"} ], |
|
|
| |
| ['missing-arg1', $inputs[0], {EXIT=>1}, |
| {ERR => "$prog: missing operand after 'a'\n" |
| . "Try '$prog --help' for more information.\n"}], |
|
|
| |
| ['missing-arg2', {EXIT=>1}, |
| {ERR => "$prog: missing operand\n" |
| . "Try '$prog --help' for more information.\n"}], |
|
|
| |
| ['extra-arg', @inputs, 'no-such', {EXIT=>1}, |
| {ERR => "$prog: extra operand 'no-such'\n" |
| . "Try '$prog --help' for more information.\n"}], |
|
|
| |
| ['ooo', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, |
| {OUT => "1\n\t\t3\n\t2\n"}, |
| {ERR => "$prog: file 2 is not in sorted order\n" |
| . "$prog: input is not in sorted order\n"}], |
|
|
| |
| ['ooo2', '--check-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, |
| {OUT => "1\n\t\t3\n"}, |
| {ERR => "$prog: file 2 is not in sorted order\n"}], |
|
|
| |
| ['ooo3', '--nocheck-order', {IN=>{a=>"1\n3"}}, {IN=>{b=>"3\n2"}}, |
| {OUT => "1\n\t\t3\n\t2\n"}], |
|
|
| |
| ['ooo4', {IN=>{a=>"3\n1\n0"}}, {IN=>{b=>"3\n2\n0"}}, {EXIT=>1}, |
| {OUT => "\t\t3\n1\n0\n\t2\n\t0\n"}, |
| {ERR => "$prog: file 1 is not in sorted order\n". |
| "$prog: file 2 is not in sorted order\n" |
| . "$prog: input is not in sorted order\n"}], |
|
|
| |
| ['ooo5', {IN=>{a=>"3\n1"}}, {IN=>{b=>"3\n2"}}, {EXIT=>1}, |
| {OUT => "\t\t3\n1\n\t2\n"}, |
| {ERR => "$prog: file 1 is not in sorted order\n". |
| "$prog: file 2 is not in sorted order\n" |
| . "$prog: input is not in sorted order\n"}], |
|
|
| |
| ['ooo5b', {IN=>{a=>"0\n3\n1"}}, {IN=>{b=>"2\n3"}}, {EXIT=>1}, |
| {OUT => "0\n\t2\n\t\t3\n1\n"}, |
| {ERR => "$prog: file 1 is not in sorted order\n" |
| . "$prog: input is not in sorted order\n"}], |
|
|
| |
| ['ooo5c', {IN=>{a=>"0\n3"}}, {IN=>{b=>"2\n3\n1"}}, {EXIT=>1}, |
| {OUT => "0\n\t2\n\t\t3\n\t1\n"}, |
| {ERR => "$prog: file 2 is not in sorted order\n" |
| . "$prog: input is not in sorted order\n"}], |
|
|
| |
| ['ooo6', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, {EXIT=>0}, |
| {OUT => "\t\t2\n\t\t1\n\t\t0\n"}], |
|
|
| |
| ['ooo7', '--check-order', {IN=>{a=>"2\n1\n0"}}, {IN=>{b=>"2\n1\n0"}}, |
| {EXIT=>1}, |
| {OUT => "\t\t2\n"}, |
| {ERR => "$prog: file 1 is not in sorted order\n"}], |
|
|
| |
| |
| ['ooo-prefix', '--check-order', {IN=>{a=>"Xa\nX\n"}}, {IN=>{b=>""}}, |
| {EXIT=>1}, |
| {OUT => "Xa\n"}, |
| {ERR => "$prog: file 1 is not in sorted order\n"}], |
|
|
| |
| ['delim-comma', '--output-delimiter=,', @inputs, |
| {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ], |
|
|
| |
| ['delim-2char', '--output-delimiter=++', @inputs, |
| {OUT=>"1\n++2\n++2\n++++3\n++++3\n++++3\n"} ], |
|
|
| |
| ['delim-empty', '--output-delimiter=', @inputs, |
| {OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"} ], |
| ['zdelim-empty', '-z', '-z --output-delimiter=', @zinputs, |
| {OUT=>"1\000\0002\000\0002\000\000\0003\000\000\0003\000\000\0003\000"} ], |
| ['total-delim-empty', '--total --output-delimiter=', @inputs, |
| {OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n" |
| . "1\0002\0003\000total\n"} ], |
|
|
| |
| ['delim-dual', '--output-delimiter=,', '--output-delimiter=+', @inputs, |
| {EXIT=>1}, {ERR => "$prog: multiple output delimiters specified\n"}], |
|
|
| |
| ['delim-dual2', '--output-delimiter=,', '--output-delimiter=,', @inputs, |
| {OUT=>"1\n,2\n,2\n,,3\n,,3\n,,3\n"} ], |
|
|
| |
| ['totalz-all', '--total', '-z', @zinputs, |
| {OUT=>"1\000\t2\000\t2\000\t\t3\000\t\t3\000\t\t3\000" |
| . "1\t2\t3\ttotal\000"} ], |
|
|
| |
| ['totalz-123', '--total', '-z123', '--output-delimiter=,', @zinputs, |
| {OUT=>"1,2,3,total\000"} ], |
| ); |
|
|
| my $save_temps = $ENV{DEBUG}; |
| my $verbose = $ENV{VERBOSE}; |
|
|
| my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); |
| exit $fail; |
|
|