1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-01 12:56:04 +02:00
zsh/Test
brian m. carlson f7a417388c 47794: exec: run final pipeline command in a subshell in sh mode
zsh typically runs the final command in a pipeline in the main shell
instead of a subshell.  However, POSIX specifies that all commands in a
pipeline run in a subshell, but permits zsh's behavior as an extension.
The default /bin/sh implementations on various Linux distros and the
BSDs always use a subshell for all components of a pipeline.

Since zsh may be used as /bin/sh in some cases (such as macOS Catalina),
it makes sense to have the common sh behavior when emulating sh, so do
that by checking for being the final item of a multi-item pipeline and
creating a subshell in that case.

From the comment above execpline(), we know the following:

 last1 is a flag that this command is the last command in a shell that
 is about to exit, so we can exec instead of forking.  It gets passed
 all the way down to execcmd() which actually makes the decision.  A 0
 is always passed if the command is not the last in the pipeline. […]
 If last1 is zero but the command is at the end of a pipeline, we pass
 2 down to execcmd().

So there are three cases to consider in this code:

• last1 is 0, which means we are not at the end of a pipeline, in which
 case we should not change behavior.
• last1 is 1, which means we are effectively running in a subshell,
 because nothing that happens due to the exec is going to affect the
 actual shell, since it will have been replaced.  So there is nothing
 to do here.
• last1 is 2, which means our command is at the end of the pipeline, so
 in sh mode we should create a subshell by forking.

input is nonzero if the input to this process is a pipe that we've
opened.  At the end of a multi-stage pipeline, it will necessarily be
nonzero.

