summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-06-15 01:01:14 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-06-15 01:01:14 +0000
commited796a820653ef1e6c63e0bae7a6f19bbff18fbb (patch)
treeb6618d02436f4b1f0720707dfd484d6988d0ecc6
parentf6320b648afec215bb1c3d95e9fe42db8819771b (diff)
patches from pdksh 5.2.13.11
-rw-r--r--bin/ksh/tests/README22
-rw-r--r--bin/ksh/tests/heredoc.t187
-rw-r--r--bin/ksh/tests/lineno.t111
-rw-r--r--bin/ksh/tests/regress.t1
-rw-r--r--bin/ksh/tests/th181
-rw-r--r--bin/ksh/tests/version.t2
6 files changed, 501 insertions, 3 deletions
diff --git a/bin/ksh/tests/README b/bin/ksh/tests/README
new file mode 100644
index 00000000000..73cf83b84a3
--- /dev/null
+++ b/bin/ksh/tests/README
@@ -0,0 +1,22 @@
+Tests can be assigned categories to restrict what program they
+are applied to (eg, pdksh, ksh88, etc.). The following are
+a list of names to be used for various shells (to keep things
+consistent):
+
+ sh generic any v7 bourne shell like thing
+ sh-v generic any system V bourne shell like thing
+ ksh generic any ksh
+ posix generic basic posix shell
+ posix-upu generic `user portability utility' options
+ sh-v7 specific the real v7 bourne shell
+ sh-sysv specific the real sysv bourne shell
+ pdksh specific public domain ksh
+ ksh88 specific at&t ksh88
+ ksh93 specific at&t ksh93
+ bash specific GNU bourne-again shell
+
+The idea is to categorize all the tests according to the `best match'
+(most generic thing). All generics that apply should be specified.
+Generally, at most one specific shell will be given.
+
+At the moment, most (all) tests have not been categorized (any volunteers?).
diff --git a/bin/ksh/tests/heredoc.t b/bin/ksh/tests/heredoc.t
index 21feb925cea..084638c99d6 100644
--- a/bin/ksh/tests/heredoc.t
+++ b/bin/ksh/tests/heredoc.t
@@ -142,3 +142,190 @@ expected-stdout:
done
---
+name: heredoc-tmpfile-1
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in simple command.
+stdin:
+ TMPDIR=$PWD
+ eval '
+ cat <<- EOF
+ hi
+ EOF
+ for i in a b ; do
+ cat <<- EOF
+ more
+ EOF
+ done
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ hi
+ more
+ more
+ Left overs: *
+---
+
+name: heredoc-tmpfile-2
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in function, multiple calls to function.
+stdin:
+ TMPDIR=$PWD
+ eval '
+ foo() {
+ cat <<- EOF
+ hi
+ EOF
+ }
+ foo
+ foo
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ hi
+ hi
+ Left overs: *
+---
+
+name: heredoc-tmpfile-3
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in function in loop, multiple calls to function.
+stdin:
+ TMPDIR=$PWD
+ eval '
+ foo() {
+ cat <<- EOF
+ hi
+ EOF
+ }
+ for i in a b; do
+ foo
+ foo() {
+ cat <<- EOF
+ folks $i
+ EOF
+ }
+ done
+ foo
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ hi
+ folks b
+ folks b
+ Left overs: *
+---
+
+name: heredoc-tmpfile-4
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Backgrounded simple command with here doc
+stdin:
+ TMPDIR=$PWD
+ eval '
+ cat <<- EOF &
+ hi
+ EOF
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ hi
+ Left overs: *
+---
+
+name: heredoc-tmpfile-5
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Backgrounded subshell command with here doc
+stdin:
+ TMPDIR=$PWD
+ eval '
+ (
+ sleep 1 # so parent exits
+ echo A
+ cat <<- EOF
+ hi
+ EOF
+ echo B
+ ) &
+ ' &
+ sleep 2
+ echo Left overs: *
+expected-stdout:
+ A
+ hi
+ B
+ Left overs: *
+---
+
+name: heredoc-tmpfile-6
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in pipeline.
+stdin:
+ TMPDIR=$PWD
+ eval '
+ cat <<- EOF | sed "s/hi/HI/"
+ hi
+ EOF
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ HI
+ Left overs: *
+---
+
+name: heredoc-tmpfile-7
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in backgrounded pipeline.
+stdin:
+ TMPDIR=$PWD
+ eval '
+ cat <<- EOF | sed 's/hi/HI/' &
+ hi
+ EOF
+ ' &
+ sleep 1
+ echo Left overs: *
+expected-stdout:
+ HI
+ Left overs: *
+---
+
+name: heredoc-tmpfile-8
+description:
+ Check that heredoc temp files aren't removed too soon or too late.
+ Heredoc in function, backgrounded call to function.
+stdin:
+ TMPDIR=$PWD
+ # Background eval so main shell doesn't do parsing
+ eval '
+ foo() {
+ cat <<- EOF
+ hi
+ EOF
+ }
+ foo
+ # sleep so eval can die
+ (sleep 1; foo) &
+ (sleep 1; foo) &
+ foo
+ ' &
+ sleep 2
+ echo Left overs: *
+expected-stdout:
+ hi
+ hi
+ hi
+ hi
+ Left overs: *
+---
+
diff --git a/bin/ksh/tests/lineno.t b/bin/ksh/tests/lineno.t
new file mode 100644
index 00000000000..eb7eab91f03
--- /dev/null
+++ b/bin/ksh/tests/lineno.t
@@ -0,0 +1,111 @@
+name: lineno-stdin
+description:
+ See if $LINENO is updated and can be modified.
+stdin:
+ echo A $LINENO
+ echo B $LINENO
+ LINENO=20
+ echo C $LINENO
+expected-stdout:
+ A 1
+ B 2
+ C 20
+---
+
+name: lineno-inc
+description:
+ See if $LINENO is set for .'d files.
+file-setup: file 644 "dotfile"
+ echo dot A $LINENO
+ echo dot B $LINENO
+ LINENO=20
+ echo dot C $LINENO
+stdin:
+ echo A $LINENO
+ echo B $LINENO
+ . ./dotfile
+expected-stdout:
+ A 1
+ B 2
+ dot A 1
+ dot B 2
+ dot C 20
+---
+
+
+name: lineno-func
+description:
+ See if $LINENO is set for commands in a function.
+stdin:
+ echo A $LINENO
+ echo B $LINENO
+ bar() {
+ echo func A $LINENO
+ echo func B $LINENO
+ }
+ bar
+ echo C $LINENO
+expected-stdout:
+ A 1
+ B 2
+ func A 4
+ func B 5
+ C 8
+---
+
+name: lineno-unset
+description:
+ See if unsetting LINENO makes it non-magic.
+file-setup: file 644 "dotfile"
+ echo dot A $LINENO
+ echo dot B $LINENO
+stdin:
+ unset LINENO
+ echo A $LINENO
+ echo B $LINENO
+ bar() {
+ echo func A $LINENO
+ echo func B $LINENO
+ }
+ bar
+ . ./dotfile
+ echo C $LINENO
+expected-stdout:
+ A
+ B
+ func A
+ func B
+ dot A
+ dot B
+ C
+---
+
+name: lineno-unset-use
+description:
+ See if unsetting LINENO makes it non-magic even
+ when it is re-used.
+file-setup: file 644 "dotfile"
+ echo dot A $LINENO
+ echo dot B $LINENO
+stdin:
+ unset LINENO
+ LINENO=3
+ echo A $LINENO
+ echo B $LINENO
+ bar() {
+ echo func A $LINENO
+ echo func B $LINENO
+ }
+ bar
+ . ./dotfile
+ echo C $LINENO
+expected-stdout:
+ A 3
+ B 3
+ func A 3
+ func B 3
+ dot A 3
+ dot B 3
+ C 3
+---
+
diff --git a/bin/ksh/tests/regress.t b/bin/ksh/tests/regress.t
index 4f0a24ffd2c..c3b5c3f2913 100644
--- a/bin/ksh/tests/regress.t
+++ b/bin/ksh/tests/regress.t
@@ -1076,3 +1076,4 @@ expected-stdout:
parent last
parent exit
---
+
diff --git a/bin/ksh/tests/th b/bin/ksh/tests/th
index 53fc654e8dc..7834b968a36 100644
--- a/bin/ksh/tests/th
+++ b/bin/ksh/tests/th
@@ -67,6 +67,25 @@
# (if any). The first word may be
# preceeded by a ! to strip the trailing
# newline in a symlink.
+# file-result mps Used to verify a file, symlink or
+# directory is created correctly.
+# The first word is either
+# file, dir or symlink; second word is
+# expected permissions; third word
+# is user-id; fourth is group-id;
+# fifth is "exact" or "pattern"
+# indicating whether the file contents
+# which follow is to be matched exactly
+# or if it is a regular expression.
+# The fifth argument is the quoted name
+# of the file that should be created.
+# The end-quote should be followed
+# by a newline, then the file data
+# (if any). The first word may be
+# preceeded by a ! to strip the trailing
+# newline in the file contents.
+# The permissions, user and group fields
+# may be * meaning accept any value.
# time-limit Time limit - the program is sent a
# SIGKILL N seconds. Default is no
# limit.
@@ -147,6 +166,7 @@ EOF
'perl-cleanup', 'm',
'env-setup', 'M',
'file-setup', 'mps',
+ 'file-result', 'mps',
'time-limit', '',
'expected-fail', '',
'expected-exit', '',
@@ -544,6 +564,13 @@ run_test
$why .= $tmp;
}
+ $tmp = &check_file_result(*test);
+ return undef if !defined $tmp;
+ if ($tmp ne '') {
+ $failed = 1;
+ $why .= $tmp;
+ }
+
if (defined $test{'perl-cleanup'}) {
eval $test{'perl-cleanup'};
if ($@ ne '') {
@@ -665,6 +692,15 @@ check_output
$got .= $_;
}
close(TEMP);
+ return compare_output($name, $what, $expect, $expect_pat, $got);
+}
+
+sub
+compare_output
+{
+ local($name, $what, $expect, $expect_pat, $got) = @_;
+ local($why) = '';
+
if (defined $expect_pat) {
$_ = $got;
$ret = eval "$expect_pat";
@@ -881,7 +917,7 @@ read_test
"$prog:$file:$.: bad file type for file-setup: $type\n";
return undef;
}
- if ($perm !~ /\d+/) {
+ if ($perm !~ /^\d+$/) {
print STDERR
"$prog:$file:$.: bad permissions for file-setup: $type\n";
return undef;
@@ -889,7 +925,7 @@ read_test
$c = substr($rest, 0, 1);
if (($len = index($rest, $c, 1) - 1) <= 0) {
print STDERR
- "$prog:$file:$.: missing end quote for file name in file-setup: $type\n";
+ "$prog:$file:$.: missing end quote for file name in file-setup: $rest\n";
return undef;
}
$name = substr($rest, 1, $len);
@@ -902,6 +938,60 @@ read_test
return undef;
}
}
+ if ($field eq 'file-result') {
+ local($type, $perm, $uid, $gid, $matchType,
+ $rest, $c, $len, $name);
+ #
+ # format is: type perm uid gid matchType "name"
+ #
+ if ($val !~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S.*)/) {
+ print STDERR
+ "$prog:$file:$.: bad paramter line for file-result field\n";
+ return undef;
+ }
+ ($type, $perm, $uid, $gid, $matchType, $rest)
+ = ($1, $2, $3, $4, $5, $6);
+ if ($type !~ /^(file|dir|symlink)$/) {
+ print STDERR
+ "$prog:$file:$.: bad file type for file-result: $type\n";
+ return undef;
+ }
+ if ($perm !~ /^\d+$/ && $perm ne '*') {
+ print STDERR
+ "$prog:$file:$.: bad permissions for file-result: $perm\n";
+ return undef;
+ }
+ if ($uid !~ /^\d+$/ && $uid ne '*') {
+ print STDERR
+ "$prog:$file:$.: bad user-id for file-result: $uid\n";
+ return undef;
+ }
+ if ($gid !~ /^\d+$/ && $gid ne '*') {
+ print STDERR
+ "$prog:$file:$.: bad group-id for file-result: $gid\n";
+ return undef;
+ }
+ if ($matchType !~ /^(exact|pattern)$/) {
+ print STDERR
+ "$prog:$file:$.: bad match type for file-result: $matchType\n";
+ return undef;
+ }
+ $c = substr($rest, 0, 1);
+ if (($len = index($rest, $c, 1) - 1) <= 0) {
+ print STDERR
+ "$prog:$file:$.: missing end quote for file name in file-result: $rest\n";
+ return undef;
+ }
+ $name = substr($rest, 1, $len);
+ if ($name =~ /^\// || $name =~ /(^|\/)\.\.(\/|$)/) {
+ # Note: this is not a security thing - just a sanity
+ # check - a test can still use symlinks to get at files
+ # outside the test directory.
+ print STDERR
+"$prog:$file:$.: file name in file-result is absolute or contains ..: $name\n";
+ return undef;
+ }
+ }
} elsif ($val eq '') {
print STDERR
"$prog:$file:$.: no value given for field \"$field\"\n";
@@ -1025,3 +1115,90 @@ never_called_funcs
$old_env{'foo'} = 'bar';
$internal_test_fields{'foo'} = 'bar';
}
+
+sub
+check_file_result
+{
+ local(*test) = @_;
+
+ return '' if (!defined $test{'file-result'});
+
+ local($why) = '';
+ local($i);
+ local($type, $perm, $uid, $gid, $rest, $c, $len, $name);
+ local(@stbuf);
+
+ for ($i = 0; $i < $test{'file-result'}; $i++) {
+ $val = $test{"file-result:$i"};
+ #
+ # format is: type perm "name"
+ #
+ ($type, $perm, $uid, $gid, $matchType, $rest) =
+ split(' ', $val, 6);
+ $c = substr($rest, 0, 1);
+ $len = index($rest, $c, 1) - 1;
+ $name = substr($rest, 1, $len);
+ $rest = substr($rest, 2 + $len);
+ $perm = oct($perm) if $perm =~ /^\d+$/;
+
+ @stbuf = lstat($name);
+ if (!@stbuf) {
+ $why .= "\texpected $type \"$name\" not created\n";
+ next;
+ }
+ if ($perm ne '*' && ($stbuf[2] & 07777) != $perm) {
+ $why .= "\t$type \"$name\" has unexpected permissions\n";
+ $why .= sprintf("\t\texpected 0%o, found 0%o\n",
+ $perm, $stbuf[2] & 07777);
+ }
+ if ($uid ne '*' && $stbuf[4] != $uid) {
+ $why .= "\t$type \"$name\" has unexpected user-id\n";
+ $why .= sprintf("\t\texpected %d, found %d\n",
+ $uid, $stbuf[4]);
+ }
+ if ($gid ne '*' && $stbuf[5] != $gid) {
+ $why .= "\t$type \"$name\" has unexpected group-id\n";
+ $why .= sprintf("\t\texpected %d, found %d\n",
+ $gid, $stbuf[5]);
+ }
+
+ if ($type eq 'file') {
+ if (-l _ || ! -f _) {
+ $why .= "\t$type \"$name\" is not a regular file\n";
+ } else {
+ local $tmp = &check_output($test{'long-name'}, $name,
+ "$type contents in \"$name\"",
+ $matchType eq 'exact' ? $rest : undef
+ $matchType eq 'pattern' ? $rest : undef);
+ return undef if (!defined $tmp);
+ $why .= $tmp;
+ }
+ } elsif ($type eq 'dir') {
+ if ($rest !~ /^\s*$/) {
+ print STDERR "$prog:$test{':long-name'}: file-result test for directory $name should not have content specified\n";
+ return undef;
+ }
+ if (-l _ || ! -d _) {
+ $why .= "\t$type \"$name\" is not a directory\n";
+ }
+ } elsif ($type eq 'symlink') {
+ if (!-l _) {
+ $why .= "\t$type \"$name\" is not a symlink\n";
+ } else {
+ local $content = readlink($name);
+ if (!defined $content) {
+ print STDERR "$prog:$test{':long-name'}: file-result test for $type $name failed - could not readlink - $!\n";
+ return undef;
+ }
+ local $tmp = &compare_output($test{'long-name'},
+ "$type contents in \"$name\"",
+ $matchType eq 'exact' ? $rest : undef
+ $matchType eq 'pattern' ? $rest : undef);
+ return undef if (!defined $tmp);
+ $why .= $tmp;
+ }
+ }
+ }
+
+ return $why;
+}
diff --git a/bin/ksh/tests/version.t b/bin/ksh/tests/version.t
index b7ea2a8ecac..fe1e7adf227 100644
--- a/bin/ksh/tests/version.t
+++ b/bin/ksh/tests/version.t
@@ -5,5 +5,5 @@ category: pdksh
stdin:
echo $KSH_VERSION
expected-stdout:
- @(#)PD KSH v5.2.13.7 99/01/15
+ @(#)PD KSH v5.2.13.11 99/05/13
---