[gnumeric] Tests: better command line quoting.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Tests: better command line quoting.
- Date: Sat, 27 Dec 2014 23:54:08 +0000 (UTC)
commit e039540761ca1998f28e53a83c031f3260425ec7
Author: Morten Welinder <terra gnome org>
Date: Sat Dec 27 18:53:31 2014 -0500
Tests: better command line quoting.
Including the common case of not quoting.
test/GnumericTest.pm | 47 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 04ff361..e4a1c4e 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -167,7 +167,7 @@ sub sstest {
my $test = shift @_;
my $expected = shift @_;
- my $cmd = "$sstest $test";
+ my $cmd = "earg ($sstest, $test);
my $actual = `$cmd 2>&1`;
my $err = $?;
die "Failed command: $cmd\n" if $err;
@@ -229,9 +229,7 @@ sub test_sheet_calc {
$tmp =~ s/\.[a-zA-Z0-9]+$/.csv/;
&junkfile ($tmp);
- my $cmd = "$ssconvert " .
- join (" ", @$pargs) .
- " --recalc --export-range='$range' '$file' '$tmp'";
+ my $cmd = "$ssconvert " . "earg (@$pargs, '--recalc', "--export-range=$range", $file, $tmp);
print STDERR "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /' ");
&system_failure ($ssconvert, $code) if $code;
@@ -349,7 +347,7 @@ sub test_exporter {
my $tmp1 = "$tmp.gnumeric";
&junkfile ($tmp1) unless $keep;
{
- my $cmd = "$ssconvert '$file' '$tmp1'";
+ my $cmd = "earg ($ssconvert, $file, $tmp1);
print STDERR "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -358,7 +356,7 @@ sub test_exporter {
my $tmp2 = "$tmp-new.$ext";
&junkfile ($tmp2) unless $keep;
{
- my $cmd = "$ssconvert '$file' '$tmp2'";
+ my $cmd = "earg ($ssconvert, $file, $tmp2);
print STDERR "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -367,7 +365,7 @@ sub test_exporter {
my $tmp3 = "$tmp-new.gnumeric";
&junkfile ($tmp3) unless $keep;
{
- my $cmd = "$ssconvert '$tmp2' '$tmp3'";
+ my $cmd = "earg ($ssconvert, $tmp2, $tmp3);
print STDERR "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -375,12 +373,12 @@ sub test_exporter {
my $tmp4 = "$tmp.xml";
&junkfile ($tmp4) unless $keep;
- $code = system ("zcat -f '$tmp1' >'$tmp4'");
+ $code = system ("earg ("zcat", "-f", $tmp1) . " >" . "earg ($tmp4));
&system_failure ('zcat', $code) if $code;
my $tmp5 = "$tmp-new.xml";
&junkfile ($tmp5) unless $keep;
- $code = system ("zcat -f '$tmp3' >'$tmp5'");
+ $code = system ("earg ("zcat" , "-f", $tmp3) . " >" . "earg ($tmp5));
&system_failure ('zcat', $code) if $code;
$code = system ('diff', '-u', $tmp4, $tmp5);
@@ -449,7 +447,7 @@ sub test_roundtrip {
$file_resized =~ s{^.*/}{};
$file_resized =~ s/(\.gnumeric)$/-resize$1/;
unlink $file_resized;
- my $cmd = "$ssconvert --resize $resize '$file' '$file_resized'";
+ my $cmd = "earg ($ssconvert, "--resize", $resize, $file, $file_resized);
print STDERR "# $cmd\n" if $verbose;
$code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -461,7 +459,7 @@ sub test_roundtrip {
unlink $tmp1;
&junkfile ($tmp1) unless $keep;
{
- my $cmd = "$ssconvert -T $format '$file_resized' '$tmp1'";
+ my $cmd = "earg ($ssconvert, "-T", $format, $file_resized, $tmp1);
print "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -472,7 +470,7 @@ sub test_roundtrip {
unlink $tmp2;
&junkfile ($tmp2) unless $keep;
{
- my $cmd = "$ssconvert '$tmp1' '$tmp2'";
+ my $cmd = "earg ($ssconvert, $tmp1, $tmp2);
print "# $cmd\n" if $verbose;
my $code = system ("$cmd 2>&1 | sed -e 's/^/| /'");
&system_failure ($ssconvert, $code) if $code;
@@ -582,7 +580,7 @@ sub test_ssindex {
&junkfile ($xmlfile);
{
- my $cmd = "$ssindex --index '$file'";
+ my $cmd = "earg ($ssindex, "--index", $file);
my $output = `$cmd 2>&1 >'$xmlfile'`;
my $err = $?;
&dump_indented ($output);
@@ -630,6 +628,29 @@ sub test_ssindex {
# -----------------------------------------------------------------------------
+sub quotearg {
+ return join (' ', map { "earg1 ($_) } @_);
+}
+
+sub quotearg1 {
+ my ($arg) = @_;
+
+ return "''" if $arg eq '';
+ my $res = '';
+ while ($arg ne '') {
+ if ($arg =~ m!^([-=/._a-zA-Z0-9]+)!) {
+ $res .= $1;
+ $arg = substr ($arg, length $1);
+ } else {
+ $res .= "\\" . substr ($arg, 0, 1);
+ $arg = substr ($arg, 1);
+ }
+ }
+ return $res;
+}
+
+# -----------------------------------------------------------------------------
+
sub report_skip {
my ($txt) = @_;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]