]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Initial revision
authorJim Meyering <jim@meyering.net>
Tue, 2 Mar 1993 14:10:31 +0000 (14:10 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 2 Mar 1993 14:10:31 +0000 (14:10 +0000)
tests/tr/Makefile [new file with mode: 0644]
tests/tr/build-script [new file with mode: 0755]
tests/tr/main [new file with mode: 0755]
tests/tr/test.data.pl [new file with mode: 0755]

diff --git a/tests/tr/Makefile b/tests/tr/Makefile
new file mode 100644 (file)
index 0000000..e3dd9be
--- /dev/null
@@ -0,0 +1,16 @@
+all: tr-tests
+       ./tr-tests
+.PHONY: all
+
+tr-tests: main build-script test.data.pl
+       ./main test.data.pl > .tmp-$@
+       mv .tmp-$@ $@
+       chmod 755 $@
+
+clean:
+       rm -f t[0-9]*.out
+.PHONY: clean
+
+realclean:
+       rm -f tr-tests t[0-9]*.in t[0-9]*.expected
+.PHONY: realclean
diff --git a/tests/tr/build-script b/tests/tr/build-script
new file mode 100755 (executable)
index 0000000..a6df348
--- /dev/null
@@ -0,0 +1,55 @@
+#!/p/bin/perl
+
+$tr = '../tr +io 5';
+$tr = 'tr';
+$test = 0;
+$failures = 0;
+$| = 1;
+
+print ":\nerrors=0\n";
+
+while (<>)
+  {
+    next if (/^\s*#/);
+
+    $test++;
+    chop;
+    $prog = '($input,$flags,$s1,$s2,$expected,$e_ret_code) = ' . $_ . ';';
+    eval $prog;
+    $in = "t$test.in"; 
+    $exp_name = 't' . $test . '.expected'; 
+    $out = "t$test.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);
+    $arg2 = ($s2 ? "'$s2'" : '');
+    $cmd = "$tr $flags \'$s1\' $arg2 < $in > $out";
+    print <<EOF ;
+$cmd 2> /dev/null
+code=\$?
+if test \$code != $e_ret_code ; then
+  echo Test $test failed: tr 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; fi ;; # equal files
+    1) echo Test $test failed: files $out and $exp_name differ 1>&2;
+       errors=`expr \$errors + 1` ;;
+    2) echo Test $test may have failed. 1>&2;
+       echo The command \"cmp $out $exp_name\" failed. 1>&2 ;
+       errors=`expr \$errors + 1` ;;
+  esac
+fi
+EOF
+  }
+print <<EOF2 ;
+if test \$errors -gt 0 ; then
+  echo Failed \$errors tests. 1>&2
+fi
+EOF2
diff --git a/tests/tr/main b/tests/tr/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/tr/test.data.pl b/tests/tr/test.data.pl
new file mode 100755 (executable)
index 0000000..8082b5b
--- /dev/null
@@ -0,0 +1,61 @@
+# input flags  1 or 2 strings      expected output   expected return code
+#
+("abcd",   '',    'abcd','[]*]',   "]]]]",              0);
+("abc",    '',    'abc','[%*]xyz',  "xyz",              0);
+("abc",    '',    '','[.*]',        "abc",              0);
+# Test --truncate-set1 behavior when string1 is longer than string2
+("abcde", '-t',   'abcd','xy',     "xycde",            0);
+# Test bsd behavior (the default) when string1 is longer than string2
+("abcde", '',      'abcd','xy',     "xyyye",            0);
+# Do it the posix way
+("abcde", '',      'abcd','x[y*]',  "xyyye",            0);
+#
+("abcdefghijklmnop", '-s', 'a-p','%[.*]$', "%.$",       0);
+("abcdefghijklmnop", '-s', 'a-p','[.*]$', ".$",         0);
+("abcdefghijklmnop", '-s', 'a-p','%[.*]', "%.",         0);
+("aabbcc", '-s', '[a-z]','',        "abc",              0);
+("aabbcc", '-s', '[a-c]','',        "abc",              0);
+("aabbcc", '-s', '[a-b]','',        "abcc",             0);
+("aabbcc", '-s', '[b-c]','',        "aabc",             0);
+("\0\0a\1\1b\2\2\2c\3\3\3d\4\4\4\4e\5\5", \
+          '-s',    '[\0-\5]','', "\0a\1b\2c\3d\4e\5",  0);
+# tests of delete
+("[[[[[[[]]]]]]]]", '-d', '[=[=]','', "]]]]]]]]", 0);
+("[[[[[[[]]]]]]]]", '-d', '[=]=]','', "[[[[[[[", 0);
+("0123456789acbdefABCDEF", '-d', '[:xdigit:]','', "", 0);
+("w0x1y2z3456789acbdefABCDEFz", '-d', '[:xdigit:]','', "wxyzz", 0);
+("0123456789", '-d', '[:digit:]','', "", 0);
+("a0b1c2d3e4f5g6h7i8j9k", '-d', '[:digit:]','', "abcdefghijk", 0);
+("abcdefghijklmnopqrstuvwxyz", '-d', '[:lower:]','', "", 0);
+("ABCDEFGHIJKLMNOPQRSTUVWXYZ", '-d', '[:upper:]','', "", 0);
+("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", \
+    '-d', '[:lower:][:upper:]','', "", 0);
+("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", \
+    '-d', '[:alpha:]','', "", 0);
+("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", \
+    '-d', '[:alnum:]','', "", 0);
+(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.", \
+    '-d', '[:alnum:]','', "..", 0);
+(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.", \
+    '-ds', '[:alnum:]','.', ".", 0);
+# The classic example, with string2 BSD-style
+("The big black fox jumped over the fence.", \
+    '-cs', '[:alnum:]','\n', \
+    "The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0);
+# The classic example, POSIX-style
+("The big black fox jumped over the fence.", \
+    '-cs', '[:alnum:]','[\n*]', \
+    "The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0);
+("aabbaa", '-ds', 'b','a',          "a",             0);
+("ZZ0123456789acbdefABCDEFZZ", \
+          '-ds', '[:xdigit:]','Z', "Z", 0);
+# Try some data with 8th bit set in case something is mistakenly sign-extended. 
+("\300\301\377\345\345\350\345", \
+          '-ds', '\350','\345', "\300\301\377\345", 0);
+("abcdefghijklmnop", '-s', 'abcdefghijklmn','[:*016]', ":op", 0);
+("abc \$code", '-d', 'a-z','', " \$", 0);
+("a.b.c \$\$\$\$code\\", '-ds', 'a-z','$.', ". \$\\", 0);
+# Make sure that a-a is accepted, even though POSIX 1001.2 says it is illegal.
+("abc",    '',  'a-a','z',         "zbc",               0);
+#
+("",       '',  'a',"''",          "",                  1);