aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests/builtins
Commit message (Collapse)AuthorAgeFilesLines
* sh tests: Update $LINENO tests after $FreeBSD$ removalMark Johnston2023-08-232-4/+4
| | | | Fixes: d0b2dbfa0ecf ("Remove $FreeBSD$: one-line sh pattern")
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-16175-175/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sh: nullify ENV in testsPiotr Pawel Stefaniak2022-08-202-2/+2
| | | | | | | | This is to avoid loading .shrc which may contain commands that would result in output different than expected. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D35876
* sh: accept fc options grouped behind one '-'Piotr Pawel Stefaniak2022-08-204-0/+14
| | | | | | | | | | | | | | | As per Utility Syntax Guidelines, accept both forms: -l -n and -ln. To do that, anticipate the source string for the next option that will be parsed by nextopt(). It's not always *argptr, sometimes it is nextopt_optptr. To simplify the check for not_fcnumber, slightly modify nextopt() to always nullify nextopt_optptr in cases where it would have been set to point to a NUL character. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D35836
* read builtin: Empty variables on timeoutBryan Drewery2021-09-243-0/+27
| | | | | | | | This matches how a non-timeout error is handled. Reviewed by: jilles MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D31876
* sh: Write absolute path in command -vV and typeJilles Tjoelker2020-09-014-0/+42
| | | | | | | | | | | | POSIX is pretty clear that command -v, command -V and type shall write absolute pathnames. Therefore, we need to prepend the current directory's name to relative pathnames. This can happen either when PATH contains a relative pathname or when the operand contains a slash but is not an absolute pathname. Notes: svn path=/head/; revision=365037
* sh: Don't treat % specially in CDPATHJilles Tjoelker2018-07-152-0/+25
| | | | Notes: svn path=/head/; revision=336320
* sh: Don't have [ match any [[:class:]]Jilles Tjoelker2018-04-292-0/+6
| | | | | | | | Submitted by: Robert Elz MFC after: 3 days Notes: svn path=/head/; revision=333092
* Fix a few speelling errorsEitan Adler2017-12-281-1/+1
| | | | | | | | | | - man pages - bin/sh Reviewed by: jilles Notes: svn path=/head/; revision=327281
* sh: Ignore error when cd writes the directory actually switched to.Jilles Tjoelker2017-06-252-0/+7
| | | | | | | | | | | | If CDPATH is used non-trivially or the operand is "-", cd writes the directory actually switched to. (We currently do this only in interactive shells, but POSIX requires this in non-interactive shells as well.) As mentioned in Austin group bug #1045, cd shall not return an error while leaving the current directory changed. Therefore, ignore any write error. Notes: svn path=/head/; revision=320340
* sh: Fix '-' from quoted arithmetic in case/glob pattern range.Jilles Tjoelker2017-05-142-0/+11
| | | | | | | | | | | It does not make much sense to generate the '-' in a pattern bracket expression using arithmetic expansion, but it does not make sense to forbid it either. Try to avoid reprocessing the string if it is unnecessary. Notes: svn path=/head/; revision=318269
* sh: Add test for arithmetic expansion in [x-y] pattern range.Jilles Tjoelker2017-05-132-0/+11
| | | | | | | | | | | It does not make much sense to generate the '-' in a pattern bracket expression using arithmetic expansion, but it does not make sense to forbid it either. This test already passes. Notes: svn path=/head/; revision=318258
* sh: Fix INTOFF leak after a builtin with different locale settings.Jilles Tjoelker2017-05-072-0/+6
| | | | | | | | | | | After executing a builtin with different locale settings such as LC_ALL=C true SIGINT handling was left disabled indefinitely. MFC after: 1 week Notes: svn path=/head/; revision=317912
* sh: Add some tests for non-standard features of the echo builtin.Jilles Tjoelker2016-09-024-0/+21
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=305305
* Back out non-collating [a-z] ranges.Andrey A. Chernov2016-07-141-1/+6
| | | | | | | | | | | Instead of changing the whole course to another POSIX-permitted way for consistency and uniformity I decide to completely ignore missing regex fucntionality and focus on fixing bugs in what we have now, too many small obstacles we have choicing other way, counting ports. Corresponding libc changes are backed out in r302824. Notes: svn path=/head/; revision=302829
* After removing collation for [a-z] ranges in r302512, do it here too.Andrey A. Chernov2016-07-131-6/+1
| | | | | | | Approved by: jilles Notes: svn path=/head/; revision=302712
* Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installedEnji Cooper2016-05-041-168/+165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after r298107 Summary of changes: - Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that namespacing is kept with FILES appropriately, and that this shouldn't need to be repeated if the namespace changes -- only the definition of PACKAGE needs to be changed - Allow PACKAGE to be overridden by callers instead of forcing it to always be `tests`. In the event we get to the point where things can be split up enough in the base system, it would make more sense to group the tests with the blocks they're a part of, e.g. byacc with byacc-tests, etc - Remove PACKAGE definitions where possible, i.e. where FILES wasn't used previously. - Remove unnecessary TESTSPACKAGE definitions; this has been elided into bsd.tests.mk - Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES; ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk. - Fix installation of files under data/ subdirectories in lib/libc/tests/hash and lib/libc/tests/net/getaddrinfo - Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup) Document the proposed changes in share/examples/tests/tests/... via examples so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of replacing FILES. share/mk/bsd.README didn't seem like the appropriate method of communicating that info. MFC after: never probably X-MFC with: r298107 PR: 209114 Relnotes: yes Tested with: buildworld, installworld, checkworld; buildworld, packageworld Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=299094
* MFHGlen Barber2016-04-113-7/+7
|\ | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=297824
| * sh: Fix some unquoted variables in tests.Jilles Tjoelker2016-04-093-7/+7
| | | | | | | | | | | | | | | | The builtins/getopts1.0 test failed if a single-character file existed in the current directory. Notes: svn path=/head/; revision=297752
* | MFHGlen Barber2016-04-042-0/+11
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=297567
| * sh: Fix use-after-free if a trap replaces itself.Jilles Tjoelker2016-03-282-0/+11
| | | | | | | | | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=297360
* | MFHGlen Barber2016-03-103-0/+16
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296625
| * DIRDEPS_BUILD: Connect MK_TESTS.Bryan Drewery2016-03-091-0/+11
| | | | | | | | | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=296587
| * sh: Add test for 'set -o nolog'.Jilles Tjoelker2016-03-092-0/+5
| | | | | | | | | | | | | | | | The option does not do anything so check that the output of 'set +o' is different. Notes: svn path=/head/; revision=296578
* | Fix build.Glen Barber2016-02-031-1/+0
| | | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295215
* | First pass to fix the 'tests' packages.Glen Barber2016-02-021-0/+4
|/ | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295171
* sh: Clean a readonly local, even if the variable does not exist outside.Jilles Tjoelker2016-01-222-0/+11
| | | | | | | | If a local variable has been made read-only, this should not prevent its removal when the function returns. Notes: svn path=/head/; revision=294593
* sh: Add already working test for local-readonly interaction.Jilles Tjoelker2016-01-222-0/+11
| | | | Notes: svn path=/head/; revision=294582
* sh: Update associated state when restoring locals while leaving a function.Jilles Tjoelker2016-01-102-0/+16
| | | | | | | | | | | Some variables like PATH call a function when modified. Make sure to call this also when leaving a function where such a variable was made local. Make sure to restore local variables before shellparam, so getopts state is not clobbered. Notes: svn path=/head/; revision=293635
* sh: Add a test for 'cd -'.Jilles Tjoelker2016-01-073-0/+11
| | | | | | | | | Redirect 'cd -' output to /dev/null since POSIX requires it to write the new directory name even if not interactive, but we currently only write it if interactive. Notes: svn path=/head/; revision=293371
* sh: Ensure OPTIND=1 in subshell without forking does not affect outer env.Jilles Tjoelker2016-01-072-0/+12
| | | | | | | | | | | | | | | Command substitutions containing a single simple command and here-document expansion are performed in a subshell environment, but may not fork. Any modified state of the shell environment should be restored afterward. The state that OPTIND=1 had been done was not saved and restored here. Note that the other parts of shellparam need not be saved and restored, since they are not modified in these situations (a fork is done before such modifications). Notes: svn path=/head/; revision=293359
* sh: Link tests/builtins/getopts9.0 to the build.Jilles Tjoelker2016-01-031-0/+1
| | | | | | | This was forgotten in r273700. Notes: svn path=/head/; revision=293120
* sh: Fix read with escaped IFS characters at the end.Jilles Tjoelker2015-08-302-0/+11
| | | | | | | | Characters escaped with a backslash must be treated as if they were not in IFS. This includes stripping trailing IFS characters. Notes: svn path=/head/; revision=287308
* sh: Fix out of bounds read when there is no ] after a [:class:].Jilles Tjoelker2015-08-252-0/+10
| | | | | | | | | | | | | | The initial check for a matching ] was incorrect if a ] may be consumed by a [:class:]. The subsequent loop assumed that there must be a ]. Remove the initial check and make the loop cope with a missing ]. Found with afl-fuzz. MFC after: 1 week Notes: svn path=/head/; revision=287148
* sh: Backslash-newline should not affect field splitting in read builtin.Jilles Tjoelker2015-08-162-0/+18
| | | | | | | This was originally broken in r212339 in 2010. Notes: svn path=/head/; revision=286826
* sh: Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap ↵Bryan Drewery2015-04-183-0/+27
| | | | | | | | | | | | | | | | | | | | n n...'. The parser considered 'trap exit INT' to reset the default for both EXIT and INT. This beahvior is not POSIX compliant. This was avoided if a value was specified for 'exit', but then disallows exiting with the signal received. A possible workaround is using ' exit'. However POSIX does allow this type of behavior if the parameters are all integers. Fix the handling for this and clarify its support in the manpage since it is specifically allowed by POSIX. Differential Revision: https://reviews.freebsd.org/D2325 Reviewed by: jilles MFC after: 2 weeks Notes: svn path=/head/; revision=281718
* sh: Make getopts memory-safe if with changing arguments.Jilles Tjoelker2014-10-262-0/+12
| | | | | | | | | | | | | | | POSIX does not permit to continuing a getopts loop with different arguments. For parsing the positional parameters, we handle this case by resetting the getopts state when the positional parameters are changed in any way (and the getopts state is local to a function). However, in the syntax getopts <optstring> <var> <arg...>, changes could lead to invalid memory access. In the syntax getopts <optstring> <var> <arg...>, store a copy of the arguments and continue to use them until getopts is reset. Notes: svn path=/head/; revision=273700
* sh: Fix break/continue/return in multiline eval.Jilles Tjoelker2014-10-123-0/+18
| | | | | | | | Example: eval $'return\necho bad' Notes: svn path=/head/; revision=272983
* sh: Fix LINENO and prompt after $'\0 and newline.Jilles Tjoelker2014-10-033-0/+9
| | | | Notes: svn path=/head/; revision=272482
* Convert bin/sh/tests to ATFEnji Cooper2014-08-131-3/+7
| | | | | | | | | | | | | | | | The new code uses a "test discovery mechanism" to determine what tests are available for execution The test shell can be specified via: kyua test -v test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh Sponsored by: EMC / Isilon Storage Division Approved by: jmmv (mentor) Reviewed by: jilles (maintainer) Notes: svn path=/head/; revision=269902
* sh: Allow arbitrarily large numbers in break and continue.Jilles Tjoelker2014-07-202-0/+9
| | | | | | | The argument is capped to loopnest, so strtol()'s [ERANGE] can be ignored. Notes: svn path=/head/; revision=268927
* Don't install locale1.0 if MK_NLS == no.Jilles Tjoelker2014-07-081-0/+2
| | | | | | | | | | | | | | | The test locale1.0 depends on locale support; it is meaningless without a working LC_MESSAGES. I added an OptionalObsoleteFiles.inc entry. PR: 181151 Submitted by: Garrett Cooper (original version) MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=268429
* sh: In getopts, unset OPTARG where POSIX says we should.Jilles Tjoelker2014-05-103-0/+14
| | | | Notes: svn path=/head/; revision=265849
* sh: Add new tests to the Makefile.Jilles Tjoelker2014-05-101-0/+2
| | | | Notes: svn path=/head/; revision=265846
* sh: Don't discard getopts state on unknown option or missing argument.Jilles Tjoelker2014-05-102-0/+13
| | | | | | | | | | When getopts finds an invalid option or a missing option-argument, it should not reset its state and should set OPTIND as normal. This is an old ash bug that was fixed long ago in dash. Our behaviour now matches most other shells. Notes: svn path=/head/; revision=265844
* sh: Send getopts error messages to stderr, not stdout.Jilles Tjoelker2014-05-091-1/+1
| | | | | | | Adjust a testcase for this change. Notes: svn path=/head/; revision=265773
* sh: Add some tests for normal use of getopts.Jilles Tjoelker2014-05-074-0/+29
| | | | Notes: svn path=/head/; revision=265616
* sh: Allow kill %job on jobs started without job control.Jilles Tjoelker2014-03-152-1/+8
| | | | | | | | | | | When killing a %job started without job control, kill all processes in it. As with process groups and zombies, if any process in the job can be killed or has already terminated, the command is successful. This also fixes occasional failures of the builtins/kill1.0 test. Notes: svn path=/head/; revision=263206
* sh: Successfully do nothing when killing a terminated job.Jilles Tjoelker2014-03-082-0/+9
| | | | | | | | | If a job has terminated but is still known, silently do nothing when using the kill builtin with the job specifier. Formerly, the shell called kill() with the process group ID that might have been reused. Notes: svn path=/head/; revision=262931
* sh: Do not corrupt internal representation if LINENO inner expansion fails.Jilles Tjoelker2014-02-272-0/+11
| | | | | | | | | Example: f() { : ${LINENO+$((1/0))}; } and call this function twice. Notes: svn path=/head/; revision=262565