]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Initial revision
authorJim Meyering <jim@meyering.net>
Thu, 27 Jul 1995 14:43:01 +0000 (14:43 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 27 Jul 1995 14:43:01 +0000 (14:43 +0000)
tests/sort/.cvsignore [new file with mode: 0644]
tests/sort/Makefile [new file with mode: 0644]
tests/sort/TODO [new file with mode: 0644]
tests/sort/build-script [new file with mode: 0755]
tests/sort/main [new file with mode: 0755]
tests/sort/test.data.pl [new file with mode: 0755]

diff --git a/tests/sort/.cvsignore b/tests/sort/.cvsignore
new file mode 100644 (file)
index 0000000..ca18a4c
--- /dev/null
@@ -0,0 +1,3 @@
+t*.out
+t*.in
+t*.exp
diff --git a/tests/sort/Makefile b/tests/sort/Makefile
new file mode 100644 (file)
index 0000000..7fc8d30
--- /dev/null
@@ -0,0 +1,19 @@
+.PHONY: all
+all: sort-tests
+       ./sort-tests
+
+sort-tests: main build-script test.data.pl
+       ./main test.data.pl > $@.n
+       mv $@.n $@
+       chmod 755 $@
+
+.PHONY: distclean
+distclean:
+       rm -f t*.out
+
+.PHONY: clean
+clean: distclean
+
+.PHONY: realclean
+realclean: clean
+       rm -f sort-tests t*.in t*.exp t*.err
diff --git a/tests/sort/TODO b/tests/sort/TODO
new file mode 100644 (file)
index 0000000..e1cffb7
--- /dev/null
@@ -0,0 +1 @@
+Integrate tests from the files `range-tests' and `failures'.
diff --git a/tests/sort/build-script b/tests/sort/build-script
new file mode 100755 (executable)
index 0000000..230a3fa
--- /dev/null
@@ -0,0 +1,64 @@
+#!/p/bin/perl -w
+
+$sort = './sort';
+$test = 0;
+$| = 1;
+
+print "#! /bin/sh\nsort='$sort'\necho testing with sort=\$sort\nerrors=0\n";
+$expected = '';
+$input = '';
+$options = '';
+
+while (<>)
+  {
+    next if (/^\s*#/);
+
+    $test++;
+    chop;
+    $prog = '($test_name, $options,$input,$expected,$e_ret_code) = ' . $_ . ';';
+    eval $prog;
+    if (defined ($seen{$test_name}))
+      {
+       die "$0: $.: duplicate test name \`$test_name'\n";
+      }
+    $seen{$test_name} = 1;
+    $in = "t$test_name.in";
+    $exp_name = 't' . $test_name . '.exp';
+    $out = "t$test_name.out";
+
+    open(IN, ">$in") || die "Couldn't open $in for writing.\n";
+    print IN $input;
+    close(IN);
+    open(EXP, ">$exp_name")
+       || die "Couldn't open $exp_name for writing.\n";
+    print EXP $expected;
+    close(EXP);
+    $err_output = "t$test_name.err";
+    $cmd = "\$sort $options $in > $out 2> $err_output";
+    print <<EOF ;
+$cmd
+code=\$?
+if test \$code != $e_ret_code ; then
+  echo Test $test_name failed: sort 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;
+       errors=`expr \$errors + 1` ;;
+    2) echo Test $test_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
+  }
+print <<EOF2 ;
+if test \$errors = 0 ; then
+  echo Passed all tests. 1>&2
+else
+  echo Failed \$errors tests. 1>&2
+fi
+EOF2
diff --git a/tests/sort/main b/tests/sort/main
new file mode 100755 (executable)
index 0000000..dd2da71
--- /dev/null
@@ -0,0 +1,3 @@
+:
+perl -pe 's/\\\n$//' "$@" \
+    | ./build-script
diff --git a/tests/sort/test.data.pl b/tests/sort/test.data.pl
new file mode 100755 (executable)
index 0000000..9b3c57a
--- /dev/null
@@ -0,0 +1,25 @@
+#test   options   input   expected-output   return-code
+#
+("1a", '', "A\nB\nC\n", "A\nB\nC\n", 0);
+#
+("2a", '-c', "A\nB\nC\n", '', 0);
+("2b", '-c', "A\nC\nB\n", '', 1);
+# This should fail because there are duplicate keys
+("2c", '-cu', "A\nA\n", '', 1);
+("2d", '-cu', "A\nB\n", '', 0);
+("2e", '-cu', "A\nB\nB\n", '', 1);
+("2f", '-cu', "B\nA\nB\n", '', 1);
+#
+("3a", '-k1', "B\nA\n", "A\nB\n",  0);
+("3b", '-k1,1', "B\nA\n", "A\nB\n",  0);
+("3c", '-k1 -k2', "A b\nA a\n", "A a\nA b\n",  0);
+# FIXME: fail with a diagnostic when -k specifies field == 0
+("3d", '-k0', "", "",  1);
+# FIXME: fail with a diagnostic when -k specifies character == 0
+("3e", '-k1.0', "", "",  1);
+#
+("4a", '-nc', "2\n11\n", "",  0);
+("4b", '-n', "11\n2\n", "2\n11\n", 0);
+("4c", '-k1n', "11\n2\n", "2\n11\n", 0);
+("4d", '-k1', "11\n2\n", "11\n2\n", 0);
+("4e", '-k2', "ignored B\nz-ig A\n", "z-ig A\nignored B\n", 0);