Commit Graph

179 Commits

Author SHA1 Message Date
Jilles Tjoelker
281fb05e83 sh: Add some testcases for alias expansion. 2010-10-24 16:55:17 +00:00
Jilles Tjoelker
f1bb5f6a87 sh: Allow running 'prove' from tools/regression/bin/sh again
without needing to set special environment variables, testing the 'sh' from
PATH.
2010-10-15 20:01:35 +00:00
David E. O'Brien
7c7a210ab8 Embellish this testcase a little bit to be more clear what the output is
and why.  The first case is correct usage which has but one correct output.
The 2nd and 3rd cases are incorrect usage in which the exact output is
not standardized and various shells give various allowable output.
2010-10-14 23:28:31 +00:00
David E. O'Brien
7cfe69417c Do not assume in growstackstr() that a "precious" character will be
immediately written into the stack after the call.  Instead let the caller
manage the "space left".

Previously, growstackstr()'s assumption causes problems with STACKSTRNUL()
where we want to be able to turn a stack into a C string, and later
pretend the NUL is not there.

This fixes a bug in STACKSTRNUL() (that grew the stack) where:
1. STADJUST() called after a STACKSTRNUL() results in an improper adjust.
   This can be seen in ${var%pattern} and ${var%%pattern} evaluation.
2. Memory leak in STPUTC() called after a STACKSTRNUL().

Reviewed by:	jilles
2010-10-13 23:29:09 +00:00
David E. O'Brien
f3bf9b7a16 Allow one to regression test 'sh' changes without having to install
a potentially bad /bin/sh first.
2010-10-12 18:20:38 +00:00
David E. O'Brien
5f7f699749 Correct regression test to not show a false positive when run as root. 2010-10-11 23:24:57 +00:00
Jilles Tjoelker
8f2dc7de67 sh: Fix exit status if return is used within a loop condition. 2010-09-11 15:07:40 +00:00
Jilles Tjoelker
011d162dd3 sh: Apply variable assignments left-to-right in bltinlookup().
Example:
  HOME=foo HOME=bar cd
2010-09-11 14:15:50 +00:00
Jilles Tjoelker
917fdfb106 sh: Fix 'read' if all chars before the first IFS char are backslash-escaped.
Backslash-escaped characters did not set the flag for a non-IFS character.

MFC after:	2 weeks
2010-09-08 20:35:43 +00:00
Jilles Tjoelker
ad931dfdcb sh: Add simple tests for backslashes in the read builtin. 2010-09-08 18:32:23 +00:00
Jilles Tjoelker
10ea2923a9 sh: Add a test that 'read' leaves the file pointer at the correct place.
Naive buffering would break the common while read x... construct, which did
not appear to be tested yet.
2010-09-03 21:17:33 +00:00
Jilles Tjoelker
83866607fb sh: Weaken builtins/command4 test to only require a nonzero exit status.
This matches what is in POSIX; various other shells use different exit
statuses.

Note that it is still required that there be no output.
2010-08-29 20:53:24 +00:00
Brian Somers
25fdbebeb2 Add a Makefile for tools/regression/bin and support 'all' in
pax/Makefile.

MFC after:	3 weeks
2010-08-29 12:14:53 +00:00
Brian Somers
cd14b45756 Correct an out-by-one error when earlying out ustar filenames that
are too long.  Filenames escaping this test are caught later on,
so the bug doesn't cause any breakage.

Document the correct ustar limitations in pax.  As I have no access
to the IEEE 1003.2 spec, I can only assume that the limitations
imposed are in fact correct.

Add regression tests for the filename limitations imposed by pax.

MFC after:	3 weeks
2010-08-29 11:56:56 +00:00
Jilles Tjoelker
8fdbdb5d50 sh: Remove remnants of '!!' to negate pattern.
This Almquist extension was disabled long ago.

In pathname generation, components starting with '!!' were treated as
containing wildcards, causing unnecessary readdir (which could fail, causing
pathname generation to fail while it should not).
2010-08-22 21:18:21 +00:00
Jilles Tjoelker
394357b2b6 sh: Test that all bytes from 128 to 255 can be used in IFS.
To avoid multibyte issues, this test forces ISO8859-1 charset.

