]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Interpret `input arg is a hash
authorJim Meyering <jim@meyering.net>
Sun, 26 Jan 1997 03:12:41 +0000 (03:12 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 26 Jan 1997 03:12:41 +0000 (03:12 +0000)
reference' as meaning that the tested program will read no input.
Most of the tests for the date program use this feature.
Also for date, the generated script now reflects specification
(in Test.pm) of default and per-test environment settings.

tests/cut/mk-script.pl
tests/head/mk-script.pl
tests/join/mk-script.pl
tests/ls/mk-script.pl

index 60a90d5b063f680602603112da88260dd6b52573..ded89142165c15e8ef0729f7aa3802dbacfd370d 100644 (file)
@@ -37,6 +37,7 @@ sub validate
 # the top level variable to the actual string literal.
 # If $SPEC is a literal Perl string (not a reference), then treat $SPEC
 # as the contents of a file.
+# If $SPEC is a hash reference, then there are no inputs.
 # If $SPEC is an array reference, consider each element of the array.
 # If the element is a string reference, treat the string as the name of
 # an existing file.  Otherwise, the element must be a string and is treated
@@ -58,9 +59,20 @@ sub spec_to_list ($$$)
   my @explicit_file;
   my @maint_gen_file;
   my @content_string;
+
+  # If SPEC is a hash reference, return empty lists.
+  if (ref $spec eq 'HASH')
+    {
+      assert ($type eq 'in');
+      return {
+       EXPLICIT => \@explicit_file,
+       MAINT_GEN => \@maint_gen_file
+       };
+    }
+
   if (ref $spec)
     {
-      assert (ref $spec eq 'ARRAY');
+      assert (ref $spec eq 'ARRAY' || ref $spec eq 'HASH');
       my $file_spec;
       foreach $file_spec (@$spec)
        {
@@ -225,27 +237,34 @@ foreach $test_vector (Test::test_vector ())
                        ? '< ' : '');
   my $z = $Test::common_option_prefix if defined $Test::common_option_prefix;
   $z ||= '';
+  my $env = $Test::env{$test_name} || $Test::default_env || [''];
   my $cmd = "\$xx $z$flags $redirect_stdin" . join (' ', @srcdir_rel_in_file)
     . " > $out 2> $err_output";
-  print <<EOF;
-$cmd
+  my $e;
+  foreach $e (@$env)
+    {
+      my $t_name = ($e ? "$test_name($e)" : $test_name);
+      my $e_cmd = ($e ? "$e " : '');
+      print <<EOF;
+$e_cmd$cmd
 code=\$?
 if test \$code != $e_ret_code ; then
-  \$echo Test $test_name failed: $xx return code \$code differs from expected value $e_ret_code 1>&2
+  \$echo "Test $t_name failed: $xx return code \$code differs from expected value $e_ret_code" 1>&2
   errors=`expr \$errors + 1`
 else
   cmp $out $exp_name
   case \$? in
-    0) if test "\$VERBOSE" ; then \$echo passed $test_name; fi ;; # equal files
-    1) \$echo Test $test_name failed: files $out and $exp_name differ 1>&2;
+    0) if test "\$VERBOSE" ; then \$echo "passed $t_name"; fi ;;
+    1) \$echo "Test $t_name failed: files $out and $exp_name differ" 1>&2;
        errors=`expr \$errors + 1` ;;
-    2) \$echo Test $test_name may have failed. 1>&2;
+    2) \$echo "Test $t_name may have failed." 1>&2;
        \$echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
        errors=`expr \$errors + 1` ;;
   esac
 fi
 test -s $err_output || rm -f $err_output
 EOF
+    }
   }
 my $n_tests = Test::test_vector ();
 print <<EOF2 ;
index 60a90d5b063f680602603112da88260dd6b52573..ded89142165c15e8ef0729f7aa3802dbacfd370d 100644 (file)
@@ -37,6 +37,7 @@ sub validate
 # the top level variable to the actual string literal.
 # If $SPEC is a literal Perl string (not a reference), then treat $SPEC
 # as the contents of a file.
+# If $SPEC is a hash reference, then there are no inputs.
 # If $SPEC is an array reference, consider each element of the array.
 # If the element is a string reference, treat the string as the name of
 # an existing file.  Otherwise, the element must be a string and is treated
@@ -58,9 +59,20 @@ sub spec_to_list ($$$)
   my @explicit_file;
   my @maint_gen_file;
   my @content_string;
+
+  # If SPEC is a hash reference, return empty lists.
+  if (ref $spec eq 'HASH')
+    {
+      assert ($type eq 'in');
+      return {
+       EXPLICIT => \@explicit_file,
+       MAINT_GEN => \@maint_gen_file
+       };
+    }
+
   if (ref $spec)
     {
-      assert (ref $spec eq 'ARRAY');
+      assert (ref $spec eq 'ARRAY' || ref $spec eq 'HASH');
       my $file_spec;
       foreach $file_spec (@$spec)
        {
@@ -225,27 +237,34 @@ foreach $test_vector (Test::test_vector ())
                        ? '< ' : '');
   my $z = $Test::common_option_prefix if defined $Test::common_option_prefix;
   $z ||= '';
+  my $env = $Test::env{$test_name} || $Test::default_env || [''];
   my $cmd = "\$xx $z$flags $redirect_stdin" . join (' ', @srcdir_rel_in_file)
     . " > $out 2> $err_output";
-  print <<EOF;
-$cmd
+  my $e;
+  foreach $e (@$env)
+    {
+      my $t_name = ($e ? "$test_name($e)" : $test_name);
+      my $e_cmd = ($e ? "$e " : '');
+      print <<EOF;
+$e_cmd$cmd
 code=\$?
 if test \$code != $e_ret_code ; then
-  \$echo Test $test_name failed: $xx return code \$code differs from expected value $e_ret_code 1>&2
+  \$echo "Test $t_name failed: $xx return code \$code differs from expected value $e_ret_code" 1>&2
   errors=`expr \$errors + 1`
 else
   cmp $out $exp_name
   case \$? in
-    0) if test "\$VERBOSE" ; then \$echo passed $test_name; fi ;; # equal files
-    1) \$echo Test $test_name failed: files $out and $exp_name differ 1>&2;
+    0) if test "\$VERBOSE" ; then \$echo "passed $t_name"; fi ;;
+    1) \$echo "Test $t_name failed: files $out and $exp_name differ" 1>&2;
        errors=`expr \$errors + 1` ;;
-    2) \$echo Test $test_name may have failed. 1>&2;
+    2) \$echo "Test $t_name may have failed." 1>&2;
        \$echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
        errors=`expr \$errors + 1` ;;
   esac
 fi
 test -s $err_output || rm -f $err_output
 EOF
+    }
   }
 my $n_tests = Test::test_vector ();
 print <<EOF2 ;
index 60a90d5b063f680602603112da88260dd6b52573..ded89142165c15e8ef0729f7aa3802dbacfd370d 100644 (file)
@@ -37,6 +37,7 @@ sub validate
 # the top level variable to the actual string literal.
 # If $SPEC is a literal Perl string (not a reference), then treat $SPEC
 # as the contents of a file.
+# If $SPEC is a hash reference, then there are no inputs.
 # If $SPEC is an array reference, consider each element of the array.
 # If the element is a string reference, treat the string as the name of
 # an existing file.  Otherwise, the element must be a string and is treated
@@ -58,9 +59,20 @@ sub spec_to_list ($$$)
   my @explicit_file;
   my @maint_gen_file;
   my @content_string;
+
+  # If SPEC is a hash reference, return empty lists.
+  if (ref $spec eq 'HASH')
+    {
+      assert ($type eq 'in');
+      return {
+       EXPLICIT => \@explicit_file,
+       MAINT_GEN => \@maint_gen_file
+       };
+    }
+
   if (ref $spec)
     {
-      assert (ref $spec eq 'ARRAY');
+      assert (ref $spec eq 'ARRAY' || ref $spec eq 'HASH');
       my $file_spec;
       foreach $file_spec (@$spec)
        {
@@ -225,27 +237,34 @@ foreach $test_vector (Test::test_vector ())
                        ? '< ' : '');
   my $z = $Test::common_option_prefix if defined $Test::common_option_prefix;
   $z ||= '';
+  my $env = $Test::env{$test_name} || $Test::default_env || [''];
   my $cmd = "\$xx $z$flags $redirect_stdin" . join (' ', @srcdir_rel_in_file)
     . " > $out 2> $err_output";
-  print <<EOF;
-$cmd
+  my $e;
+  foreach $e (@$env)
+    {
+      my $t_name = ($e ? "$test_name($e)" : $test_name);
+      my $e_cmd = ($e ? "$e " : '');
+      print <<EOF;
+$e_cmd$cmd
 code=\$?
 if test \$code != $e_ret_code ; then
-  \$echo Test $test_name failed: $xx return code \$code differs from expected value $e_ret_code 1>&2
+  \$echo "Test $t_name failed: $xx return code \$code differs from expected value $e_ret_code" 1>&2
   errors=`expr \$errors + 1`
 else
   cmp $out $exp_name
   case \$? in
-    0) if test "\$VERBOSE" ; then \$echo passed $test_name; fi ;; # equal files
-    1) \$echo Test $test_name failed: files $out and $exp_name differ 1>&2;
+    0) if test "\$VERBOSE" ; then \$echo "passed $t_name"; fi ;;
+    1) \$echo "Test $t_name failed: files $out and $exp_name differ" 1>&2;
        errors=`expr \$errors + 1` ;;
-    2) \$echo Test $test_name may have failed. 1>&2;
+    2) \$echo "Test $t_name may have failed." 1>&2;
        \$echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
        errors=`expr \$errors + 1` ;;
   esac
 fi
 test -s $err_output || rm -f $err_output
 EOF
+    }
   }
 my $n_tests = Test::test_vector ();
 print <<EOF2 ;
index 60a90d5b063f680602603112da88260dd6b52573..ded89142165c15e8ef0729f7aa3802dbacfd370d 100644 (file)
@@ -37,6 +37,7 @@ sub validate
 # the top level variable to the actual string literal.
 # If $SPEC is a literal Perl string (not a reference), then treat $SPEC
 # as the contents of a file.
+# If $SPEC is a hash reference, then there are no inputs.
 # If $SPEC is an array reference, consider each element of the array.
 # If the element is a string reference, treat the string as the name of
 # an existing file.  Otherwise, the element must be a string and is treated
@@ -58,9 +59,20 @@ sub spec_to_list ($$$)
   my @explicit_file;
   my @maint_gen_file;
   my @content_string;
+
+  # If SPEC is a hash reference, return empty lists.
+  if (ref $spec eq 'HASH')
+    {
+      assert ($type eq 'in');
+      return {
+       EXPLICIT => \@explicit_file,
+       MAINT_GEN => \@maint_gen_file
+       };
+    }
+
   if (ref $spec)
     {
-      assert (ref $spec eq 'ARRAY');
+      assert (ref $spec eq 'ARRAY' || ref $spec eq 'HASH');
       my $file_spec;
       foreach $file_spec (@$spec)
        {
@@ -225,27 +237,34 @@ foreach $test_vector (Test::test_vector ())
                        ? '< ' : '');
   my $z = $Test::common_option_prefix if defined $Test::common_option_prefix;
   $z ||= '';
+  my $env = $Test::env{$test_name} || $Test::default_env || [''];
   my $cmd = "\$xx $z$flags $redirect_stdin" . join (' ', @srcdir_rel_in_file)
     . " > $out 2> $err_output";
-  print <<EOF;
-$cmd
+  my $e;
+  foreach $e (@$env)
+    {
+      my $t_name = ($e ? "$test_name($e)" : $test_name);
+      my $e_cmd = ($e ? "$e " : '');
+      print <<EOF;
+$e_cmd$cmd
 code=\$?
 if test \$code != $e_ret_code ; then
-  \$echo Test $test_name failed: $xx return code \$code differs from expected value $e_ret_code 1>&2
+  \$echo "Test $t_name failed: $xx return code \$code differs from expected value $e_ret_code" 1>&2
   errors=`expr \$errors + 1`
 else
   cmp $out $exp_name
   case \$? in
-    0) if test "\$VERBOSE" ; then \$echo passed $test_name; fi ;; # equal files
-    1) \$echo Test $test_name failed: files $out and $exp_name differ 1>&2;
+    0) if test "\$VERBOSE" ; then \$echo "passed $t_name"; fi ;;
+    1) \$echo "Test $t_name failed: files $out and $exp_name differ" 1>&2;
        errors=`expr \$errors + 1` ;;
-    2) \$echo Test $test_name may have failed. 1>&2;
+    2) \$echo "Test $t_name may have failed." 1>&2;
        \$echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
        errors=`expr \$errors + 1` ;;
   esac
 fi
 test -s $err_output || rm -f $err_output
 EOF
+    }
   }
 my $n_tests = Test::test_vector ();
 print <<EOF2 ;