From 0205f6d1fd380413d97fcc6060c63e10d057282c Mon Sep 17 00:00:00 2001 From: brian d foy Date: Tue, 9 Jan 2024 11:17:44 -0500 Subject: [PATCH] Tests for cut (see #403) --- t/cut/cut.t | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 t/cut/cut.t diff --git a/t/cut/cut.t b/t/cut/cut.t new file mode 100644 index 00000000..1f42b680 --- /dev/null +++ b/t/cut/cut.t @@ -0,0 +1,35 @@ +use File::Spec::Functions; +use IPC::Run3 qw(run3); + +use Test::More; + +require './t/lib/common.pl'; + +my $Script = program_name(); + +compile_test($Script); +sanity_test($Script); + +# taken form Michael Mikonos's tests in https://github.com/briandfoy/PerlPowerTools/pull/403 +my @table = ( + [ "positive -b value", 'a:b:c:d', [qw( -b 3 )], "b\n" ], + [ "negative -b value", 'a:b:c:d', [qw( -b -3 )], "a:b\n" ], + [ "-b range", 'a:b:c:d', [qw( -b 2-3 )], ":b\n" ], + [ "positive -f value", 'a:b:c:d', [qw( -d : -f 2 )], "b\n" ], + [ "negative -f value", 'a:b:c:d', [qw( -d : -f -2 )], "a:b\n" ], + [ "-f range", 'a:b:c:d', [qw( -d : -f 2-3 )], "b:c\n" ], + ); + + +foreach my $tuple ( @table ) { + my( $label, $stdin, $args, $stdout ) = @$tuple; + + subtest $label => sub { + my $result = run_command( $Script, $args, $stdin ); + is( length($stdout), length($result->{stdout}), "received and expected data lengths are the same" ); + is( $result->{stdout}, $stdout, "stdout is as expected for args <@$args>" ); + is( $result->{error}, $stderr, "stderr is as expected for args <@$args>" ); + } + } + +done_testing();