Commit Graph

100 Commits

Author SHA1 Message Date
kre a60600e0af Add a test case for "set -X".
Currently (or when testing any shell that does not support -X) the
test will be skipped (also for [m]ksh (but not ksh93 etc) where there
is an absurdly badly named -X option, skip the new test for them as well.)

When -X appears in /bin/sh, this will verify that it is probably working
(the test is MUCH more gruelling than any rational use of -X would be.)
2017-11-16 19:41:41 +00:00
kre 5c624ca98d Add a new sub-test to validate ~ expansions.
Currently testing ~user is too much effort to contemplate (other than
assuming that it works in order to verify that it works...) so only bare ~
is being tested for now.   Maybe someday...

Right now (@ time of commit), this new test is expected to fail, as ~
expansions are horribly badly broken (have been for months, some forms
for much longer) in all but the simplest of uses.   Fix for that coming
very soon.
2017-10-06 17:05:05 +00:00
kre 5f02c8e934 Make the $'...' syntax tests test what is supposed to work, rather than
what I thought was required (just a couple of changes...).
2017-08-21 00:56:22 +00:00
kre 9985dad5cb Add a few more sub-tests to the $'...' syntax tests.
Remove dome debug noise accidentally left in when the test was first added.
(This still does not matter just yet, but should do soon.)
2017-08-19 21:18:47 +00:00
kre 327a7bf9d0 Add a basic test for $'...' quoting (roughly C ctyle strings).
This test will be skipped on shells (such as /bin/sh in -current as of
the date of this commit) which do not support $'...'

While here fix a typo in a comment (there are probably more...)
2017-08-18 21:22:30 +00:00
kre 21aab71556 PR bin/48498 PR bin/52426
Add two new sh syntax test cases to check for bug fixes for the parser
problems (syntax errors unidentified) reported in the two PRs.

In the latter case, also include some tests that test similar
looking, valid, syntax - to make sure the fix for the PR does not
break code that should not fail.  This is not needed for the earlier
PR as other tests, and just normal parsing, is sufficient.

These tests have been verified to fail with a current /bin/sh and to
pass with the sh updates that are to be committed soon -- and because that
fix is expected within hours, the tests are not marked as expected to
fail, just let them actually fail for now.
2017-07-26 17:50:20 +00:00
kre 56aa5062b1 Add some tests for the (likely forthcoming) pipefail option (modelled
after than in ksh and bash, and the similar thing in zsh) for which a
request has been made for support in the NetBSD sh.

Until the support is committed, the test will be skipped.
2017-07-15 18:52:21 +00:00
kre 8d48762db3 Add basic tests for the forthcoming ',' '++' and '--' operators.
Until the support for those is committed to /bin/sh (and when testing
any other sh that does not support them) the new tests will be skipped.
2017-07-15 18:50:42 +00:00
kre 8b5ee9a5ac Give this test a promotion! This was the test that enabled the sh's
STACKSTRNUL() bug to eventually be found.   Not any of the test cases
directly - the shell running the tests (the same /bin/sh) managed to
build one of the f_variable_syntax sub-tests incorrectly, and that was
enough to eventually allow the bug to be located and squashed.

Like all good promotions, this one comes with increased work, and no extra pay.
2017-06-24 11:09:42 +00:00
kre 82288f99fc NFC: Added some comments (about other comments)
We currently parse var expansions like "${x-"a b c"}" incorrectly
according to POSIX (and ancient tradition) though in a way that is
generally unexpcted (there are 2 quoted strings there, according
to the standard, "${x-" and "}" and 'a b c' is unquoted.)  This has
never been fixed in our sh, as like in many other shells, it is just
a little unbelievable, most people expect that inside the {} is a
whole new ballpark, and everything starts again, and it does in cases
like "${x%"a b c"}" (the newer matching operators.)  There have been
comments in this test explaining how the test is actually testing for
incorrect behaviour for a while now.

But I have since learned of POSIX bug #221 (2010), the resolution of which is
to make the problem case unspecified.  This will not actually become part
of posix until the next major version (POSIX 8) whenever that appears (still
years away I expect) - but at least we now can feel happier about the
way our code works and not worry quite so much about testing that incorrect
code keeps working incorrectly....
2017-06-24 11:06:17 +00:00
kre d9c02a764f Add a new test to verify correct operation when a command substitution
produces output with a very large number of consecutive embegged \n
characters.