This also passes on stable/8.
2010-08-22 13:09:12 +00:00
Jilles Tjoelker
193da04bd8 sh: Add a test for breaking from a loop outside the current function.
It is unwise to rely on this but I'd like to know if this would break.
2010-08-22 11:04:30 +00:00
Jilles Tjoelker
44510b41ff sh: Add a test for break from a trap action. 2010-08-18 20:26:50 +00:00
Jilles Tjoelker
7ba25e6e69 sh: Reduce unnecessary testsuite failures with other shells. 2010-08-16 22:23:19 +00:00
Jilles Tjoelker
2070b57f64 sh: Split off a more dubious test from parser/heredoc2.0. 2010-08-16 21:14:49 +00:00
Jilles Tjoelker
c06336d428 sh: Get rid of unnecessary non-standard empty lists.
POSIX does not allow constructs like:
  if cmd; then fi
  { }
Add a colon dummy command, except in a test that verifies that such empty
lists do not cause crashes when used as a function definition.
2010-08-16 17:18:08 +00:00
Jilles Tjoelker
ae7c0700dc sh: Fix break/continue/return sometimes not skipping the rest of dot script.
In our implementation and most others, a break or continue in a dot script
can break or continue a loop outside the dot script. This should cause all
further commands in the dot script to be skipped. However, cmdloop() did not
know about this and continued to parse and execute commands from the dot
script.

As described in the man page, a return in a dot script in a function returns
from the function, not only from the dot script. There was a similar issue
as with break and continue. In various other shells, the return appears to
return from the dot script, but POSIX seems not very clear about this.
2010-08-15 21:06:53 +00:00
Jilles Tjoelker
a129ce0167 sh: Test that all bytes from 1 to 127 can be used in IFS.
This also passes on stable/8.
2010-08-15 17:14:05 +00:00
Jilles Tjoelker
c8a3d81f34 sh: Fix heap-based buffer overflow in pathname generation.
The buffer for generated pathnames could be too small in some cases. It
happened to be always at least PATH_MAX long, so there was never an overflow
if the resulting pathnames would be usable.

This bug may be abused if a script subjects input from an untrusted source
to pathname generation, which a bad idea anyhow. Most shell scripts do not
work on untrusted data. secteam@ says no advisory is necessary.

PR:		bin/148733
Reported by:	Changming Sun snnn119 at gmail com
MFC after:	10 days
2010-08-10 22:45:59 +00:00
Jilles Tjoelker
40d2ccc36f sh: Add more testcases for ${var:-word}.
Whether POSIX requires these is unclear.

They pass with 8-stable sh as well.
2010-08-08 17:03:23 +00:00
Jilles Tjoelker
b84d7af7c6 sh: Return 0 from eval if no command was given.
This makes a difference if there is a command substitution.

To make this work, evalstring() has been changed to set exitstatus to 0 if
no command was executed (the string contained only whitespace).

Example:
  eval $(false); echo $?
should print 0.
2010-08-03 22:17:29 +00:00
Jilles Tjoelker
d0a59d85df sh: Add a test for a corner case in eval that already works correctly. 2010-08-01 22:39:07 +00:00
Jilles Tjoelker
6c0c240366 sh: Fix crash due to uninitialized here-document.
If an ; or & token was followed by an EOF token, pending here-documents were
left uninitialized. Execution would crash, either in the main shell process
for literal here-documents or in a child process for expanded
here-documents. In the latter case the problem is hard to detect apart from
the core dumps and log messages.

Side effect: slightly different retries on inputs where EOF is not
persistent.

Note that tools/regression/bin/sh/parser/heredoc6.0 still causes a similar
crash in a child process. The text passed to eval is malformed and should be
rejected.
2010-07-25 22:25:52 +00:00
Jilles Tjoelker
cac4830ce4 sh: Allow a background command consisting solely of redirections.
Example:
  </dev/null &

MFC after:	2 weeks
2010-07-18 12:45:31 +00:00
Jilles Tjoelker
778c4480f4 sh: Remove comment that the comma operator is missing in arithmetic
expansion.

