summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-03-02 14:10:31 +0000
committerJim Meyering <jim@meyering.net>1993-03-02 14:10:31 +0000
commitd71cb4d9c702ff4bf106504f5737660123e08f33 (patch)
treea2b61b2a706269fb33c4902902af28f3764c5a55 /tests
parentd766e142eaa5a8608f2c35002a3cb6e4d667a724 (diff)
downloadcoreutils-d71cb4d9c702ff4bf106504f5737660123e08f33.tar.xz
Initial revision
Diffstat (limited to 'tests')
-rw-r--r--tests/tr/Makefile16
-rwxr-xr-xtests/tr/build-script55
-rwxr-xr-xtests/tr/main3
-rwxr-xr-xtests/tr/test.data.pl61
4 files changed, 135 insertions, 0 deletions
diff --git a/tests/tr/Makefile b/tests/tr/Makefile
new file mode 100644
index 000000000..e3dd9be08
--- /dev/null
+++ b/tests/tr/Makefile
@@ -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
index 000000000..a6df348e4
--- /dev/null
+++ b/tests/tr/build-script
@@ -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
index 000000000..dd2da71f4
--- /dev/null
+++ b/tests/tr/main
@@ -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
index 000000000..8082b5bce
--- /dev/null
+++ b/tests/tr/test.data.pl
@@ -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);