Initial revision
authorJim Meyering <jim@meyering.net>
Mon, 7 Nov 1994 12:47:50 +0000 (12:47 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 7 Nov 1994 12:47:50 +0000 (12:47 +0000)
tests/join/.cvsignore [new file with mode: 0644]
tests/join/Makefile [new file with mode: 0644]
tests/join/TODO [new file with mode: 0644]
tests/join/build-script [new file with mode: 0755]
tests/join/failures [new file with mode: 0644]
tests/join/main [new file with mode: 0755]
tests/join/range-tests [new file with mode: 0644]
tests/join/test.data.pl [new file with mode: 0755]

diff --git a/tests/join/.cvsignore b/tests/join/.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/join/Makefile b/tests/join/Makefile
new file mode 100644 (file)
index 0000000..391f1a0
--- /dev/null
@@ -0,0 +1,19 @@
+.PHONY: all
+all: tr-tests
+       ./tr-tests
+
+tr-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 tr-tests t*.in t*.exp
diff --git a/tests/join/TODO b/tests/join/TODO
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/join/build-script b/tests/join/build-script
new file mode 100755 (executable)
index 0000000..ab064d5
--- /dev/null
@@ -0,0 +1,59 @@
+#!/p/bin/perl5.000 -w
+
+$tr = '../tr +io 5';
+$tr = 'tr';
+$test = 0;
+$| = 1;
+
+print ":\nerrors=0\n";
+$expected = '';
+$s1 = '';
+$input = '';
+$flags = '';
+$s1 = '';
+
+while (<>)
+  {
+    next if (/^\s*#/);
+
+    $test++;
+    chop;
+    $prog = '($test_name, $input,$flags,$s1,$s2,$expected,$e_ret_code) = ' . $_ . ';';
+    eval $prog;
+    $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);
+    $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_name 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_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
+EOF
+  }
+print <<EOF2 ;
+if test \$errors -gt 0 ; then
+  echo Failed \$errors tests. 1>&2
+fi
+EOF2
diff --git a/tests/join/failures b/tests/join/failures
new file mode 100644 (file)
index 0000000..defc474
--- /dev/null
@@ -0,0 +1,19 @@
+# ./tr a '[c*]b'
+# ./tr -s abc zy
+# ./tr abc zy
+tr a '[:not-a-class:]' < /dev/null
+tr a '[:digit:]' < /dev/null
+tr '[c*]' k < /dev/null
+tr a '[=c=]' < /dev/null
+tr a '[c*][c*]' < /dev/null
+tr -ds abd '[c*]' < /dev/null
+tr -c '[:lower:]' '[:upper:]' < /dev/null
+tr '[:lower:]' '[:lower:]' < /dev/null
+tr '0-9[:lower:]' '[:upper:]' < /dev/null
+tr a '' < /dev/null
+tr -s '\432' < /dev/null
+tr a 'abc\' < /dev/null
+tr a '\x' < /dev/null
+tr -s < /dev/null
+
+# And make sure tr does the right thing when POSIXLY_... is set.
diff --git a/tests/join/main b/tests/join/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/join/range-tests b/tests/join/range-tests
new file mode 100644 (file)
index 0000000..d13d472
--- /dev/null
@@ -0,0 +1,18 @@
+[]*]     # What about this?!  valid
+[:*096]  # invalid: 096 isn't a valid octal number
+a [:*0]  # as many colons as string1 was long (not to be confused
+        # with a character class)
+[:*]     # ditto
+[:*016]  # 14 colons
+[=]=]    # valid: equivalence class containing ']'
+[-a      # valid, assuming `[' is before 'a' in collating sequence
+ -]      # valid, assuming ` ' is before ']' in collating sequence
+--]      # valid, assuming `-' is before ']' in collating sequence
+\0-\377  # valid
+[\0-\377]# valid, (but brackets will be mapped to corresponding chars
+        # in other string)
+abcde[:* # valid, but none of the characters is considered special
+abc xyzdef # Should this (str2 longer than str1) evoke a warning?
+           # Probably so if we're only translating, but if also deleting or
+          # squeezing this makes sense.
+abcdef : # Map abcdef all to `:', as if str2 had been [:*]
diff --git a/tests/join/test.data.pl b/tests/join/test.data.pl
new file mode 100755 (executable)
index 0000000..35322ca
--- /dev/null
@@ -0,0 +1,4 @@
+# test name
+#     flags       file-1 file-2    expected output   expected return code
+#
+("1", '-a1 -a2',  "a 1\n", "\n",   "a 1\n",              0);