This test is currently expected to fail (as of commit date) but is not
marked as atf_expect_fail as the shell should be fixed to avoid the
problem quite soon.   Until then almost anything might happen to the
sh that runs this test (from just plain wrong results, to core dumps,
even possibly the right results, though that's unlikely).

Whie doing this, get rid of the duplicate implementation of the
nested_cmdsubs_in_heredoc test (which was achieving nothing).  I know
how I managed to do that, but on advice of counsel, I ...   (it was
just a harmless waste of a tiny amount of CPU time "compiling" the test,
just like writing "x=0;" on consecutive lines....)
2017-06-16 07:37:41 +00:00
kre a238581652 Fix a really stupid typo/thinko that was preventing many of the
redirect syntax sub-tests from being attempted.
2017-06-16 07:30:32 +00:00
kre e045f926b6 Add two new sub-tests to the c_line_wrapping test case.
These should detect if the errors that caused MAKDEV to fail and
pkgsrc/pkgtools/cwrappers to fail to build (problem detected in
libnbcompat/configure) ever return.

Also fixed one of the other sub-tests so that it actually does what
it should - no idea how this one has been passing, it did not for me
when I was checking the new ones (but perhaps in the interim I have
fixed something else in sh, the problem was in the area I have been
playing, and I originally debugged the new tests using a newer version
of /bin/sh than has yet been committed.)
2017-06-09 23:49:58 +00:00
kre 9817a5b1e5 Paranoia: add a new test case testing that $(( )) results get split
by IFS just the same as any other expansion (split when they should be,
and not when they shouldn't).

Good thing I did ... this discovered a regression in the new expand
code (from an hour or three ago) where quoted arith expansions are
being split, and shouldn't be.  (on the other hand, when they should
be split, they are being split correctly, so that's good...)

No need to worry too much about this, in real life (as opposed to
torture tests) no-one ever puts digits in IFS, and a $(( )) expansion
only ever contains digits, so in practice, splitting never happens,
whether because it is quoted, or just becaue there is nothing to split.

The FreeBSD shell does it correctly (they do word splitting using a
totally different mechanism than we do) - I will find where I missed
testing for quoted expansions later tonight.  Until that happens,
expect a test failure from t_fsplit:split_arith

While here add more comments in the other test casess (one had a comment
already) that our shell parses incorrectly (this is a parsing problem,
not an expansion problem, and the bug has existed forever .. and is
shared by bash).

That is, in an expression like "${var:-word}" the whole thing (including
word) is quoted by the double quotes, and in "${var:-"word"}" the
expansion is quoted, but 'word' is not, the 2nd " (the one before 'w')
ends the opening quote, and the third (before }) turns quoting on
again (it is required that there be an even number of unquoted quotes inside
a ${} expression, so things like "${var:-"word} are simply invalid.)
Another way of saying this, is that if the { is quoted (for which the
only way is using " to get to this kind of expansion at all) the }
must also be quoted (" quoted).  There is no quote nesting here.

This also means that in "${var:-'word'}" the single quotes are just
characters, they are quoted by the "" that surround them, just as in
"a 'string' containing quotes", but "${var:-"'word'"}} is valid and
contains a single quoted word.

Note that this is different than the patetrn-match/trim expansions
( ${var%pattern} etc) where any surrounding quotes do not affect the
pattern, and all forms of quoting can be used in it - but it always
parses as a pattern, and is never subject to filename expansion, so
a '*' in it that is to mean "match any string" does not need special
quoting to avoid it expanding to file names, regardless of whether
the ${var%*} is quoted or not, but a * that is to be matched as a
character literally does need to be quoted.

I will probably file a PR about this bug sometime, but as it is
very old, and doesn't every seem to bother anyone (and is shared by
bash) there isn't any big hurry to open yet another verry messy can
of excrement to fix it...

This does mean that the FreeBSD shell "fails" some of our tests.
(The test is wrong, their shell is correct.)
2017-06-03 15:15:49 +00:00
kre a12c6cfae6 Complete the special request by quoting chapter & verse from POSIX
as to why ${011} is ${11} and not ${9} (that is, why we interpret it
that way, the "why could it not be the other way?" is just "because
that is not how it was ever implemented".
2017-06-03 14:45:59 +00:00
kre 25950655c8 By special request, add a check that ${011} is ${11} not ${9} (etc) and
that ${08} is not an error.
2017-06-03 11:23:01 +00:00
kre 3806d6f4e4 Add some extra sub-tests checking splitting of ${#var} - just for my
piece of mind (to verify I was not breaking anything here.)

Also added some commentary better explaining why one of the tests of splitting
quoted variable expansions is almost certainly incorrect (both the tests,
and what sh does) ... though bash does the same as us, so all is not lost!
2017-06-03 10:27:05 +00:00
kre f0acc68ec6 Add a new test case "nested_arith" (that is, things like $(( 1 + $(( 2 )) ))
which will currently fail (some of the sub-tests, but this one stops on
first failure, so the test simply fails.)  This will be corrected later today.
2017-06-02 01:50:48 +00:00
kre 3782bd48c9 Add 3 new subtests to the shell_params test case. These test currently
broken behaviour (so for now, 3 of 15 subtests will fail).   This will
be corrected later today.
2017-06-02 01:48:13 +00:00
kre 06627d31e7 One more weird test of parsing (and correctly understanding) words
whose meaning is defined entirely by context.

For those who read commit messages, and want a (small) challenge,
work out where (and what) to insert as punctuation/operator chars
in the following to produce 3 ines of output, and what those will be:

	for in in in do in do case in in in echo do do echo in esac done

(There are no comments, quotes of any kind, or any kind of sub-shell,
including cmd substitutions)  With correct non alpha-numeric chars added,
it works.
2017-06-02 01:45:06 +00:00
kre bdbf3d66ba Guard against EVN being set, and possibly referencing an unset
variable, when we are running tests with sh -u
2017-06-02 01:38:44 +00:00
kre 6768e34b73 Add a new test case wrap_strip based upon strip (ie: cut&paste.. to start)
but with \ newline line continuations inserted at strange places.

For the shell as it is today, since strip passes, wrap_strip should
automaticallty pass as well (and does), as the \ newline combination
is simply removed, producing identical input to that of strip.

However, for accurate line counting ($LINENO: coming soon) newlines (no
matter the context) cannot simply "go away" - we have to know where they
occur(ed) (perhaps long after the text was read)  so we know what line
number we are actually processing.   This new test case is (perhaps just
part) of future-proofing that the modified code does not break anything.
2017-05-29 22:27:47 +00:00
kre ff906b151f Skip the test of non-posix behaviour if we are deliberately trying
to be posix compatible (POSIXLY_CORRECT is set).
2017-05-27 13:11:50 +00:00
kre 79115595d5 Add a test of sh syntax & parsing (first attempt anyway.) 2017-05-20 16:35:55 +00:00
kre 22a6d2dd08 More test sub-cases for the dollar_hash ( ${#...} ) test.
Upi really (really!) don't want to know!

Also, add a comment (in another section) and avoid giving messages
to atf_fail that include newlines - AFT really doesn't like that.
Instead, convert the \n's to ;'s so at least the content is retained.
2017-05-15 19:53:40 +00:00
kre c70ddc9b88 Add a test for opening files with exec "when" in posix mode (close-on-exec
should not get set.)  While here, remove the (unused) runhelper() function.
2017-05-14 17:28:46 +00:00
kre a30f469fdd Add a test case for the various ways that ${xxx} expansions, which
contain a # character, can get parsed (which amounts to 86 extra checks,
any Australian can tell you why I decided to stop there and not add one
more...)
2017-05-14 11:28:49 +00:00
kre a787cac634 PR bin/52090 - the $* tests are no longer expected to fail. 2017-03-20 11:48:41 +00:00
kre 0c0af3f55d Add tests for the $(( )) assignment operators PR bin/50958 2017-03-20 11:32:51 +00:00
kre 86dd15a646 PR bin/52090
Add 5 new test cases to test various ways that $* can be expanded.
Currently 3 of the 5 are marked as "expected to fail" because of the
bug in this PR.
2017-03-19 20:29:30 +00:00
kre 706a2d4f09 Add new test case in to check (coming) bug fix for newly discovered
ash based shell bug
	echo ${unset_var##$(echo a)}$(echo b)
should say "b" but instead says "a" ... the first "echo a" is not
evaluated because it cannot possibly match an unset variable, but is
not removed from the list of command substitutions, when the shell
needs to execute the 2nd cmdsub, "echo b" should be at the head of
the list, but isn't, "echo a" is still there...

This test should fail (for now) - should show 4 of 40 subtests failing.
It isn't marked as atf_expect_fail as the fix for this will be coming
later today (I will just wait at least 1 b5 build cycle so the failure
can be observed).

Detecting the bug, and the fix, are from FreeBSD.
2017-03-12 00:39:47 +00:00
sevan efb5f2c4e7 PR bin/4841 was filed regarding the handling of blank lines when cat was invoked
with -be, the test case however did not utilise any blank lines, only testing
that the text was aligned.
2016-06-26 22:50:46 +00:00
sevan 17a9d10433 Add a unit test for PR bin/51250 called se_output. se_output checks the output of cat
when invoked with '-se', to ensure that a '$' is printed on blank lines.
2016-06-16 01:04:58 +00:00
kre c80063823d Use valid (standard) shell syntax, in anticipation of /bin/sh enforcing
it sometime soon (perhaps.)
2016-05-17 09:05:14 +00:00
kre b752c81378 Add a new test case to validate N>&N redirect disables close-on-exec.
OK christos@
2016-05-15 15:44:43 +00:00
kre cd13213fdd Add another test for the 48875 fix fallout... 2016-05-14 00:33:02 +00:00
kre e588572b24 Grunge. I know I fixed this typo before... must have been in a different
couy of the test.
2016-05-12 14:25:11 +00:00
kre 2f35ca415e Verify that questionable characters don't have bad associates.
ok christos@
2016-05-12 13:34:23 +00:00
kre 5ab36d6022 Add a test for fd redirections on functions in loops (the etcupdate issue)
and also fix a quoting bug which was causing a test to fail, though
ATF was ignoring (an ATF bug to be investigated later.)

OK christos@
2016-05-11 17:43:17 +00:00
kre 07e424459c PR bin/48875 PR bin/51123 This adds tests more that verify fide descriptor
redirection works correctly (including that the bugs reported in those PRs
are fixed.)  Note that the tests for 48875 are slow, so one of the new
test cases ends up running > 25 seconds (just doing sleeps) - each individual
test is just a few seconds, but there are several of them.

OK christos@
2016-05-09 22:34:37 +00:00
kre 44b3998960 Remove the trap_zero__explicit_return test case - it was testing undefined
behaviour (and failed with the NetBSD shell, and was marked as expected to
fail.)   Other shells do different things.   The test was worthless, and is
now gone.

OK christos@
2016-05-07 23:51:30 +00:00
christos 28ac500a6d More redirect tests, in particular, tests for redirects to/from
file descriptors outside the 0..9 range, and complex fd
reassignments.  Also test that the shell can cope with the
value of ulimit -n changing (downwards, up is harmless)
(Freom kre@)
2016-05-02 01:47:14 +00:00
christos c6dfc962be use "" so ${TEST_SH} is expanded. 2016-04-29 18:29:17 +00:00
christos 2e4e2294f3 Add a test case for here documents positioned outside `` with the
redirect operator inside the ``.   Move the one similar test using
$( ) into its own test case (and expand that test as well.
The `` case was omitted before, as no shells (including NetBSD) were
parsing it correctly,  Now the NetBSD shell does, so ... (from kre@)
2016-04-04 12:40:13 +00:00
christos 9f1b8a789b Avoid leaving turds in /tmp. (from kre@) 2016-03-31 16:22:54 +00:00
christos 87a25451df When embedding a command in a subshell "( ... )" avoid accidentally
producing (( (when the cmd starts with a '(' as that as a reserved
sequence (according to posix) and some shells do treat it specially.
So, force a space after the enclosing '(' to avoid the problem.
For symmetry, put a space before the concluding ')' as well, though
there is nothing special about )). (from kre@)
2016-03-31 16:22:27 +00:00
christos de3efde923 Added lots more end delimiter tests (some weird cases...). Also
use printf %s instead of echo, as there are embedded \ chars in
some of the strings, and some other (nameless) shells insist on
treating \ in the args to echo as something special... (from kre@)
2016-03-31 16:21:52 +00:00
christos 3f90444865 PR bin/51027 - tests for shell positional parameters, including
testing that $10 is correctly parsed as ${1}0 and not as ${10}.
More than that though. (from kre@)
2016-03-31 16:21:10 +00:00
christos 54d4333f65 Added tests collected by Sven Mascheck
http://www.in-ulm.de/~mascheck/various/cmd-subst/
which test cases of ')' being embedded in command substitutions.
(from kre@)
2016-03-31 16:20:39 +00:00
christos 8f7ab1d41a Don't confuse more capable shells by writing operator combinations
that could be interpreted as something different. That is, for our
shell +4++3 is just (+4)+(+3) and works fine. But others treat ++
as the increment operator.  Same for --. Sprinkle spaces to taste.
(from kre@)
2016-03-31 16:19:52 +00:00