Note that several of the tests may appear bizarre, since most developers
do not place useless variable assignments directly at the end of a
pipeline.  However, as the function tests demonstrate, there are cases
where assignments may occur when a shell function is used at the end of
a command.  The remaining assignment tests simply test additional cases,
such as the use of local, that would otherwise be untested.
2021-04-10 17:56:39 -05:00
..
.cvsignore unposted: cvsignore VIM *.swp files 2003-05-05 06:14:49 +00:00
.distfiles 33047: use git to simplify massively source distribution file selection 2014-08-23 21:01:58 +01:00
A01grammar.ztst 45616: Remove token from count argument to repeat 2020-03-26 20:54:37 +00:00
A02alias.ztst 45004: Fix typos in comments 2019-12-11 02:37:39 +00:00
A03quoting.ztst 41485: test for previous fix 2017-08-03 21:50:18 +01:00
A04redirect.ztst 46026: Add CLOBBER_EMPTY option. 2020-06-09 18:07:01 +01:00
A05execution.ztst 47296 (+ unposted additional tests and comments): 'repeat' loops: Let the repeat count use $?. 2020-08-08 06:11:00 +00:00
A06assign.ztst 42101 (tweaked): assigning shell status to array was broken 2018-05-11 09:29:14 +01:00
A07control.ztst 34077: further tests for return status from "for" loops 2015-01-02 21:16:41 +00:00
B01cd.ztst 46168: Update $PWD and call chpwd hook after normalizing path 2020-07-03 21:17:58 -05:00
B02typeset.ztst 44296: "typeset Q= {X}" crashed the shell. 2019-05-14 12:10:10 +01:00
B03print.ztst 48202 + 48366: Fix handling of NUL bytes in zexpandtabs multibyte version 2021-04-01 09:50:52 +02:00
B04read.ztst 29731: fix read -AE, test that and read -Ae 2011-08-28 17:06:27 +00:00
B05eval.ztst 25409: fix eval's use of lastval 2008-08-06 19:51:04 +00:00
B06fc.ztst 33686: set PS1 before pattern-matching for it 2014-11-13 09:27:14 -08:00
B07emulate.ztst 47794: exec: run final pipeline command in a subshell in sh mode 2021-04-10 17:56:39 -05:00
B08shift.ztst 32246: option "shift -p" pops arguments from end of array 2014-01-11 19:31:29 +00:00
B09hash.ztst 39949: Special case for "-" in directory names. 2016-11-15 18:01:32 +00:00
B10getopts.ztst 44469: correct error on missing option argument 2019-07-01 09:42:22 +01:00
B11kill.ztst 45463: test: kill: Document why we use SIGURG 2020-02-18 19:35:18 +00:00
B12limit.ztst 45584, 45620: zsh/rlimits: Skip the tests for this module when it wasn't compiled in. 2020-03-27 01:14:42 +00:00
B13whence.ztst 45640: Fix new test when ${PWD}'s value contains symlinks. 2020-03-28 00:46:51 +00:00
C01arith.ztst 46079: Ignore double quotes in math expressions. 2020-06-23 12:17:32 +01:00
C02cond.ztst 45470: C02cond: Simplify '-N cond' test 2020-03-11 21:17:12 -05:00
C03traps.ztst 45373: Fix ERR_EXIT bug in else branch of if. 2020-02-02 18:05:47 +00:00
C04funcdef.ztst Copy functions using functions -c old new. 2019-08-03 19:53:51 +01:00
C05debug.ztst clean up test temporary files 2008-12-29 04:24:36 +00:00
D01prompt.ztst 47352 (+ extra test cases): fix %<n>K prompt expansion 2020-09-10 07:34:56 +01:00
D02glob.ztst 47895: Remove trailing spaces from "print -ac" output lines. 2021-02-04 17:52:22 -08:00
D03procsubst.ztst 46183: New XFail test: external command with =(...) on LHS of pipeline cleans up its tempfiles. 2020-07-12 15:57:49 +00:00
D04parameter.ztst 48379: Make the parameter expansion subscript flags parse error message, "error in flags", identify the location of the parse error. 2021-04-08 02:19:39 +00:00
D05array.ztst 23562: add KSH_ZERO_SUBSCRIPT option and leave off by default 2007-06-18 13:25:03 +00:00
D06subscript.ztst 45004: Fix typos in comments 2019-12-11 02:37:39 +00:00
D07multibyte.ztst unposted: Improve documentation and add regression test for workers/47745 2021-03-23 00:26:21 -05:00
D08cmdsubst.ztst 45004: Fix typos in comments 2019-12-11 02:37:39 +00:00
D09brace.ztst 41420: "{.." wasn't check for brace expansion properly 2017-07-13 17:20:24 +01:00
E01options.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
E02xtrace.ztst 45601: fix another status in new function -T test 2020-03-25 15:55:19 +09:00
Makefile.in 44523: Add ZTST_handler capability. 2019-07-16 10:57:35 +01:00
P01privileged.ztst 45542: P01privileged: Use test-directory owner for auto-determined EUID/EGID 2020-04-01 17:05:26 -05:00
README Add unsetopt/PRIVILEGED tests 2020-02-14 16:06:58 -06:00
V01zmodload.ztst 45591 (Cf. 45587, 45620): In the test suite, centralize testing that compiled modules can be loaded successfully. 2020-03-27 01:14:42 +00:00
V02zregexparse.ztst 37181: consistent use of zmodload and corresponding ZTST_unimplemented or ZTST_skip 2015-11-21 23:56:25 -08:00
V03mathfunc.ztst 43275: Add log2 to match func 2018-08-13 09:36:55 +01:00
V04features.ztst 37181: consistent use of zmodload and corresponding ZTST_unimplemented or ZTST_skip 2015-11-21 23:56:25 -08:00
V05styles.ztst 48432 and enable test: fix quotiing of zstyle -L for zstyle -e 2021-04-09 21:01:37 +01:00
V06parameter.ztst Revert 40626 which broke tests. 2017-02-26 06:11:19 +00:00
V07pcre.ztst unposted: Fix syntax error introduced in 45591. 2020-03-28 00:56:22 +00:00
V08zpty.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
V09datetime.ztst 47494, 47495: Add -n option to strftime 2020-10-25 23:06:02 +01:00
V10private.ztst 45004: Fix typos in comments 2019-12-11 02:37:39 +00:00
V11db_gdbm.ztst Improve comment at top of GDBM test 2017-03-21 09:57:00 +00:00
V12zparseopts.ztst 47905: Add leading '-' to zparseopts option parsing errors 2021-02-13 00:54:59 +01:00
V13zformat.ztst 45137: zformat: Allow the specifying minimum width and a dot with an empty maximum width. 2019-12-26 04:21:47 +00:00
V14system.ztst 46152: zsh/system: Re-allow '0' timeout in zsystem flock 2020-07-11 00:14:58 -05:00
W01history.ztst unposted: Add smoke test for :P history modifier. 2019-11-19 17:57:13 +00:00
W02jobs.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
X02zlevi.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
X03zlebindkey.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
X04zlehighlight.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
Y01completion.ztst 48413: Fix _expand completion test 2021-04-06 13:59:43 +02:00
Y02compmatch.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
Y03arguments.ztst 47849: do not skip tests requiring zpty on Cygwin 2021-01-20 13:49:42 +09:00
Z01is-at-least.ztst 47314: is-at-least false positive (5.8.0.2 / 5.8) 2020-08-16 14:24:29 +00:00
Z02zmathfunc.ztst 48147/0002: zmathfunc: Fix bug where the exit code would be non-zero if the expression evaluted to zero. 2021-03-07 21:58:13 +00:00
comptest 48413: Fix _expand completion test 2021-04-06 13:59:43 +02:00
list-XFails 45290: New helper script for listing XFail tests. 2020-01-13 22:48:55 +00:00
runtests.zsh 24316: count skipped tests differently from successes and failures. 2007-12-25 01:40:16 +00:00
ztst.zsh 46102: test harness: Make the XPass message distinct from the Fail message. 2020-06-25 10:24:11 +00:00

There are now different sections, expressed by the first letter in the
scripts names:

 A: basic command parsing and execution
 B: builtins
 C: shell commands with special syntax
 D: substititution
 E: options
 P: privileged (needs super-user privileges)
 V: modules
 W: builtin interactive commands and constructs
 X: line editing
 Y: completion
 Z: separate systems and user contributions

You will need to run these by using `make test' in the Test subdirectory of
the build area for your system (which may or may not be the same as the
Test subdirectory of the source tree), or the directory above.  You can get
more information about the tests being performed with
  ZTST_verbose=1 make check
(`test' is equivalent to `check') or change 1 to 2 for even more detail.

Individual or groups of tests can be performed with
  make TESTNUM=C02 check
or
  make TESTNUM=C check
to perform just the test beginning C02, or all tests beginning C,
respectively.

Instructions on how to write tests are given in B01cd.ztst, which acts as a
model.