The comma operator is not listed in POSIX.1-2008 XCU 1.1.2.1 Arithmetic
Precision and Operations (referenced by XCU 2.6.4 Arithmetic Expansion) and
is therefore not required.
2010-07-02 21:31:24 +00:00
Jilles Tjoelker
5d91007000 sh: Fix a crash if a heredoc was not properly ended and parsing continued.
Example (in interactive mode):
  cat <<EOF && )
The next command typed caused sh to segfault, because the state for the here
document was not reset.

Like parser_temp, this uses the fact that the parser is not re-entered.
2010-05-30 14:20:32 +00:00
Jilles Tjoelker
ba02a307fe sh: Change interaction of command substitution and here documents.
If a command substitution contains a newline token, this no longer starts
here documents of outer commands. This way, we follow POSIX's idea of the
command substitution being a separate script more closely. It also matches
other shells better and is consistent with newline characters in quotes not
starting here documents.

The extension tested in parser/heredoc3.0 ($(cat <<EOF)\ntext\nEOF\n)
continues to be supported.

In particular, this change allows things like
  cat <<EOF && echo `pwd`
(a `` command substitution after a here document)
which formerly silently used an empty file as the here document, because the
EOF of the inner command "pwd" also forced an empty here document.
2010-05-30 14:11:27 +00:00
Jilles Tjoelker
c1564db05d sh: Recognize "--" in . and exec.
Although "--" historically has not been required to be recognized for
certain special builtins that do not take options in POSIX, some other
implementations recognize options for them, requiring scripts to use "--" or
avoid operands starting with "-".

Operands starting with "-" can be avoided with eval by prepending a space,
and cannot occur with break, continue, exit, return and shift as they only
take numbers, nor with times as it does not take operands. With . and exec,
avoiding "-" is not so easy as it may require reimplementing the PATH
search; therefore the current proposal for POSIX is to require recognition
of "--" for them.

We continue to accept other strings starting with "-" as operands to . and
exec, and also "--" if it is alone to . (which would otherwise be invalid
anyway).
2010-05-28 22:40:24 +00:00
Jilles Tjoelker
bc4c1a0670 sh: Add some simple tests for ., exec and return from . script. 2010-05-28 22:08:34 +00:00
Jilles Tjoelker
f7b46e74b3 sh: Add some simplistic tests for the wait builtin. 2010-05-23 22:10:20 +00:00
Jilles Tjoelker
4710b07ecf sh: Fix pathname expansion with quoted slashes like *\/.
These are git commits 36f0fa8fcbc8c7b2b194addd29100fb40e73e4e9 and
d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 in dash.

Because this is the first code I'm importing from dash to expand.c, add the
Herbert Xu copyright notice which is in dash's expand.c.

When pathname expanding *\/, the CTLESC representing the quoted state was
erroneously taken as part of the * pathname component. This CTLESC was then
seen by the pattern matching code as escaping the '\0' terminating the
string.

The code is slightly different because dash converts the CTLESC characters
to backslashes and removes all the other CTL* characters to allow
substituting glob(3).

The effect of the bug was also slightly different from dash (where nothing
matched at all). Because a CTLESC can escape a '\0' in some way, whether
files were included despite the bug depended on memory that should not be
read. In particular, on many machines /*\/ expanded to a strict subset of
what /*/ expanded to.

Example:
  echo /*"/null"

This should print /dev/null, not /*/null.

PR:		bin/146378
Obtained from:	dash
2010-05-11 23:19:28 +00:00
Jilles Tjoelker
58729dbfc4 sh: Add some simple testcases for pathname expansion. 2010-05-11 22:28:55 +00:00
Jilles Tjoelker
cd06f6e065 Fix error in comment. 2010-05-09 17:15:26 +00:00
Jilles Tjoelker
084d796d16 sh: Add some parser tests.
case1.0 tests POSIX requirements and one more for keywords in case
statements. The others test very special cases of command substitution.

