diff options
author | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
---|---|---|
committer | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
commit | 378cc40b38293ffc7298c6a7ed3cd740ad79be52 (patch) | |
tree | 87bedf9adc5c88847a2e2d85963df5f94435aaf5 /t | |
parent | a4de7c03d0bdc29d9d3a18abad4ac2628182ed7b (diff) | |
download | perl-378cc40b38293ffc7298c6a7ed3cd740ad79be52.tar.gz |
perl 2.0 (no announcement message available)perl-2.0
Some of the enhancements from Perl1 included:
* New regexp routines derived from Henry Spencer's.
o Support for /(foo|bar)/.
o Support for /(foo)*/ and /(foo)+/.
o \s for whitespace, \S for non-, \d for digit, \D nondigit
* Local variables in blocks, subroutines and evals.
* Recursive subroutine calls are now supported.
* Array values may now be interpolated into lists: unlink 'foo', 'bar', @trashcan, 'tmp';
* File globbing.
* Use of <> in array contexts returns the whole file or glob list.
* New iterator for normal arrays, foreach, that allows both read and write.
* Ability to open pipe to a forked off script for secure pipes in setuid scripts.
* File inclusion via do 'foo.pl';
* More file tests, including -t to see if, for instance, stdin is a terminal. File tests now behave in a more correct manner. You can do file tests on filehandles as well as filenames. The special filetests -T and -B test a file to see if it's text or binary.
* An eof can now be used on each file of the <> input for such purposes as resetting the line numbers or appending to each file of an inplace edit.
* Assignments can now function as lvalues, so you can say things like ($HOST = $host) =~ tr/a-z/A-Z/; ($obj = $src) =~ s/\.c$/.o/;
* You can now do certain file operations with a variable which holds the name of a filehandle, e.g. open(++$incl,$includefilename); $foo = <$incl>;
* Warnings are now available (with -w) on use of uninitialized variables and on identifiers that are mentioned only once, and on reference to various undefined things.
* There is now a wait operator.
* There is now a sort operator.
* The manual is now not lying when it says that perl is generally faster than sed. I hope.
Diffstat (limited to 't')
-rw-r--r-- | t/TEST | 20 | ||||
-rw-r--r-- | t/base.cond | 2 | ||||
-rw-r--r-- | t/base.if | 2 | ||||
-rw-r--r-- | t/base.lex | 9 | ||||
-rw-r--r-- | t/base.pat | 2 | ||||
-rw-r--r-- | t/base.term | 4 | ||||
-rw-r--r-- | t/cmd.elsif | 2 | ||||
-rw-r--r-- | t/cmd.for | 28 | ||||
-rw-r--r-- | t/cmd.mod | 2 | ||||
-rw-r--r-- | t/cmd.subval | 32 | ||||
-rw-r--r-- | t/cmd.while | 2 | ||||
-rw-r--r-- | t/comp.cmdopt | 2 | ||||
-rw-r--r-- | t/comp.cpp | 2 | ||||
-rw-r--r-- | t/comp.decl | 2 | ||||
-rw-r--r-- | t/comp.multiline | 2 | ||||
-rw-r--r-- | t/comp.script | 2 | ||||
-rw-r--r-- | t/comp.term | 5 | ||||
-rw-r--r-- | t/io.argv | 4 | ||||
-rw-r--r-- | t/io.dup | 32 | ||||
-rw-r--r-- | t/io.fs | 31 | ||||
-rw-r--r-- | t/io.inplace | 2 | ||||
-rw-r--r-- | t/io.pipe | 21 | ||||
-rw-r--r-- | t/io.print | 15 | ||||
-rw-r--r-- | t/io.tell | 12 | ||||
-rw-r--r-- | t/op.append | 2 | ||||
-rw-r--r-- | t/op.auto | 11 | ||||
-rw-r--r-- | t/op.chop | 2 | ||||
-rw-r--r-- | t/op.cond | 2 | ||||
-rw-r--r-- | t/op.crypt | 12 | ||||
-rw-r--r-- | t/op.delete | 29 | ||||
-rw-r--r-- | t/op.do | 14 | ||||
-rw-r--r-- | t/op.each | 7 | ||||
-rw-r--r-- | t/op.eval | 28 | ||||
-rw-r--r-- | t/op.exec | 21 | ||||
-rw-r--r-- | t/op.exp | 2 | ||||
-rw-r--r-- | t/op.flip | 4 | ||||
-rw-r--r-- | t/op.fork | 2 | ||||
-rw-r--r-- | t/op.goto | 2 | ||||
-rw-r--r-- | t/op.int | 2 | ||||
-rw-r--r-- | t/op.join | 2 | ||||
-rw-r--r-- | t/op.list | 29 | ||||
-rw-r--r-- | t/op.magic | 31 | ||||
-rw-r--r-- | t/op.oct | 2 | ||||
-rw-r--r-- | t/op.ord | 2 | ||||
-rw-r--r-- | t/op.pat | 43 | ||||
-rw-r--r-- | t/op.push | 2 | ||||
-rw-r--r-- | t/op.regexp | 31 | ||||
-rw-r--r-- | t/op.repeat | 2 | ||||
-rw-r--r-- | t/op.sleep | 2 | ||||
-rw-r--r-- | t/op.split | 12 | ||||
-rw-r--r-- | t/op.sprintf | 2 | ||||
-rw-r--r-- | t/op.stat | 115 | ||||
-rw-r--r-- | t/op.study | 69 | ||||
-rw-r--r-- | t/op.subst | 23 | ||||
-rw-r--r-- | t/op.time | 2 | ||||
-rw-r--r-- | t/op.unshift | 2 | ||||
-rw-r--r-- | t/re_tests | 122 |
57 files changed, 748 insertions, 122 deletions
@@ -1,6 +1,6 @@ #!./perl -# $Header: TEST,v 1.0.1.1 88/01/24 03:55:39 root Exp $ +# $Header: TEST,v 2.0 88/06/05 00:11:47 root Exp $ # This is written in a peculiar style, since we're trying to avoid # most of the constructs we'll be testing for. @@ -10,6 +10,8 @@ if ($ARGV[0] eq '-v') { shift; } +chdir 't' if -f 't/TEST'; + if ($ARGV[0] eq '') { @ARGV = split(/[ \n]/,`echo base.* comp.* cmd.* io.* op.*`); } @@ -23,11 +25,14 @@ while (<config>) { } $bad = 0; while ($test = shift) { + if ($test =~ /\.orig$/) { + next; + } print "$test..."; if ($sharpbang) { - open(results,"$test|") || (print "can't run.\n"); + open(results,"./$test|") || (print "can't run.\n"); } else { - open(script,"$test") || die "Can't run $test"; + open(script,"$test") || die "Can't run $test.\n"; $_ = <script>; close(script); if (/#!..perl(.*)/) { @@ -38,6 +43,7 @@ while ($test = shift) { open(results,"./perl$switch $test|") || (print "can't run.\n"); } $ok = 0; + $next = 0; while (<results>) { if ($verbose) { print $_; @@ -65,7 +71,7 @@ while ($test = shift) { $bad = $bad + 1; $_ = $test; if (/^base/) { - die "Failed a basic test--cannot continue."; + die "Failed a basic test--cannot continue.\n"; } } } @@ -74,13 +80,13 @@ if ($bad == 0) { if ($ok) { print "All tests successful.\n"; } else { - die "FAILED--no tests were run for some reason."; + die "FAILED--no tests were run for some reason.\n"; } } else { if ($bad == 1) { - die "Failed 1 test."; + die "Failed 1 test.\n"; } else { - die "Failed $bad tests."; + die "Failed $bad tests.\n"; } } ($user,$sys,$cuser,$csys) = times; diff --git a/t/base.cond b/t/base.cond index b592b59855..201b39896e 100644 --- a/t/base.cond +++ b/t/base.cond @@ -1,6 +1,6 @@ #!./perl -# $Header: base.cond,v 1.0 87/12/18 13:11:41 root Exp $ +# $Header: base.cond,v 2.0 88/06/05 00:11:52 root Exp $ # make sure conditional operators work @@ -1,6 +1,6 @@ #!./perl -# $Header: base.if,v 1.0 87/12/18 13:11:45 root Exp $ +# $Header: base.if,v 2.0 88/06/05 00:12:02 root Exp $ print "1..2\n"; diff --git a/t/base.lex b/t/base.lex index 015f442c77..e778c72caf 100644 --- a/t/base.lex +++ b/t/base.lex @@ -1,8 +1,8 @@ #!./perl -# $Header: base.lex,v 1.0.1.1 88/01/28 10:37:00 root Exp $ +# $Header: base.lex,v 2.0 88/06/05 00:12:06 root Exp $ -print "1..6\n"; +print "1..7\n"; $ # this is the register <space> = 'x'; @@ -30,3 +30,8 @@ eval 'while (0) { eval '$foo{1} / 1;'; if (!$@) {print "ok 6\n";} else {print "not ok 6\n";} + +eval '$foo = 123+123.4+123e4+123.4E5+123.4e+5+.12;'; + +$foo = int($foo * 100 + .5); +if ($foo eq 2591024652) {print "ok 7\n";} else {print "not ok 7\n";} diff --git a/t/base.pat b/t/base.pat index d796b697fb..54591dd7fa 100644 --- a/t/base.pat +++ b/t/base.pat @@ -1,6 +1,6 @@ #!./perl -# $Header: base.pat,v 1.0 87/12/18 13:11:56 root Exp $ +# $Header: base.pat,v 2.0 88/06/05 00:12:08 root Exp $ print "1..2\n"; diff --git a/t/base.term b/t/base.term index 509454f053..eba2f6dcf6 100644 --- a/t/base.term +++ b/t/base.term @@ -1,6 +1,6 @@ #!./perl -# $Header: base.term,v 1.0 87/12/18 13:11:59 root Exp $ +# $Header: base.term,v 2.0 88/06/05 00:12:13 root Exp $ print "1..6\n"; @@ -32,5 +32,5 @@ if ($x == '1') {print "ok 4\n";} else {print "not ok 4\n";} open(try, "/dev/null") || (die "Can't open /dev/null."); if (<try> eq '') {print "ok 5\n";} else {print "not ok 5\n";} -open(try, "/etc/termcap") || (die "Can't open /etc/termcap."); +open(try, "../Makefile") || (die "Can't open ../Makefile."); if (<try> ne '') {print "ok 6\n";} else {print "not ok 6\n";} diff --git a/t/cmd.elsif b/t/cmd.elsif index 51a7641d08..3ec8b7f8fd 100644 --- a/t/cmd.elsif +++ b/t/cmd.elsif @@ -1,6 +1,6 @@ #!./perl -# $Header: cmd.elsif,v 1.0 87/12/18 13:12:02 root Exp $ +# $Header: cmd.elsif,v 2.0 88/06/05 00:12:16 root Exp $ sub foo { if ($_[0] == 1) { @@ -1,8 +1,8 @@ #!./perl -# $Header: cmd.for,v 1.0 87/12/18 13:12:05 root Exp $ +# $Header: cmd.for,v 2.0 88/06/05 00:12:19 root Exp $ -print "1..2\n"; +print "1..7\n"; for ($i = 0; $i <= 10; $i++) { $x[$i] = $i; @@ -23,3 +23,27 @@ for (;;) { last if $i++ > 10; } if ($c == 12) {print "ok 2\n";} else {print "not ok 2\n";} + +$foo = 3210; +@ary = (1,2,3,4,5); +foreach $foo (@ary) { + $foo *= 2; +} +if (join('',@ary) eq '246810') {print "ok 3\n";} else {print "not ok 3\n";} + +for (@ary) { + s/(.*)/ok $1\n/; +} + +print $ary[1]; + +# test for internal scratch array generation +# this also tests that $foo was restored to 3210 after test 3 +for (split(' ','a b c d e')) { + $foo .= $_; +} +if ($foo eq '3210abcde') {print "ok 5\n";} else {print "not ok 5\n";} + +foreach $foo (("ok 6\n","ok 7\n")) { + print $foo; +} @@ -1,6 +1,6 @@ #!./perl -# $Header: cmd.mod,v 1.0 87/12/18 13:12:09 root Exp $ +# $Header: cmd.mod,v 2.0 88/06/05 00:12:23 root Exp $ print "1..6\n"; diff --git a/t/cmd.subval b/t/cmd.subval index 2b4962f58a..490276ae05 100644 --- a/t/cmd.subval +++ b/t/cmd.subval @@ -1,6 +1,6 @@ #!./perl -# $Header: cmd.subval,v 1.0 87/12/18 13:12:12 root Exp $ +# $Header: cmd.subval,v 2.0 88/06/05 00:12:26 root Exp $ sub foo1 { 'true1'; @@ -32,7 +32,7 @@ sub foo6 { 'true2' unless $_[0]; } -print "1..12\n"; +print "1..22\n"; if (do foo1(0) eq '') {print "ok 1\n";} else {print "not ok 1\n";} if (do foo1(1) eq 'true2') {print "ok 2\n";} else {print "not ok 2\n";} @@ -48,3 +48,31 @@ if (do foo5(0) eq '') {print "ok 9\n";} else {print "not ok 9\n";} if (do foo5(1) eq 'true2') {print "ok 10\n";} else {print "not ok 10\n";} if (do foo6(0) eq 'true2') {print "ok 11\n";} else {print "not ok 11\n";} if (do foo6(1) eq '') {print "ok 12\n";} else {print "not ok 12\n";} + +# Now test to see that recursion works using a Fibonacci number generator + +sub fib { + local($arg) = @_; + local($foo); + $level++; + if ($arg <= 2) { + $foo = 1; + } + else { + $foo = do fib($arg-1) + do fib($arg-2); + } + $level--; + $foo; +} + +@good = (0,1,1,2,3,5,8,13,21,34,55,89); + +for ($i = 1; $i <= 10; $i++) { + $foo = $i + 12; + if (do fib($i) == $good[$i]) { + print "ok $foo\n"; + } + else { + print "not ok $foo\n"; + } +} diff --git a/t/cmd.while b/t/cmd.while index 585e27f708..a48318897f 100644 --- a/t/cmd.while +++ b/t/cmd.while @@ -1,6 +1,6 @@ #!./perl -# $Header: cmd.while,v 1.0 87/12/18 13:12:15 root Exp $ +# $Header: cmd.while,v 2.0 88/06/05 00:12:31 root Exp $ print "1..10\n"; diff --git a/t/comp.cmdopt b/t/comp.cmdopt index c459324fcc..48b235c387 100644 --- a/t/comp.cmdopt +++ b/t/comp.cmdopt @@ -1,6 +1,6 @@ #!./perl -# $Header: comp.cmdopt,v 1.0 87/12/18 13:12:19 root Exp $ +# $Header: comp.cmdopt,v 2.0 88/06/05 00:12:34 root Exp $ print "1..40\n"; diff --git a/t/comp.cpp b/t/comp.cpp index ee7ad73f16..d9e21fe2c1 100644 --- a/t/comp.cpp +++ b/t/comp.cpp @@ -1,6 +1,6 @@ #!./perl -P -# $Header: comp.cpp,v 1.0 87/12/18 13:12:22 root Exp $ +# $Header: comp.cpp,v 2.0 88/06/05 00:12:37 root Exp $ print "1..3\n"; diff --git a/t/comp.decl b/t/comp.decl index 649103ac14..c49f8032dd 100644 --- a/t/comp.decl +++ b/t/comp.decl @@ -1,6 +1,6 @@ #!./perl -# $Header: comp.decl,v 1.0 87/12/18 13:12:27 root Exp $ +# $Header: comp.decl,v 2.0 88/06/05 00:12:40 root Exp $ # check to see if subroutine declarations work everwhere diff --git a/t/comp.multiline b/t/comp.multiline index 9bf1be21e0..a669d4088a 100644 --- a/t/comp.multiline +++ b/t/comp.multiline @@ -1,6 +1,6 @@ #!./perl -# $Header: comp.multiline,v 1.0 87/12/18 13:12:31 root Exp $ +# $Header: comp.multiline,v 2.0 88/06/05 00:12:44 root Exp $ print "1..5\n"; diff --git a/t/comp.script b/t/comp.script index 0364d1901d..5a537aadba 100644 --- a/t/comp.script +++ b/t/comp.script @@ -1,6 +1,6 @@ #!./perl -# $Header: comp.script,v 1.0 87/12/18 13:12:36 root Exp $ +# $Header: comp.script,v 2.0 88/06/05 00:12:49 root Exp $ print "1..3\n"; diff --git a/t/comp.term b/t/comp.term index 83cce45cbd..497b8042c3 100644 --- a/t/comp.term +++ b/t/comp.term @@ -1,10 +1,10 @@ #!./perl -# $Header: comp.term,v 1.0 87/12/18 13:12:40 root Exp $ +# $Header: comp.term,v 2.0 88/06/05 00:12:52 root Exp $ # tests that aren't important enough for base.term -print "1..9\n"; +print "1..10\n"; $x = "\\n"; print "#1\t:$x: eq " . ':\n:' . "\n"; @@ -24,4 +24,5 @@ if (length("$one\\n") == 3) {print "ok 6\n";} else {print "not ok 6\n";} if (length("$one\\\n") == 3) {print "ok 7\n";} else {print "not ok 7\n";} if (length("\\n$one") == 3) {print "ok 8\n";} else {print "not ok 8\n";} if (length("\\\n$one") == 3) {print "ok 9\n";} else {print "not ok 9\n";} +if (length("\\${one}") == 2) {print "ok 10\n";} else {print "not ok 10\n";} @@ -1,6 +1,6 @@ #!./perl -# $Header: io.argv,v 1.0 87/12/18 13:12:44 root Exp $ +# $Header: io.argv,v 2.0 88/06/05 00:12:55 root Exp $ print "1..5\n"; @@ -23,7 +23,7 @@ if ($x eq "foo\n") {print "ok 3\n";} else {print "not ok 3\n";} @ARGV = ('Io.argv.tmp', 'Io.argv.tmp', '/dev/null', 'Io.argv.tmp'); while (<>) { $y .= $. . $_; - if (eof) { + if (eof()) { if ($. == 3) {print "ok 4\n";} else {print "not ok 4\n";} } } diff --git a/t/io.dup b/t/io.dup new file mode 100644 index 0000000000..6f35892e8a --- /dev/null +++ b/t/io.dup @@ -0,0 +1,32 @@ +#!./perl + +# $Header: io.dup,v 2.0 88/06/05 00:12:57 root Exp $ + +print "1..6\n"; + +print "ok 1\n"; + +open(dupout,">&stdout"); +open(duperr,">&stderr"); + +open(stdout,">Io.dup") || die "Can't open stdout"; +open(stderr,">&stdout") || die "Can't open stderr"; + +select(stderr); $| = 1; +select(stdout); $| = 1; + +print stdout "ok 2\n"; +print stderr "ok 3\n"; +system 'echo ok 4'; +system 'echo ok 5 1>&2'; + +close(stdout); +close(stderr); + +open(stdout,">&dupout"); +open(stderr,">&duperr"); + +system 'cat Io.dup'; +unlink 'Io.dup'; + +print stdout "ok 6\n"; @@ -1,10 +1,14 @@ #!./perl -# $Header: io.fs,v 1.0 87/12/18 13:12:48 root Exp $ +# $Header: io.fs,v 2.0 88/06/05 00:12:59 root Exp $ -print "1..18\n"; +print "1..22\n"; -chdir '/tmp'; +$wd = `pwd`; +chop($wd); + +`rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`; +chdir './tmp'; `/bin/rm -rf a b c x`; umask(022); @@ -52,12 +56,27 @@ if (rename('a','b')) {print "ok 14\n";} else {print "not ok 14\n";} ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat('a'); if ($ino == 0) {print "ok 15\n";} else {print "not ok 15\n";} +$foo = (utime 0,1,'b'); +if ($foo == 1) {print "ok 16\n";} else {print "not ok 16 $foo\n";} ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat('b'); -if ($ino) {print "ok 16\n";} else {print "not ok 16\n";} +if ($ino) {print "ok 17\n";} else {print "not ok 17\n";} +if ($atime == 0 && $mtime == 1) {print "ok 18\n";} else {print "not ok 18 $atime $mtime\n";} -if ((unlink 'b') == 1) {print "ok 17\n";} else {print "not ok 17\n";} +if ((unlink 'b') == 1) {print "ok 19\n";} else {print "not ok 19\n";} ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks) = stat('b'); -if ($ino == 0) {print "ok 18\n";} else {print "not ok 18\n";} +if ($ino == 0) {print "ok 20\n";} else {print "not ok 20\n";} +unlink 'c'; + +chdir $wd || die "Can't cd back to $wd"; + unlink 'c'; +if (`ls -l perl 2>/dev/null` =~ /^l.*->/) { # we have symbolic links + if (symlink("TEST","c")) {print "ok 21\n";} else {print "not ok 21\n";} + $foo = `grep perl c`; + if ($foo) {print "ok 22\n";} else {print "not ok 22\n";} +} +else { + print "ok 21\nok 22\n"; +} diff --git a/t/io.inplace b/t/io.inplace index 2a245306c9..cacb7d0dc1 100644 --- a/t/io.inplace +++ b/t/io.inplace @@ -1,6 +1,6 @@ #!./perl -i.bak -# $Header: io.inplace,v 1.0 87/12/18 13:12:51 root Exp $ +# $Header: io.inplace,v 2.0 88/06/05 00:13:02 root Exp $ print "1..2\n"; diff --git a/t/io.pipe b/t/io.pipe new file mode 100644 index 0000000000..c4cb2f7537 --- /dev/null +++ b/t/io.pipe @@ -0,0 +1,21 @@ +#!./perl + +# $Header: io.pipe,v 2.0 88/06/05 00:13:05 root Exp $ + +$| = 1; +print "1..4\n"; + +open(PIPE, "|-") || (exec 'tr', '[A-Z]', '[a-z]'); +print PIPE "OK 1\n"; +print PIPE "ok 2\n"; +close PIPE; + +if (open(PIPE, "-|")) { + while(<PIPE>) { + print; + } +} +else { + print stdout "ok 3\n"; + exec 'echo', 'ok 4'; +} diff --git a/t/io.print b/t/io.print index f183b14013..3163b03dfb 100644 --- a/t/io.print +++ b/t/io.print @@ -1,11 +1,14 @@ #!./perl -# $Header: io.print,v 1.0 87/12/18 13:12:55 root Exp $ +# $Header: io.print,v 2.0 88/06/05 00:13:11 root Exp $ -print "1..11\n"; +print "1..16\n"; -print stdout "ok 1\n"; -print "ok 2\n","ok 3\n","ok 4\n","ok 5\n"; +$foo = 'stdout'; +print $foo "ok 1\n"; + +print "ok 2\n","ok 3\n","ok 4\n"; +print stdout "ok 5\n"; open(foo,">-"); print foo "ok 6\n"; @@ -23,3 +26,7 @@ $, = ' '; $\ = "\n"; print "ok","11"; + +@x = ("ok","12\nok","13\nok"); +@y = ("15\nok","16"); +print @x,"14\nok",@y; @@ -1,14 +1,16 @@ #!./perl -# $Header: io.tell,v 1.0 87/12/18 13:13:02 root Exp $ +# $Header: io.tell,v 2.0 88/06/05 00:13:14 root Exp $ print "1..13\n"; -open(tst, '../Makefile') || (die "Can't open ../Makefile"); +$TST = 'tst'; + +open($TST, '../Makefile') || (die "Can't open ../Makefile"); if (eof(tst)) { print "not ok 1\n"; } else { print "ok 1\n"; } -$firstline = <tst>; +$firstline = <$TST>; $secondpos = tell; $x = 0; @@ -21,7 +23,7 @@ $lastpos = tell; unless (eof) { print "not ok 3\n"; } else { print "ok 3\n"; } -if (seek(tst,0,0)) { print "ok 4\n"; } else { print "not ok 4\n"; } +if (seek($TST,0,0)) { print "ok 4\n"; } else { print "not ok 4\n"; } if (eof) { print "not ok 5\n"; } else { print "ok 5\n"; } @@ -31,7 +33,7 @@ if ($secondpos == tell) { print "ok 7\n"; } else { print "not ok 7\n"; } if (seek(tst,0,1)) { print "ok 8\n"; } else { print "not ok 8\n"; } -if (eof) { print "not ok 9\n"; } else { print "ok 9\n"; } +if (eof($TST)) { print "not ok 9\n"; } else { print "ok 9\n"; } if ($secondpos == tell) { print "ok 10\n"; } else { print "not ok 10\n"; } diff --git a/t/op.append b/t/op.append index 5972ac4533..63ab64917e 100644 --- a/t/op.append +++ b/t/op.append @@ -1,6 +1,6 @@ #!./perl -# $Header: op.append,v 1.0 87/12/18 13:13:05 root Exp $ +# $Header: op.append,v 2.0 88/06/05 00:13:16 root Exp $ print "1..3\n"; @@ -1,8 +1,8 @@ #!./perl -# $Header: op.auto,v 1.0 87/12/18 13:13:08 root Exp $ +# $Header: op.auto,v 2.0 88/06/05 00:13:19 root Exp $ -print "1..30\n"; +print "1..34\n"; $x = 10000; if (0 + ++$x - 1 == 10000) { print "ok 1\n";} else {print "not ok 1\n";} @@ -39,3 +39,10 @@ if (0 + $x{0} == 10000) { print "ok 27\n";} else {print "not ok 27\n";} if (0 + --$x{0} + 1 == 10000) { print "ok 28\n";} else {print "not ok 28\n";} if (0 + ++$x{0} + 0 == 10000) { print "ok 29\n";} else {print "not ok 29\n";} if ($x{0} == 10000) { print "ok 30\n";} else {print "not ok 30\n";} + +# test magical autoincrement + +if (++($foo = '99') eq '100') {print "ok 31\n";} else {print "not ok 31\n";} +if (++($foo = 'a0') eq 'a1') {print "ok 32\n";} else {print "not ok 32\n";} +if (++($foo = 'Az') eq 'Ba') {print "ok 33\n";} else {print "not ok 33\n";} +if (++($foo = 'zz') eq 'aaa') {print "ok 34\n";} else {print "not ok 34\n";} @@ -1,6 +1,6 @@ #!./perl -# $Header: op.chop,v 1.0 87/12/18 13:13:11 root Exp $ +# $Header: op.chop,v 2.0 88/06/05 00:13:22 root Exp $ print "1..2\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.cond,v 1.0 87/12/18 13:13:14 root Exp $ +# $Header: op.cond,v 2.0 88/06/05 00:13:26 root Exp $ print "1..4\n"; diff --git a/t/op.crypt b/t/op.crypt deleted file mode 100644 index b28dda6aaa..0000000000 --- a/t/op.crypt +++ /dev/null @@ -1,12 +0,0 @@ -#!./perl - -# $Header: op.crypt,v 1.0 87/12/18 13:13:17 root Exp $ - -print "1..2\n"; - -# this evaluates entirely at compile time! -if (crypt('uh','oh') eq 'ohPnjpYtoi1NU') {print "ok 1\n";} else {print "not ok 1\n";} - -# this doesn't. -$uh = 'uh'; -if (crypt($uh,'oh') eq 'ohPnjpYtoi1NU') {print "ok 2\n";} else {print "not ok 2\n";} diff --git a/t/op.delete b/t/op.delete new file mode 100644 index 0000000000..24315a5611 --- /dev/null +++ b/t/op.delete @@ -0,0 +1,29 @@ +#!./perl + +# $Header: op.delete,v 2.0 88/06/05 00:13:30 root Exp $ + +print "1..6\n"; + +$foo{1} = 'a'; +$foo{2} = 'b'; +$foo{3} = 'c'; + +$foo = delete $foo{2}; + +if ($foo eq 'b') {print "ok 1\n";} else {print "not ok 1\n";} +if ($foo{2} eq '') {print "ok 2\n";} else {print "not ok 2\n";} +if ($foo{1} eq 'a') {print "ok 3\n";} else {print "not ok 3\n";} +if ($foo{3} eq 'c') {print "ok 4\n";} else {print "not ok 4\n";} + +$foo = join('',values(foo)); +if ($foo eq 'ac' || $foo eq 'ca') {print "ok 5\n";} else {print "not ok 5\n";} + +foreach $key (keys(foo)) { + delete $foo{$key}; +} + +$foo{'foo'} = 'x'; +$foo{'bar'} = 'y'; + +$foo = join('',values(foo)); +if ($foo eq 'xy' || $foo eq 'yx') {print "ok 6\n";} else {print "not ok 6\n";} @@ -1,6 +1,7 @@ #!./perl -# $Header: op.do,v 1.0 87/12/18 13:13:20 root Exp $ +# $Header: op.do,v 2.0 88/06/05 00:13:36 root Exp $ + sub foo1 { print $_[0]; @@ -15,7 +16,7 @@ sub foo2 $x; } -print "1..8\n"; +print "1..15\n"; $_[0] = "not ok 1\n"; $result = do foo1("ok 1\n"); @@ -32,3 +33,12 @@ if ($_[0] EQ "not ok 4\n") { print "ok 6\n"; } else { print "not ok 6\n"; } $result = do{print "ok 7\n"; 'value';}; print "#8\t:$result: eq :value:\n"; if ($result EQ 'value') { print "ok 8\n"; } else { print "not ok 8\n"; } + +sub blather { + print @_; +} + +do blather("ok 9\n","ok 10\n"); +@x = ("ok 11\n", "ok 12\n"); +@y = ("ok 14\n", "ok 15\n"); +do blather(@x,"ok 13\n",@y); @@ -1,8 +1,8 @@ #!./perl -# $Header: op.each,v 1.0 87/12/18 13:13:23 root Exp $ +# $Header: op.each,v 2.0 88/06/05 00:13:38 root Exp $ -print "1..2\n"; +print "1..3\n"; $h{'abc'} = 'ABC'; $h{'def'} = 'DEF'; @@ -48,3 +48,6 @@ while (($key,$value) = each(h)) { } if ($i == 30) {print "ok 2\n";} else {print "not ok 2\n";} + +@keys = ('blurfl', keys(h), 'dyick'); +if ($#keys == 31) {print "ok 3\n";} else {print "not ok 3\n";} @@ -1,6 +1,8 @@ #!./perl -print "1..6\n"; +# $Header: op.eval,v 2.0 88/06/05 00:13:40 root Exp $ + +print "1..10\n"; eval 'print "ok 1\n";'; @@ -12,9 +14,29 @@ print $foo,"\n"; eval "\$foo\n = # this is a comment\n'ok 4\n';"; print $foo; -eval ' +print eval ' $foo ='; # this tests for a call through yyerror() if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";} -eval '$foo = /'; # this tests for a call through fatal() +print eval '$foo = /'; # this tests for a call through fatal() if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";} + +print eval '"ok 7\n";'; + +# calculate a factorial with recursive evals + +$foo = 5; +$fact = 'if ($foo <= 1) {1;} else {push(@x,$foo--); (eval $fact) * pop(@x);}'; +$ans = eval $fact; +if ($ans == 120) {print "ok 8\n";} else {print "not ok 8\n";} + +$foo = 5; +$fact = 'local($foo); $foo <= 1 ? 1 : $foo-- * (eval $fact);'; +$ans = eval $fact; +if ($ans == 120) {print "ok 9\n";} else {print "not ok 9 $ans\n";} + +open(try,'>Op.eval'); +print try 'print "ok 10\n"; unlink "Op.eval";',"\n"; +close try; + +do 'Op.eval'; print $@; @@ -1,12 +1,21 @@ #!./perl -# $Header: op.exec,v 1.0 87/12/18 13:13:26 root Exp $ +# $Header: op.exec,v 2.0 88/06/05 00:13:46 root Exp $ $| = 1; # flush stdout -print "1..4\n"; +print "1..8\n"; -system "echo ok \\1"; # shell interpreted -system "echo ok 2"; # split and directly called -system "echo", "ok", "3"; # directly called +print "not ok 1\n" if system "echo ok \\1"; # shell interpreted +print "not ok 2\n" if system "echo ok 2"; # split and directly called +print "not ok 3\n" if system "echo", "ok", "3"; # directly called -exec "echo","ok","4"; +if (system "true") {print "not ok 4\n";} else {print "ok 4\n";} + +if ((system "/bin/sh -c 'exit 1'") != 256) { print "not "; } +print "ok 5\n"; + +if ((system "lskdfj") == 255 << 8) {print "ok 6\n";} else {print "not ok 6\n";} + +unless (exec "lskdjfalksdjfdjfkls") {print "ok 7\n";} else {print "not ok 7\n";} + +exec "echo","ok","8"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.exp,v 1.0 87/12/18 13:13:29 root Exp $ +# $Header: op.exp,v 2.0 88/06/05 00:13:48 root Exp $ print "1..6\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.flip,v 1.0 87/12/18 13:13:34 root Exp $ +# $Header: op.flip,v 2.0 88/06/05 00:13:51 root Exp $ print "1..8\n"; @@ -17,7 +17,7 @@ if ($y eq '12E0123E0') {print "ok 7\n";} else {print "not ok 7\n";} @a = ('a','b','c','d','e','f','g'); -open(of,'/etc/termcap'); +open(of,'../Makefile'); while (<of>) { (3 .. 5) && $foo .= $_; } @@ -1,6 +1,6 @@ #!./perl -# $Header: op.fork,v 1.0 87/12/18 13:13:37 root Exp $ +# $Header: op.fork,v 2.0 88/06/05 00:13:53 root Exp $ $| = 1; print "1..2\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.goto,v 1.0 87/12/18 13:13:40 root Exp $ +# $Header: op.goto,v 2.0 88/06/05 00:13:58 root Exp $ print "1..3\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.int,v 1.0 87/12/18 13:13:43 root Exp $ +# $Header: op.int,v 2.0 88/06/05 00:14:01 root Exp $ print "1..4\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.join,v 1.0 87/12/18 13:13:46 root Exp $ +# $Header: op.join,v 2.0 88/06/05 00:14:05 root Exp $ print "1..3\n"; @@ -1,8 +1,8 @@ #!./perl -# $Header: op.list,v 1.0 87/12/18 13:13:50 root Exp $ +# $Header: op.list,v 2.0 88/06/05 00:14:09 root Exp $ -print "1..11\n"; +print "1..18\n"; @foo = (1, 2, 3, 4); if ($foo[0] == 1 && $foo[3] == 4) {print "ok 1\n";} else {print "not ok 1\n";} @@ -32,3 +32,28 @@ if ($d eq 4) {print "ok 10\n";} else {print "not ok 10\n";} ($a, $b, $c, $d) = @foo; print "#11 $a;$b;$c;$d eq 1;2;3;4\n"; if ("$a;$b;$c;$d" eq '1;2;3;4') {print "ok 11\n";} else {print "not ok 11\n";} + +@foo = (1); +if (join(':',@foo) eq '1') {print "ok 12\n";} else {print "not ok 12\n";} + +@foo = (); +@foo = 1+2+3; +if (join(':',@foo) eq '6') {print "ok 13\n";} else {print "not ok 13\n";} + +for ($x = 0; $x < 3; $x++) { + ($a, $b, $c) = + $x == 0? + ('ok ', 14, "\n"): + $x == 1? + ('ok ', 15, "\n"): + # default + ('ok ', 16, "\n"); + + print $a,$b,$c; +} + +@a = ($x == 12345 || (1,2,3)); +if (join('',@a) eq '123') {print "ok 17\n";} else {print "not ok 17\n";} + +@a = ($x == $x || (4,5,6)); +if (join('',@a) eq '1') {print "ok 18\n";} else {print "not ok 18\n";} diff --git a/t/op.magic b/t/op.magic index 7696803127..ab8dbeec3d 100644 --- a/t/op.magic +++ b/t/op.magic @@ -1,27 +1,26 @@ #!./perl -# $Header: op.magic,v 1.0 87/12/18 13:13:54 root Exp $ - -print "1..4\n"; +# $Header: op.magic,v 2.0 88/06/05 00:14:11 root Exp $ $| = 1; # command buffering -$ENV{'foo'} = 'hi there'; +print "1..4\n"; + +eval '$ENV{"foo"} = "hi there";'; # check that ENV is inited inside eval if (`echo \$foo` eq "hi there\n") {print "ok 1\n";} else {print "not ok 1\n";} $! = 0; open(foo,'ajslkdfpqjsjfkslkjdflksd'); if ($! == 2) {print "ok 2\n";} else {print "not ok 2\n";} -$SIG{'INT'} = 'ok3'; -kill 2,$$; -$SIG{'INT'} = 'IGNORE'; -kill 2,$$; -print "ok 4\n"; -$SIG{'INT'} = 'DEFAULT'; -kill 2,$$; -print "not ok\n"; - -sub ok3 { - print "ok 3\n" if pop(@_) eq 'INT'; -} +# the next tests are embedded inside system simply because sh spits out +# a newline onto stderr when a child process kills itself with SIGINT. + +system './perl', +'-e', '$| = 1; # command buffering', + +'-e', '$SIG{"INT"} = "ok3"; kill 2,$$;', +'-e', '$SIG{"INT"} = "IGNORE"; kill 2,$$; print "ok 4\n";', +'-e', '$SIG{"INT"} = "DEFAULT"; kill 2,$$; print "not ok\n";', + +'-e', 'sub ok3 { print "ok 3\n" if pop(@_) eq "INT"; }'; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.oct,v 1.0 87/12/18 13:13:57 root Exp $ +# $Header: op.oct,v 2.0 88/06/05 00:14:14 root Exp $ print "1..3\n"; @@ -1,6 +1,6 @@ #!./perl -# $Header: op.ord,v 1.0 87/12/18 13:14:01 root Exp $ +# $Header: op.ord,v 2.0 88/06/05 00:14:17 root Exp $ print "1..2\n"; @@ -1,7 +1,8 @@ #!./perl -# $Header: op.pat,v 1.0 87/12/18 13:14:07 root Exp $ -print "1..22\n"; +# $Header: op.pat,v 2.0 88/06/05 00:14:20 root Exp $ + +print "1..30\n"; $x = "abc\ndef\n"; @@ -54,3 +55,41 @@ if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";} if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";} if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";} + +if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";} + +$* = 1; # test 3 only tested the optimized version--this one is for real +if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";} +$* = 0; + +$XXX{123} = 123; +$XXX{234} = 234; +$XXX{345} = 345; + +@XXX = ('ok 25','not ok 25', 'ok 26','not ok 26','not ok 27'); +while ($_ = shift(XXX)) { + ?(.*)? && (print $1,"\n"); + /not/ && reset; + /not ok 26/ && reset 'X'; +} + +while (($key,$val) = each(XXX)) { + print "not ok 27\n"; + exit; +} + +print "ok 27\n"; + +'cde' =~ /[^ab]*/; +'xyz' =~ //; +if ($& eq 'xyz') {print "ok 28\n";} else {print "not ok 28\n";} + +$foo = '[^ab]*'; +'cde' =~ /$foo/; +'xyz' =~ //; +if ($& eq 'xyz') {print "ok 29\n";} else {print "not ok 29\n";} + +$foo = '[^ab]*'; +'cde' =~ /$foo/; +'xyz' =~ /$null/; +if ($& eq 'xyz') {print "ok 30\n";} else {print "not ok 30\n";} @@ -1,6 +1,6 @@ #!./perl -# $Header: op.push,v 1.0 87/12/18 13:14:10 root Exp $ +# $Header: op.push,v 2.0 88/06/05 00:14:23 root Exp $ print "1..2\n"; diff --git a/t/op.regexp b/t/op.regexp new file mode 100644 index 0000000000..7c97227ccc --- /dev/null +++ b/t/op.regexp @@ -0,0 +1,31 @@ +#!./perl + +# $Header: op.regexp,v 2.0 88/06/05 00:14:27 root Exp $ + +open(TESTS,'re_tests') || open(TESTS,'t/re_tests') || die "Can't open re_tests"; +while (<TESTS>) { } +$numtests = $.; +close(TESTS); + +print "1..$numtests\n"; +open(TESTS,'re_tests') || open(TESTS,'t/re_tests') || die "Can't open re_tests"; +while (<TESTS>) { + ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_); + $input = join(':',$pat,$subject,$result,$repl,$expect); + eval "\$match = (\$subject =~ \$pat); \$got = \"$repl\";"; + if ($result eq 'c') { + if ($@ ne '') {print "ok $.\n";} else {print "not ok $.\n";} + } + elsif ($result eq 'n') { + if (!$match) {print "ok $.\n";} else {print "not ok $. $input => $got\n";} + } + else { + if ($match && $got eq $expect) { + print "ok $.\n"; + } + else { + print "not ok $. $input => $got\n"; + } + } +} +close(TESTS); diff --git a/t/op.repeat b/t/op.repeat index 1c03c31d9a..e293ea873c 100644 --- a/t/op.repeat +++ b/t/op.repeat @@ -1,6 +1,6 @@ #!./perl -# $Header: op.repeat,v 1.0 87/12/18 13:14:14 root Exp $ +# $Header: op.repeat,v 2.0 88/06/05 00:14:31 root Exp $ print "1..11\n"; diff --git a/t/op.sleep b/t/op.sleep index e32e62bf1b..410ced709c 100644 --- a/t/op.sleep +++ b/t/op.sleep @@ -1,6 +1,6 @@ #!./perl -# $Header: op.sleep,v 1.0 87/12/18 13:14:17 root Exp $ +# $Header: op.sleep,v 2.0 88/06/05 00:14:35 root Exp $ print "1..1\n"; diff --git a/t/op.split b/t/op.split index a6bb1b47c8..7c58f8f860 100644 --- a/t/op.split +++ b/t/op.split @@ -1,8 +1,8 @@ #!./perl -# $Header: op.split,v 1.0.1.1 88/02/02 11:26:37 root Exp $ +# $Header: op.split,v 2.0 88/06/05 00:14:37 root Exp $ -print "1..6\n"; +print "1..7\n"; $FS = ':'; @@ -23,9 +23,13 @@ $_ = "a:b:c::::"; @ary = split(/:/); if (join(".",@ary) eq "a.b.c") {print "ok 4\n";} else {print "not ok 4\n";} -$_ = join(':',split(' ',' a b c ')); -if ($_ eq 'a:b:c') {print "ok 5\n";} else {print "not ok 5\n";} +$_ = join(':',split(' '," a b\tc \t d ")); +if ($_ eq 'a:b:c:d') {print "ok 5\n";} else {print "not ok 5 #$_#\n";} $_ = join(':',split(/ */,"foo bar bie\tdoll")); if ($_ eq "f:o:o:b:a:r:b:i:e:\t:d:o:l:l") {print "ok 6\n";} else {print "not ok 6\n";} + +$_ = join(':', 'foo', split(/ /,'a b c'), 'bar'); +if ($_ eq "foo:a:b::c:bar") {print "ok 7\n";} else {print "not ok 7 $_\n";} + diff --git a/t/op.sprintf b/t/op.sprintf index cb4e5c7b3a..81fbdaabfc 100644 --- a/t/op.sprintf +++ b/t/op.sprintf @@ -1,6 +1,6 @@ #!./perl -# $Header: op.sprintf,v 1.0 87/12/18 13:14:24 root Exp $ +# $Header: op.sprintf,v 2.0 88/06/05 00:14:40 root Exp $ print "1..1\n"; @@ -1,8 +1,8 @@ #!./perl -# $Header: op.stat,v 1.0 87/12/18 13:14:27 root Exp $ +# $Header: op.stat,v 2.0 88/06/05 00:14:43 root Exp $ -print "1..4\n"; +print "1..56\n"; open(foo, ">Op.stat.tmp"); @@ -26,4 +26,115 @@ if ($nlink == 2) {print "ok 3\n";} else {print "not ok 3\n";} if ($mtime && $mtime != $ctime) {print "ok 4\n";} else {print "not ok 4\n";} print "#4 :$mtime: != :$ctime:\n"; +`cp /dev/null Op.stat.tmp`; + +if (-z 'Op.stat.tmp') {print "ok 5\n";} else {print "not ok 5\n";} +if (! -s 'Op.stat.tmp') {print "ok 6\n";} else {print "not ok 6\n";} + +`echo hi >Op.stat.tmp`; +if (! -z 'Op.stat.tmp') {print "ok 7\n";} else {print "not ok 7\n";} +if (-s 'Op.stat.tmp') {print "ok 8\n";} else {print "not ok 8\n";} + +chmod 0,'Op.stat.tmp'; +$olduid = $>; # can't test -r if uid == 0 +eval '$> = 1;'; # so switch uid (may not be implemented) +if (!$> || ! -r 'Op.stat.tmp') {print "ok 9\n";} else {print "not ok 9\n";} +if (!$> || ! -w 'Op.stat.tmp') {print "ok 10\n";} else {print "not ok 10\n";} +eval '$> = $olduid;'; # switch uid back (may not be implemented) +if (! -x 'Op.stat.tmp') {print "ok 11\n";} else {print "not ok 11\n";} + +foreach ((12,13,14,15,16,17)) { + print "ok $_\n"; #deleted tests +} + +chmod 0700,'Op.stat.tmp'; +if (-r 'Op.stat.tmp') {print "ok 18\n";} else {print "not ok 18\n";} +if (-w 'Op.stat.tmp') {print "ok 19\n";} else {print "not ok 19\n";} +if (-x 'Op.stat.tmp') {print "ok 20\n";} else {print "not ok 20\n";} + +if (-f 'Op.stat.tmp') {print "ok 21\n";} else {print "not ok 21\n";} +if (! -d 'Op.stat.tmp') {print "ok 22\n";} else {print "not ok 22\n";} + +if (-d '.') {print "ok 23\n";} else {print "not ok 23\n";} +if (! -f '.') {print "ok 24\n";} else {print "not ok 24\n";} + +if (`ls -l perl` =~ /^l.*->/) { + if (-l 'perl') {print "ok 25\n";} else {print "not ok 25\n";} +} +else { + print "ok 25\n"; +} + +if (-o 'Op.stat.tmp') {print "ok 26\n";} else {print "not ok 26\n";} + +if (-e 'Op.stat.tmp') {print "ok 27\n";} else {print "not ok 27\n";} `rm -f Op.stat.tmp Op.stat.tmp2`; +if (! -e 'Op.stat.tmp') {print "ok 28\n";} else {print "not ok 28\n";} + +if (-c '/dev/tty') {print "ok 29\n";} else {print "not ok 29\n";} +if (! -c '.') {print "ok 30\n";} else {print "not ok 30\n";} + +if (! -e '/dev/printer' || -S '/dev/printer') + {print "ok 31\n";} +else + {print "not ok 31\n";} +if (! -S '.') {print "ok 32\n";} else {print "not ok 32\n";} + +if (! -e '/dev/mt0' || -b '/dev/mt0') + {print "ok 33\n";} +else + {print "not ok 33\n";} +if (! -b '.') {print "ok 34\n";} else {print "not ok 34\n";} + +$cnt = $uid = 0; + +while (</usr/bin/*>) { + $cnt++; + $uid++ if -u; + last if $uid && $uid < $cnt; +} + +# I suppose this is going to fail somewhere... +if ($uid > 0 && $uid < $cnt) {print "ok 35\n";} else {print "not ok 35\n";} + +unless (open(tty,"/dev/tty")) { + print stderr "Can't open /dev/tty--run t/TEST outside of make.\n"; +} +if (-t tty) {print "ok 36\n";} else {print "not ok 36\n";} +if (-c tty) {print "ok 37\n";} else {print "not ok 37\n";} +close(tty); +if (! -t tty) {print "ok 38\n";} else {print "not ok 38\n";} +open(null,"/dev/null"); +if (! -t null) {print "ok 39\n";} else {print "not ok 39\n";} +close(null); +if (-t) {print "ok 40\n";} else {print "not ok 40\n";} + +# These aren't strictly "stat" calls, but so what? + +if (-T 'op.stat') {print "ok 41\n";} else {print "not ok 41\n";} +if (! -B 'op.stat') {print "ok 42\n";} else {print "not ok 42\n";} + +if (-B './perl') {print "ok 43\n";} else {print "not ok 43\n";} +if (! -T './perl') {print "ok 44\n";} else {print "not ok 44\n";} + +open(foo,'op.stat'); +if (-T foo) {print "ok 45\n";} else {print "not ok 45\n";} +if (! -B foo) {print "ok 46\n";} else {print "not ok 46\n";} +$_ = <foo>; +if (/perl/) {print "ok 47\n";} else {print "not ok 47\n";} +if (-T foo) {print "ok 48\n";} else {print "not ok 48\n";} +if (! -B foo) {print "ok 49\n";} else {print "not ok 49\n";} +close(foo); + +open(foo,'op.stat'); +$_ = <foo>; +if (/perl/) {print "ok 50\n";} else {print "not ok 50\n";} +if (-T foo) {print "ok 51\n";} else {print "not ok 51\n";} +if (! -B foo) {print "ok 52\n";} else {print "not ok 52\n";} +seek(foo,0,0); +if (-T foo) {print "ok 53\n";} else {print "not ok 53\n";} +if (! -B foo) {print "ok 54\n";} else {print "not ok 54\n";} +close(foo); + +if (-T '/dev/null') {print "ok 55\n";} else {print "not ok 55\n";} +if (-B '/dev/null') {print "ok 56\n";} else {print "not ok 56\n";} diff --git a/t/op.study b/t/op.study new file mode 100644 index 0000000000..8da28d6575 --- /dev/null +++ b/t/op.study @@ -0,0 +1,69 @@ +#!./perl + +# $Header: op.study,v 2.0 88/06/05 00:14:45 root Exp $ + +print "1..24\n"; + +$x = "abc\ndef\n"; +study($x); + +if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";} +if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";} + +$* = 1; +if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";} +$* = 0; + +$_ = '123'; +study; +if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";} + +if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";} +if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";} + +if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";} +if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";} + +study($x); +if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";} +if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";} + +if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";} +if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";} + +$_ = 'aaabbbccc'; +study; +if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') { + print "ok 13\n"; +} else { + print "not ok 13\n"; +} +if (/(a+b+c+)/ && $1 eq 'aaabbbccc') { + print "ok 14\n"; +} else { + print "not ok 14\n"; +} + +if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";} + +$_ = 'aaabccc'; +study; +if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";} +if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";} + +$_ = 'aaaccc'; +study; +if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";} +if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";} + +$_ = 'abcdef'; +study; +if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";} +if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";} + +if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";} + +if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";} + +$* = 1; # test 3 only tested the optimized version--this one is for real +if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";} diff --git a/t/op.subst b/t/op.subst index e431be8cec..86b5b41c76 100644 --- a/t/op.subst +++ b/t/op.subst @@ -1,8 +1,8 @@ #!./perl -# $Header: op.subst,v 1.0 87/12/18 13:14:30 root Exp $ +# $Header: op.subst,v 2.0 88/06/05 00:14:49 root Exp $ -print "1..7\n"; +print "1..13\n"; $x = 'foo'; $_ = "x"; @@ -20,9 +20,8 @@ s/x/\$x $x/; print "#3\t:$_: eq :\$x foo:\n"; if ($_ eq '$x foo') {print "ok 3\n";} else {print "not ok 3\n";} -$a = 'abcdef'; $b = 'cd'; -$a =~ s'(b${b}e)'\n$1'; +($a = 'abcdef') =~ s'(b${b}e)'\n$1'; print "#4\t:$1: eq :bcde:\n"; print "#4\t:$a: eq :a\\n\$1f:\n"; if ($1 eq 'bcde' && $a eq 'a\n$1f') {print "ok 4\n";} else {print "not ok 4\n";} @@ -35,4 +34,18 @@ if (($a =~ s/a/y/g) == 0 && $a eq 'xbxcxdx') {print "ok 6\n";} else {print "not ok 6\n";} if (($a =~ s/b/y/g) == 1 && $a eq 'xyxcxdx') - {print "ok 7\n";} else {print "not ok 7\n";} + {print "ok 7\n";} else {print "not ok 7 $a\n";} + +$_ = 'ABACADA'; +if (/a/i && s///gi && $_ eq 'BCD') {print "ok 8\n";} else {print "not ok 8\n";} + +$_ = '\\' x 4; +if (length($_) == 4) {print "ok 9\n";} else {print "not ok 9\n";} +s/\\/\\\\/g; +if ($_ eq '\\' x 8) {print "ok 10\n";} else {print "not ok 10\n";} + +$_ = '\/' x 4; +if (length($_) == 8) {print "ok 11\n";} else {print "not ok 11\n";} +s/\//\/\//g; +if ($_ eq '\\//' x 4) {print "ok 12\n";} else {print "not ok 12\n";} +if (length($_) == 12) {print "ok 13\n";} else {print "not ok 13\n";} @@ -1,6 +1,6 @@ #!./perl -# $Header: op.time,v 1.0.1.1 88/01/24 03:56:09 root Exp $ +# $Header: op.time,v 2.0 88/06/05 00:14:58 root Exp $ print "1..5\n"; diff --git a/t/op.unshift b/t/op.unshift index 3008da5de9..948902a97f 100644 --- a/t/op.unshift +++ b/t/op.unshift @@ -1,6 +1,6 @@ #!./perl -# $Header: op.unshift,v 1.0 87/12/18 13:14:37 root Exp $ +# $Header: op.unshift,v 2.0 88/06/05 00:15:00 root Exp $ print "1..2\n"; diff --git a/t/re_tests b/t/re_tests new file mode 100644 index 0000000000..807f6ece36 --- /dev/null +++ b/t/re_tests @@ -0,0 +1,122 @@ +abc abc y $& abc +abc xbc n - - +abc axc n - - +abc abx n - - +abc xabcy y $& abc +abc ababc y $& abc +ab*c abc y $& abc +ab*bc abc y $& abc +ab*bc abbc y $& abbc +ab*bc abbbbc y $& abbbbc +ab+bc abbc y $& abbc +ab+bc abc n - - +ab+bc abq n - - +ab+bc abbbbc y $& abbbbc +ab?bc abbc y $& abbc +ab?bc abc y $& abc +ab?bc abbbbc n - - +ab?c abc y $& abc +^abc$ abc y $& abc +^abc$ abcc n - - +^abc abcc y $& abc +^abc$ aabc n - - +abc$ aabc y $& abc +^ abc y $& +$ abc y $& +a.c abc y $& abc +a.c axc y $& axc +a.*c axyzc y $& axyzc +a.*c axyzd n - - +a[bc]d abc n - - +a[bc]d abd y $& abd +a[b-d]e abd n - - +a[b-d]e ace y $& ace +a[b-d] aac y $& ac +a[-b] a- y $& a- +a[b-] a- y $& a- +a[b-a] - c - - +a[]b - c - - +a[ - c - - +a] a] y $& a] +a[]]b a]b y $& a]b +a[^bc]d aed y $& aed +a[^bc]d abd n - - +a[^-b]c adc y $& adc +a[^-b]c a-c n - - +a[^]b]c a]c n - - +a[^]b]c adc y $& adc +ab|cd abc y $& ab +ab|cd abcd y $& ab +()ef def y $&-$1 ef- +()* - c - - +*a - c - - +^* - c - - +$* - c - - +(*)b - c - - +$b b n - - +a\ - c - - +a\(b a(b y $&-$1 a(b- +a\(*b ab y $& ab +a\(*b a((b y $& a((b +a\\b a\b y $& a\b +abc) - c - - +(abc - c - - +((a)) abc y $&-$1-$2 a-a-a +(a)b(c) abc y $&-$1-$2 abc-a-c +a+b+c aabbabc y $& abc +a** - c - - +a*? - c - - +(a*)* - c - - +(a*)+ - c - - +(a|)* - c - - +(a*|b)* - c - - +(a+|b)* ab y $&-$1 ab-b +(a+|b)+ ab y $&-$1 ab-b +(a+|b)? ab y $&-$1 a-a +(^)* - c - - +(ab|)* - c - - +)( - c - - +[^ab]* cde y $& cde +abc n - - +a* y $& +([abc])*d abbbcd y $&-$1 abbbcd-c +([abc])*bcd abcd y $&-$1 abcd-a +a|b|c|d|e e y $& e +(a|b|c|d|e)f ef y $&-$1 ef-e +((a*|b))* - c - - +abcd*efg abcdefg y $& abcdefg +ab* xabyabbbz y $& ab +ab* xayabbbz y $& a +(ab|cd)e abcde y $&-$1 cde-cd +[abhgefdc]ij hij y $& hij +^(ab|cd)e abcde n x$1y xy +(abc|)ef abcdef y $&-$1 ef- +(a|b)c*d abcd y $&-$1 bcd-b +(ab|ab*)bc abc y $&-$1 abc-a +a([bc]*)c* abc y $&-$1 abc-bc +a([bc]*)(c*d) abcd y $&-$1-$2 abcd-bc-d +a([bc]+)(c*d) abcd y $&-$1-$2 abcd-bc-d +a([bc]*)(c+d) abcd y $&-$1-$2 abcd-b-cd +a[bcd]*dcdcde adcdcde y $& adcdcde +a[bcd]+dcdcde adcdcde n - - +(ab|a)b*c abc y $&-$1 abc-ab +((a)(b)c)(d) abcd y $1-$2-$3-$4 abc-a-b-d +[a-zA-Z_][a-zA-Z0-9_]* alpha y $& alpha +^a(bc+|b[eh])g|.h$ abh y $&-$1 bh- +(bc+d$|ef*g.|h?i(j|k)) effgz y $&-$1-$2 effgz-effgz- +(bc+d$|ef*g.|h?i(j|k)) ij y $&-$1-$2 ij-ij-j +(bc+d$|ef*g.|h?i(j|k)) effg n - - +(bc+d$|ef*g.|h?i(j|k)) bcdd n - - +(bc+d$|ef*g.|h?i(j|k)) reffgz y $&-$1-$2 effgz-effgz- +((((((((((a)))))))))) - c - - +(((((((((a))))))))) a y $& a +multiple words of text uh-uh n - - +multiple words multiple words, yeah y $& multiple words +(.*)c(.*) abcde y $&-$1-$2 abcde-ab-de +\((.*), (.*)\) (a, b) y ($2, $1) (b, a) +[k] ab n - - +abcd abcd y $&-\$&-\\$& abcd-$&-\abcd +a(bc)d abcd y $1-\$1-\\$1 bc-$1-\bc +a[-]?c ac y $& ac +(abc)\1 abcabc y $1 abc +([a-c]*)\1 abcabc y $1 abc |