Add support for backslash escapes to args. Also, don't pass arguments through shell, and support quotes in directives of type string...
diff --git a/regress/NiHTest.pm b/regress/NiHTest.pm index 7eca20d..1dfbb51 100644 --- a/regress/NiHTest.pm +++ b/regress/NiHTest.pm
@@ -622,8 +622,29 @@ sub parse_args { my ($self, $type, $str) = @_; - - if ($type =~ m/(\s|\.\.\.$)/) { + + if ($type eq 'string...') { + my $args = []; + + while ($str ne '') { + if ($str =~ m/^\"/) { + unless ($str =~ m/^\"([^\"]*)\"\s*(.*)/) { + $self->warn_file_line("unclosed quote in [$str]"); + return undef; + } + push @$args, $1; + $str = $2; + } + else { + $str =~ m/^(\S+)\s*(.*)/; + push @$args, $1; + $str = $2; + } + } + + return $args; + } + elsif ($type =~ m/(\s|\.\.\.$)/) { my $ellipsis = 0; if ($type =~ m/(.*)\.\.\.$/) { $ellipsis = 1; @@ -706,8 +727,11 @@ } my $args = $self->parse_args($def->{type}, $argstring); - - next unless (defined($args)); + + if (!defined($args)) { + $ok = 0; + next; + } if ($def->{once}) { if (defined($test{$cmd})) { @@ -838,17 +862,37 @@ } +sub backslash_decode { + my ($str) = @_; + + if ($str =~ m/\\/) { + $str =~ s/\\a/\a/gi; + $str =~ s/\\b/\b/gi; + $str =~ s/\\f/\f/gi; + $str =~ s/\\n/\n/gi; + $str =~ s/\\r/\r/gi; + $str =~ s/\\t/\t/gi; + $str =~ s/\\v/\cK/gi; + $str =~ s/\\s/ /gi; + # TODO: \xhh, \ooo + $str =~ s/\\(.)/$1/g; + } + + return $str; +} + + sub run_program { my ($self) = @_; my ($stdin, $stdout, $stderr); $stderr = gensym; - - my $cmd = '../' . $self->{test}->{program} . " " . (join ' ', @{$self->{test}->{args}}); - + + my @cmd = ('../' . $self->{test}->{program}, map ({ backslash_decode($_); } @{$self->{test}->{args}})); + ### TODO: catch errors? - my $pid = open3($stdin, $stdout, $stderr, $cmd); + my $pid = open3($stdin, $stdout, $stderr, @cmd); $self->{stdout} = []; $self->{stderr} = [];
diff --git a/regress/open_incons.test b/regress/open_incons.test index c954bf4..3673872 100644 --- a/regress/open_incons.test +++ b/regress/open_incons.test
@@ -36,7 +36,7 @@ file incons-local-filename.zzip incons-local-filename.zip incons-local-filename.zip file incons-local-magic-bad.zzip incons-local-magic-bad.zip incons-local-magic-bad.zip file incons-local-size-larger.zzip incons-local-size-larger.zip incons-local-size-larger.zip -args -c incons-* +args -c incons-archive-comment-longer.zzip incons-archive-comment-shorter.zzip incons-cdoffset.zzip incons-central-compression-method.zzip incons-central-compsize-larger-toolarge.zzip incons-central-compsize-larger.zzip incons-central-compsize-smaller.zzip incons-central-crc.zzip incons-central-date.zzip incons-central-file-comment-longer.zzip incons-central-file-comment-shorter.zzip incons-central-magic-bad.zzip incons-central-magic-bad2.zzip incons-central-size-larger.zzip incons-data.zzip incons-ef-central-size-wrong.zzip incons-ef-local-id-size.zzip incons-ef-local-id.zzip incons-ef-local-incomplete1.zzip incons-ef-local-incomplete2.zzip incons-ef-local-incomplete3.zzip incons-ef-local-incomplete4.zzip incons-ef-local-size.zzip incons-eocd-magic-bad.zzip incons-file-count.zzip incons-local-compression-method.zzip incons-local-compsize-larger.zzip incons-local-compsize-smaller.zzip incons-local-crc.zzip incons-local-filename-long.zzip incons-local-filename-missing.zzip incons-local-filename-short.zzip incons-local-filename.zzip incons-local-magic-bad.zzip incons-local-size-larger.zzip return 1 stdout opening 'incons-archive-comment-longer.zzip' returned error 21 stdout opening 'incons-archive-comment-shorter.zzip' returned error 21
diff --git a/regress/runtest.in b/regress/runtest.in index cd1b2fc..1e1fde1 100755 --- a/regress/runtest.in +++ b/regress/runtest.in
@@ -38,6 +38,6 @@ use NiHTest; -my $test = NiHTest::new({ default_program => 'modify', srcdir => '@srcdir@', zipcmp => '../../src/zipcmp' }); +my $test = NiHTest::new({ default_program => 'modify', srcdir => '@srcdir@', zipcmp => '../../src/zipcmp', zipcmp_flags => '-p' }); $test->run(@ARGV);