* tests/scripts/options/dash-I: Use string comparison operator.
* tests/test_driver.pl (cmd2str): New method to convert a
command line to a string with proper quoting.
* tests/run_make_tests.pl (create_command): Call cmd2str() to format
the command. Add the filename/line number to the output.
# Using a ref should be preferred as it's more portable but all the older
# invocations use strings.
sub run_make_with_options {
- my ($filename,$options,$logname,$expected_code,$timeout,@call) = @_;
+ my ($filename, $options, $logname, $expected_code, $timeout, @call) = @_;
@call = caller unless @call;
my $code;
my $command = create_command($options);
$command = add_options($command, $options);
}
- my $cmdstr = ref($command) ? "'".join("' '", @$command)."'" : $command;
-
- if (@call) {
- $command_string = "#$call[1]:$call[2]\n$cmdstr\n";
- } else {
- $command_string = $cmdstr;
- }
+ my $cmdstr = cmd2str($command);
+ $command_string = "# $call[1]:$call[2]:\n$cmdstr\n";
if ($valgrind) {
print VALGRIND "\n\nExecuting: $cmdstr\n";
}
if ($code != $expected_code) {
- print "Error running @make_command (expected $expected_code; got $code): $cmdstr\n";
+ print "Error running @make_command (expected $expected_code; got $code)\n$call[1]:$call[2]: $cmdstr\n";
$test_passed = 0;
- &create_file (&get_runfile, $command_string);
+ &create_file(get_runfile(), $command_string);
# If it's a SIGINT, stop here
if ($code & 127) {
print STDERR "\nCaught signal ".($code & 127)."!\n";
my $fn = undef;
foreach my $dn (split ' ', $dirs) {
# On Windows the default is "." which is bogus!
- if ($dn != '.') {
+ if ($dn ne '.') {
my @files = glob(File::Spec->catfile($dn, "*"));
if (@files) {
(undef, undef, $fn) = File::Spec->splitpath($files[0]);
}
}
+# Returns a string-ified version of cmd which is a value provided to exec()
+# so it can either be a ref of a list or a string.
+sub cmd2str
+{
+ my $cmd = $_[0];
+ if (!ref($cmd)) {
+ return $cmd;
+ }
+
+ my @c;
+ foreach (@$cmd) {
+ if (/[][#;"*?&|<>(){}\$`^~!]/) {
+ s/\'/\'\\'\'/g;
+ push @c, "'$_'";
+ } else {
+ push @c, $_;
+ }
+ }
+ return join(' ', @c);
+}
+
sub toplevel
{
# Pull in benign variables from the user's environment
sub compare_output
{
- my ($answer,$logfile) = @_;
+ my ($answer, $logfile) = @_;
my ($slurp, $answer_matched) = ('', 0);
++$tests_run;
if (! $answer_matched) {
print "DIFFERENT OUTPUT\n" if $debug;
- &create_file (&get_basefile, $answer);
- &create_file (&get_runfile, $command_string);
+ &create_file(&get_basefile, $answer);
+ &create_file(&get_runfile, $command_string);
print "\nCreating Difference File ...\n" if $debug;
# Create the difference file
my $command = "diff -c " . &get_basefile . " " . $logfile;
- &run_command_with_output(&get_difffile,$command);
+ &run_command_with_output(get_difffile(), $command);
}
return 0;
if ($vos)
{
my $code = system "++attach_default_output_hack $filename";
- $code == -2 or &error ("adoh death\n", 1);
+ $code == -2 or &error ("ado death\n", 1);
return 1;
}