These also work on stable/8.
2010-05-09 17:10:50 +00:00
Jilles Tjoelker
4b7fb70199 Generate some tests for sh's case command from the fnmatch tests.
I'm committing the generated files because I don't like a build dependency
for the sh(1) tests, and they are small and will not change much.
2010-05-09 16:15:40 +00:00
Jilles Tjoelker
941af8d6c6 sh: Fix bug in assignment error test.
The test failed if the command returned nonzero exit status, and it really
should return that.
2010-05-09 16:04:32 +00:00
Jilles Tjoelker
e4b50334ec sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.
This allows doing things like LC_ALL=C some_builtin to run a builtin under a
different locale, just like is possible with external programs. The
immediate reason is that this allows making printf(1) a builtin without
breaking things like LC_NUMERIC=C printf '%f\n' 1.2

This change also affects special builtins, as even though the assignment is
persistent, the export is only to the builtin (unless the variable was
already exported).

Note: for this to work for builtins that also exist as external programs
such as /bin/test, the setlocale() call must be under #ifndef SHELL. The
shell will do the setlocale() calls which may not agree with the environment
variables.
2010-05-05 21:48:40 +00:00
Jilles Tjoelker
e9615a1a0e sh: Add some more tests for ${v#...} and ${v%...}.
These pass on stable/8 as well.
2010-04-23 17:26:49 +00:00
Jilles Tjoelker
348c81a032 sh: Add testcases for double-quotes within quoted ${var+-...} (non-POSIX).
POSIX leaves things like "${var+"word"}" undefined.
We follow traditional ash behaviour here.
Hence, these testcases also work on stable/8.
2010-04-18 22:13:45 +00:00
Jilles Tjoelker
8eac1f9477 sh: On startup of the shell, use PWD from the environment if it is valid.
Unset PWD if it is incorrect and no value for it can be determined.
This preserves the logical current directory across shell invocations.

Example (assuming /home is a symlink):
$ cd
$ pwd
/home/foo
$ sh
$ pwd
/home/foo

Formerly the second pwd would show the physical path (symlinks resolved).
2010-04-17 14:35:46 +00:00
Jilles Tjoelker
e74e09f851 sh: Test that bogus values of PWD are not imported from the environment.
Current versions pass this test trivially by never importing PWD, but I plan
to change sh to import PWD if it is an absolute pathname for the current
directory, possibly containing symlinks.
2010-04-11 20:21:34 +00:00
Jilles Tjoelker
8ef6f9f2d2 sh: Add test for nested arithmetic substitution.
Pre-r206145 sh changes nested arithmetic substitution to parentheses, which
is not always correct, as exercised by this test.
2010-04-04 16:48:33 +00:00
Jilles Tjoelker
07c0b06768 sh: Add test for some associativity in arithmetic. 2010-04-04 16:29:48 +00:00
Jilles Tjoelker
634e9188af sh: Do tilde expansion in substitutions.
This applies to word in ${v-word}, ${v+word}, ${v=word}, ${v?word} (which
inherits quoting from the outside) and in ${v%word}, ${v%%word}, ${v#word},
${v##word} (which does not inherit any quoting).

In all cases tilde expansion is only attempted at the start of word, even if
word contains spaces. This agrees with POSIX and other shells.

This is the last part of the patch tested in the exp-run.

Exp-run done by: erwin (with some other sh(1) changes)
2010-04-03 22:04:44 +00:00
Jilles Tjoelker
5cada825b4 sh: Fix duplicate variable name in test. 2010-04-03 21:56:24 +00:00
Jilles Tjoelker
382e6ae29d sh: Add some testcases for the working parts of tilde expansion. 2010-04-03 21:32:22 +00:00
Jilles Tjoelker
6415a1293f sh: Allow quoting pattern match characters in ${v%pat} and ${v#pat}.
Note that this depends on r206145 for allowing pattern match characters to
have their special meaning inside a double-quoted expansion like "${v%pat}".

PR:		bin/117748
Exp-run done by:	erwin (with some other sh(1) changes)
2010-04-03 21:07:50 +00:00
Jilles Tjoelker
8cf06f5eee sh: Fix various things about expansions:
* remove the backslash from \} inside double quotes inside +-=?
  substitutions, e.g. "${$+\}a}"
* maintain separate double-quote state for ${v#...} and ${v%...};
  single and double quotes are special inside, even in a double-quoted
  string or here document
* keep track of correct order of substitutions and arithmetic

This is different from dash's approach, which does not track individual
double quotes in the parser, trying to fix this up during expansion.
This treats single quotes inside "${v#...}" incorrectly, however.

This is similar to NetBSD's approach (as submitted in PR bin/57554), but
recognizes the difference between +-=? and #% substitutions hinted at in
POSIX and is more refined for arithmetic expansion and here documents.

PR:		bin/57554
Exp-run done by:	erwin (with some other sh(1) changes)
2010-04-03 20:55:56 +00:00
Jilles Tjoelker
cc4b8e985d sh: Add some testcases for the working parts of ${v%...} and ${v#...}. 2010-04-03 20:14:10 +00:00
Jilles Tjoelker
c3bb858966 sh: Do not abort on a redirection error on a compound command.
Redirection errors on subshells already did not abort the shell because
the redirection is executed in the subshell.

Other shells seem to agree that these redirection errors should not abort
the shell.

Also ensure that the redirections will be cleaned up properly in cases like
  command eval '{ shift x; } 2>/dev/null'

Example:
  { echo bad; } </var/empty/x; echo good
2010-03-14 14:24:35 +00:00
Jilles Tjoelker
a4a58620d3 sh: Add test for redirection error on subshell (should not abort). 2010-03-14 13:51:12 +00:00
Jilles Tjoelker
3a64dbc20a sh: Do not abort on a redirection error if there is no command word.
Although simple commands without a command word (only assignments and/or
redirections) are much like special builtins, POSIX and most shells seem to
agree that redirection errors should not abort the shell in this case. Of
course, the assignments persist and assignment errors are fatal.

To get the old behaviour portably, use the ':' special builtin.
To get the new behaviour portably, given that there are no assignments, use
the 'true' regular builtin.
2010-03-13 22:53:17 +00:00
Jilles Tjoelker
45249f152b sh: Add test for assignment errors (e.g. trying to change a readonly var).
We currently ignore readonly status for assignments before regular builtins
and external programs (these assignments are not persistent anyway), so just
check that the readonly variable really is not changed.
The test depends on the command builtin changes for 'command :'.
2010-03-13 22:30:52 +00:00
Jilles Tjoelker
d5c6bd74d9 sh: Add tests for " and $ inside `. 2010-03-12 23:23:46 +00:00
Jilles Tjoelker
0de1173276 sh: Add some testcases for ${v=w}, ${v-w}, ${v+w}.
These expansions, which were already in the Bourne shell, work correctly for
the most part. The testcases are only about the parts that already work
correctly.
2010-03-07 18:43:29 +00:00
Jilles Tjoelker
0019284ae8 sh: Add various testcases for here documents.
They are mainly about expansions in here documents but because all the
testcases are in $() command substitution, we also test that $() command
substitution is recursively parsed (or very close to it).
2010-03-07 15:08:42 +00:00
Jilles Tjoelker
1749097497 sh: Make sure to popredir() even if a function caused an error. 2010-03-06 17:31:09 +00:00
Jilles Tjoelker
544754df6f sh: Make sure to popredir() even if a special builtin caused an error. 2010-03-06 17:09:22 +00:00
Jilles Tjoelker
c848bc18e8 sh: Improve the command builtin:
* avoid unnecessary fork
* allow executing builtins via command
* executing a special builtin via command removes its special properties

Obtained from:	NetBSD (parts)
2010-03-06 16:57:53 +00:00
Jilles Tjoelker
9f21d0a3a5 sh: arith: Add a test for a bug in the dash arith code,
which I plan to import at some point.
Our current code handles it fine and it should stay that way.
2010-02-17 22:25:22 +00:00
Jilles Tjoelker
70293312f8 sh: arith: Test an octal constant as well. 2010-02-17 22:22:20 +00:00
Jilles Tjoelker
91f2621cd1 sh: Make sure the mail2.0 test can actually fail if $MAIL is not touched. 2010-02-08 18:57:18 +00:00
Jilles Tjoelker
5706357661 sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.
These may be NFS mounted, and we should not touch them unless we are going
to do something useful with the information.
2010-02-06 22:57:24 +00:00
Jilles Tjoelker
dc82a6f600 sh: Send the "not found" message for builtin <cmd> to redirected fd 2. 2010-01-03 15:01:38 +00:00
Jilles Tjoelker
b485cf94fb sh: Add a regression test that tries out all arithmetic ops.
MFC after:	1 week
2010-01-03 12:50:27 +00:00
David E. O'Brien
043ccc7cf3 Use t1 & t2 as more symbolic than 'a' and 'b' for the two times. 2010-01-03 12:17:51 +00:00
David E. O'Brien
91212b8c98 Hide expected error output so the 'prove -r' results are easy to read. 2010-01-03 09:31:33 +00:00
David E. O'Brien
a56d32a6a0 Allow to be driven by 'prove -r'. 2010-01-03 09:30:50 +00:00
Jilles Tjoelker
f7cc73afc8 sh: Fix some bugs with backquoted builtins:
- correctly handle error output in $(builtin 2>&1), clarify out1/out2 vs
  output/errout in the code
- treat all builtins as regular builtins so errors do not abort the shell
  and variable assignments do not persist
- respect the caller's INTOFF

Some bugs still exist:
- expansion errors may still abort the shell
- some side effects of expansions and builtins persist
2010-01-01 18:17:46 +00:00
Jilles Tjoelker
0fb60646df sh: Use PATH= assignment in type.
Example:
  PATH=/var/empty; PATH=/bin type ls
2009-12-31 17:44:24 +00:00
Jilles Tjoelker
06a8a57f82 sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH). 2009-12-31 16:13:33 +00:00
Jilles Tjoelker
63ccda7719 sh: arith: Return only 0 and 1 from && and ||.
This agrees with C, POSIX and other shells.
2009-12-30 15:59:40 +00:00
Jilles Tjoelker
29d401c22d sh: Do not run callers' exception handlers in subshells.
Reset the exception handler in the child to main's.

This avoids inappropriate double cleanups or shell duplication when the
exception is caught, such as 'fc' and future 'command eval' and 'command .'.
2009-12-25 20:21:35 +00:00
Jilles Tjoelker
df8d66693f sh: Test ;<newline> as well as ; in the 'for' parser test. 2009-12-06 23:31:23 +00:00
Jilles Tjoelker
772e9b41df Disable job control when running 'sh -i' in the testsuite.
Job control tty manipulations sometimes cause the tests to stop (SIGTTOU
and the like) when run from the 'prove' tool.
2009-11-29 22:58:10 +00:00
Jilles Tjoelker
e1ef314121 Fix some cases where file descriptors from redirections leak to programs.
- Redirecting fds that were not open before kept two copies of the
  redirected file.
    sh -c '{ :; } 7>/dev/null; fstat -p $$; true'
    (both fd 7 and 10 remained open)
- File descriptors used to restore things after redirection were not
  set close-on-exec, instead they were explicitly closed before executing
  a program normally and before executing a shell procedure. The latter
  must remain but the former is replaced by close-on-exec.
    sh -c 'exec 7</; { exec fstat -p $$; } 7>/dev/null; true'
    (fd 10 remained open)

The examples above are simpler than the testsuite because I do not want to
use fstat or procstat in the testsuite.
2009-11-29 22:33:59 +00:00
Jilles Tjoelker
eaa3489312 sh: Ensure the same command input file is on top after executing a builtin.
This avoids weirdness when 'fc -e vi' or the like is done and there is a
syntax error in the file. Formerly an interactive shell tried to execute
stuff after the syntax error and exited.

This should also avoid similar issues with 'command eval' and 'command .'
when 'command' is implemented properly as in NetBSD sh.

Special builtins did not have this problem since errors in them cause the
shell to exit or to reset various state such as the current command input
file.
2009-11-22 14:04:20 +00:00
Jilles Tjoelker
e3c2cd7237 trap: do not consider a bad signal name a fatal error.
POSIX explicitly prescribes this.
Continue processing any other signals and return status 1.
2009-11-21 20:44:34 +00:00
Stefan Farfeleder
80d5dd5fdb Add a test for r199631. 2009-11-21 14:54:35 +00:00
Stefan Farfeleder
ee47d334ef Add a few very basic tests for cd -{L,P} and pwd -{L,P}. 2009-11-21 14:12:51 +00:00
Jilles Tjoelker
7ab07e8ada sh: Allow a newline before "in" in a for command, as required by POSIX. 2009-11-14 22:08:32 +00:00
Jilles Tjoelker
64254a667a sh: Exempt $@ and $* from set -u
This seems more useful and will likely be in the next POSIX standard.

Also document more precisely in the man page what set -u does (note that
$@, $* and $! are the only special parameters that can ever be unset, all
the others are always set, although they may be empty).
2009-10-24 21:20:04 +00:00
Jilles Tjoelker
941538c0f4 Add some tests for ${var?} and set -u. 2009-10-24 20:57:11 +00:00
Jilles Tjoelker
640b70e414 sh: Send the "xyz: not found" message to redirected fd 2.
This also fixes that trying to execute a non-regular file with a command
name without '/' returns 127 instead of 126.
The fix is rather simplistic: treat CMDUNKNOWN as if the command were found
as an external program. The resulting fork is a bit wasteful but executing
unknown commands should not be very frequent.

PR:		bin/137659
2009-10-06 22:00:14 +00:00
Jilles Tjoelker
47e5ae08a1 sh: Disallow mismatched quotes in backticks (...).
Due to the amount of code removed by this, it seems that allowing unmatched
quotes was a deliberate imitation of System V sh and real ksh. Most other
shells do not allow unmatched quotes (e.g. bash, zsh, pdksh, NetBSD /bin/sh,
dash).

PR:		bin/137657
2009-10-01 21:40:08 +00:00
Jilles Tjoelker
e16947f83d sh: Fix crash with empty functions (f() { }) introduced in r196483
Empty pairs of braces are represented by a NULL node pointer, just like
empty lines at the top level.

Support for empty pairs of braces may be removed later. They make the code
more complex, have inconsistent behaviour (may or may not change $?), are
not specified by POSIX and are not allowed by some other shells like bash,
dash and ksh93.

Reported by:	kan
2009-08-28 22:41:25 +00:00
Jilles Tjoelker
840f51bb6d Add some tests for a fixed bug in an uncommitted patch.
(Trying to get syntax errors for sh -c ':; do' and `:; do`.)
2009-08-27 22:23:23 +00:00
Jilles Tjoelker
eb33e843b8 sh: Fix crash when undefining or redefining a currently executing function.
Add a reference count to function definitions.
Memory may leak if multiple SIGINTs arrive in interactive mode,
this will be fixed later by changing SIGINT handling.

PR:		bin/137640
2009-08-23 21:09:46 +00:00
Jilles Tjoelker
886bb28357 Add some tests for r194975 and r194977.
Approved by:	ed (mentor) (implicit)
2009-06-25 17:36:08 +00:00
Jilles Tjoelker
30268dfa3f Designate special builtins as such in command -V and type.
Also document various properties of special builtins that we implement.

Approved by:	ed (mentor) (implicit)
2009-06-24 22:04:04 +00:00
Jilles Tjoelker
97ab37f704 Add test for r190698.
Submitted by:	Eygene Ryabinkin
Approved by:	ed (mentor) (implicit)
2009-06-24 20:22:54 +00:00
Jilles Tjoelker
e2451bddff Add tests for r194774.
Approved by:	ed (mentor) (implicit)
2009-06-23 22:03:56 +00:00
Jilles Tjoelker
57c21ee73a Add tests for r194406 and r194516.
Approved by:	ed (mentor)
2009-06-19 22:15:59 +00:00
Jilles Tjoelker
1251149b3c Add tests for r194127 and r194128.
Approved by:	ed (mentor)
2009-06-14 16:21:51 +00:00
Stefan Farfeleder
912ee8a8a3 Add tests for r193169. 2009-05-31 17:23:27 +00:00