Commit Graph
37 Commits
Author SHA1 Message Date
Pádraig Brady 8026b38e21 tests: env: fix false failure with sh linked to multi-call binary
* tests/env/env.sh: Avoid calling "sh" with a modified argv[0],
as e.g. with busybox providing sh, it will fail with "applet not found".
Reported by Bruno Haible.
2026-11-10 20:01:17 +00:00
Sylvestre Ledru a041593749 tests: env: check a leading '=' in attached short option values
* tests/env/env.sh: Ensure -C=DIR, -vC=DIR, -S'-C=DIR ...' and -C=
change to a directory whose name starts with '=', that -a=NAME
sets argv[0] to '=NAME', and that -u=NAME and -vu=NAME are rejected.
https://github.com/uutils/coreutils/pull/15838

Link: https://github.com/coreutils/coreutils/pull/454
2026-11-09 00:13:38 +00:00
Sylvestre Ledru bea11752b3 tests: env: ensure an unset variable on its own adds no argument with -S
Reported at https://github.com/uutils/coreutils/issues/15773

* tests/env/env-S.pl: Add test cases.

Link: https://github.com/coreutils/coreutils/pull/415
2026-11-07 12:35:10 +00:00
Sylvestre Ledru 3c77964c82 tests: env: ensure env -a requires a command
Reported at https://github.com/uutils/coreutils/issues/15991

* tests/env/env.sh: Add test cases.

Link: https://github.com/coreutils/coreutils/pull/414
2026-11-07 12:35:10 +00:00
Pádraig Brady 8fcaebfe47 timeout: ensure we timeout with --verbose failures
In the edge case where --verbose diagnostics might block
or induce signals, ensure we always timeout the monitored command
and do not loop diagnosing diagnostic induced signals.

* NEWS: Mention the bug fix.
* src/timeout.c (cleanup): Avoid diagnosing SIGPIPE and SIGXFSZ.
Also send the signal before diagnosing to ensure command is timed out.
* tests/env/env-signal-handler.sh: Run timeout(1) with -f to ensure
the SIGKILL is diagnosed.
* tests/timeout/timeout.sh: Likewise.  Also add test cases for
SIGPIPE and SIGXFSZ.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-GV4Z4T3T.
2026-10-27 23:15:30 +00:00
Pádraig Brady 38aaf5e611 all: quote more user originated strings
* src/csplit.c: Quote arbitrary strings for clarity/safety.
* src/dircolors.c: Likewise.
* src/env.c: Likewise.
* src/split.c: Likewise.
* src/uniq.c: Likewise.
* tests/env/env-S.pl: Adjust accordingly.
* NEWS: Mention the improvement.
2026-10-23 14:08:24 +01:00
Pádraig Brady b257228543 maint: move tests/misc/printenv.h to tests/env/
* tests/misc/printenv.sh: Rename to ...
* tests/env/printenv.sh: ... here.
* tests/local.mk: Update the reference.
2026-09-17 08:52:12 +01:00
Pádraig Brady f799b2f48a env,printenv: support --quoting-style to control quoting
Quoting is currently only enabled by default when writing to terminals,
but it is usually desired to constrain the output format for processing.
E.g. for processing by a shell you can now:

  env --quoting-style=shell-escape | grep ^FOO

We use an option rather than reyling on $QUOTING_STYLE so
that $QUOTING_STYLE is restricted to be user config for terminals
and does not impact redirected processing.
Also it avoids an extra getenv() call if not outputting to tty.

* src/env.c (main): Parse --quoting-style and use that for the output
format for all outputs.
* src/printenv.c (main): Likewise.
* doc/coreutils.texi (env invocation): Describe --quoting-style.
(printenv invocation): Likewise.
* tests/env/env.sh: Reinstate testing of various output modes.
* tests/misc/printenv.sh: Likewise.
* NEWS: Mention the new feature.  Also mention the change from
the previous commit not done there so that builders would have
a clean patch against the previous release.
2026-09-17 08:52:12 +01:00
Pádraig Brady 782a1e5bc2 env,printenv: only quote when outputting to terminals
To support albeit non-robust but existing use cases like:

  env | grep SPARK_JAVA_OPT_ | sort -t_ -k4 -n |
   sed 's/[^=]*=\(.*\)/\1/g' > java_opts.txt
  readarray -t SPARK_EXECUTOR_JAVA_OPTS < java_opts.txt
  ...
  CMD=("${JAVA_HOME}/bin/java" "${SPARK_EXECUTOR_JAVA_OPTS[@]}" ...)

* src/env.c (main): Restrict quoting to terminals.
* src/printenv.c (main): Likewise.
* tests/env/env.sh: Adjust accordingly.
* tests/misc/printenv.sh: Likewise.
* doc/coreutils.texi: Likewise.

Link: https://github.com/coreutils/coreutils/issues/355
2026-09-17 08:52:12 +01:00
Collin Funk 1859316a9f tests: env: fix a false failure on GNU/Hurd
* tests/env/env.sh: Also filter out LD_ORIGIN_PATH.
2026-09-08 21:19:39 -07:00
Pádraig Brady d18d3a85be env: ensure all -v messages are quoted
$ env-before -v -u 'B' -S 'A=1 B="\n"' 'true'
split -S:  ‘A=1 B="\\n"’
 into:    ‘A=1’
     &    ‘B=\n’
unset:    B
setenv:   A=1
setenv:   B=

executing: true
   arg[0]= ‘true’

$ src/env-after -v -u 'B' -S 'A=1 B="\n"' 'true'
split -S:  ‘A=1 B="\\n"’
 into:     ‘A=1’
     &     ‘B=\n’
unsetting: ‘B’
setting:   ‘A=1’
setting:   ‘B=\n’
executing: ‘true’
   arg[0]= ‘true’

* src/env.c: -v is often used to debug spacing issues,
so it's important to quote output.
2026-08-27 16:40:49 +01:00
oech3 c717ca569b tests: env: support referencing of external env
* tests/env/env-S-script.sh: Use `cmd_exe` instead of
$abs_top_builddir for external usage of tests.

Link: https://github.com/coreutils/coreutils/pull/336
2026-08-26 18:24:20 +01:00
Pádraig Brady ff91f242fd tests: provide a cmd_exe helper to find a program binary
init.cfg (cmd_exe): Provide a function to find the command under test,
whether in the $PATH or in the standard build directory.
* tests/env/env0-from.sh: Use it instead of `command -v`.
* tests/misc/coreutils.sh: Likewise.
* tests/nproc/nproc-quota.sh: Likewise.
* tests/env/env.sh: Likewise.  Also remove non robust use of sed.
2026-08-26 15:18:08 +01:00
Pádraig Brady 493ed58f21 tests: env: avoid false failure on FreeBSD
Avoid unsetenv() on a non standard environment,
as FreeBSD 14 and 15 at least fail when manipulating
such an environment with unsetenv().

  $ printf 'A=1\0A=2\0foo\0' |
    src/env --env0-from=- src/env foo=bar | grep foo
  foo=bar
  foo

  $ printf 'A=1\0A=2\0foo\0' |
    src/env --env0-from=- src/env -u foo
  env: environment corrupt; missing value for foo
  env: cannot unset ‘foo’: Bad address

  $ printf 'A=1\0A=2\0foo\0' |
    src/env --env0-from=- src/env -u bar
  env: environment corrupt; missing value for foo
  env: cannot unset ‘bar’: Bad address

* tests/env/env0-from.sh: Use routines internal to env(1)
to manipulate the environment, only delegating the
executed env(1) to adding any implicit environment variables.
Reported by Bruno Haible.
2026-08-26 12:10:22 +01:00
Pádraig Brady fce42ec790 tests: env: fix false failure in recent --env0-from test
* tests/env/env0-from.sh: Make independent from implicit env vars,
like __CF_USER_TEXT_ENCODING etc.  Also improve test by,
making independent of location of env(1) under test, and
using textual output where possible to ease test debugging.
2026-08-18 00:38:52 +01:00
Pádraig Brady e871648b79 env: allow bare --env0-from to round-trip
Support --env0-from reading any environment generated by -0,
irrespective of whether -i is specified.

* src/env.c (set_envvars_from_file): Now that this function
always builds its own vector, support reading entries
without an equals, which are just appended to the existing vector.
* doc/coreutils.texi (env invocation): Adjust accordingly.
* tests/env/env0-from.sh: Likewise.
2026-08-14 18:00:15 +01:00
Pádraig Brady 9c28113d8a env: improve performance of merging environments
* bootstrap.conf: Reference the hashcode-mem module.
* src/env.c: Avoid quadratic merging using a hash of vector slots,
as the combined file entries and existing env entries may be
significant.  The performance diffence become noticable
when merging 500 x 500 entries.  Note we keep using system
interfaces on native windows to retain its case-insensitive behavior.
* tests/env/env0-from.sh: Add coverage for duplicate and
nonstandard inherited entries.
2026-08-14 18:00:15 +01:00
Pádraig Brady ebbff3d4cb env: implement full round-tripping for -i --env0-from
* src/env.c: Construct environ directly, preserving order, duplicates,
empty entries, and entries without =.  Note non -i mode continues
using system putenv()/unsetenv().
* doc/coreutils.texi: Adjust acordingly.
* tests/env/env0-from.sh: Likewise.
* NEWS: Likewise.
2026-08-14 18:00:15 +01:00
Pádraig Brady adb4d98799 env: support --env0-from to read NUL separated vars from file
* doc/coreutils.texi (env invocation): Document --env0-from.
* src/env.c (set_envvars_from_file): A new function to parse
.*=.*\0 format files and augment the environment with them.
* tests/env/env0-from.sh: Add a new test.
* tests/local.mk: Reference new test.
* NEWS: Mention the new feature.
* THANKS.in: Add Stefan Klinger, who proposed/discussed the change.

Link: https://github.com/coreutils/coreutils/issues/324
2026-08-14 18:00:15 +01:00
Collin Funk f5e1fd3126 tests: env,printenv: fix test failures on macOS
* tests/env/env.sh: Filter out __CF_USER_TEXT_ENCODING from the output.
Make the regex more strict.
* tests/misc/printenv.sh: Likewise.
Reported by Bruno Haible.
2026-08-10 19:25:38 -07:00
Pádraig Brady e0ae3dc846 tests: env: avoid false failure due to new quoting
* tests/env/env-S.pl: Disable quoting on output
rather than complicate the matching output strings.
2026-08-10 14:32:13 +01:00
Collin Funk 328322ca64 printenv,env: quote problematic variables
* doc/coreutils.texi (printenvAlwaysQuoted): New macro.
(printenv invocation): Use it.
(env invocation): Use it.
* src/printenv.h: New file.
* src/local.mk (noinst_HEADERS): Add it.
(src_env_SOURCES): Likewise. Group with src_printenv_SOURCES.
(src_printenv_SOURCES): New variable.
* src/printenv.c: Include argmatch.h and printenv.h.
(main): Quote printed variable names and values.
* src/env.c: Include argmatch.h and printenv.h.
(main): Quote printed variable names and values.
* tests/misc/printenv.sh: Add test cases.
* tests/env/env.sh: Likewise. Adjust invalid UTF-8 test cases.
* NEWS: Mention the change in behavior.
2026-08-05 21:29:35 -07:00
oech3 fcccbab0fb tests: env/env.sh: improve portability
* tests/env/env.sh: Make more portable by avoiding references to our
build dir,  and avoiding names that may cause false matches in
multi-call binaries.
https://github.com/coreutils/coreutils/pull/216
2026-03-27 21:15:18 +00:00
oech3 d5164f3d21 tests: env.sh: avoid multi-call binary considerations
A simpler fix than commit v9.9-4-g3b6efd555
which is less dependent on the exact behavior
of a multi-call binary.

* tests/env/env.sh: Use a local script rather than 'true'.
which may be a symlinked multi-call binary.
https://github.com/coreutils/coreutils/pull/174
2026-01-18 21:41:23 +00:00
Collin Funk 73d3a49f45 maint: run 'make update-copyright' 2026-01-01 10:56:16 -08:00
Collin Funk d3f0c72902 tests: env: check that real-time signals can be ignored
* tests/env/env-signal-handler.sh: Test that --ignore-signal with no
options also ignores real-time signals. Test that real-time signals can
be ignored by explicitly listing them.
2025-12-29 21:26:22 -08:00
Pádraig Brady a68ffc7176 tests: env: ensure non-utf8 name or value is supported
* tests/env/env.sh: Add a test case ensuring non-utf8 characters
in the name or value are supported.
2025-12-11 21:27:44 +00:00
Pádraig Brady ef613e2a76 tests: env: add a test for --ignore-signal=PIPE
* tests/env/env-signal-handler.sh: Add a test for this
oft interfered with signal.
2025-12-10 22:41:42 +00:00
Pádraig Brady 3b6efd5557 tests: env --argv0: fix false failure with symlinked single binary
* tests/env/env.sh: Always pass --coreutils-prog=true so that the
program to run can be determined with --enable-single-binary=symlinks.
Also actually verify the expected verbose output.
Reported by the Alpine Linux project.
2025-11-12 13:47:55 +00:00
Collin Funk bbde83899d tests: env: skip a few tests if LD_LIBRARY_PATH is set
* tests/env/env-null.sh: Skip test if LD_LIBRARY_PATH or platform's
equivalent is set, since 'env -i' will unset it which may prevent
programs from running.
* tests/env/env-S.pl: Likewise.
Issue and suggested fix reported by Bruno Haible.
2025-09-19 16:40:09 -07:00
Collin Funk 91d5a51236 maint: tests: remove duplicate uses of 'my' in Perl
* tests/env/env-S.pl (cf): Remove uses of 'my' after the variable has
been declared.
* tests/factor/factor.pl (t): Likewise.
* tests/misc/fold.pl (prog): Remove duplicate assignment.
2025-01-20 15:45:03 +00:00
Collin Funk 75e2224ae2 tests: env-S.pl: unset GNU/Hurd env vars
* tests/misc/env-S.pl: Unset LD_ORIGIN_PATH.
2025-01-14 12:33:52 +00:00
Pádraig Brady 28b176085f maint: update all copyright year number ranges
Update to latest gnulib with new copyright year.
Run "make update-copyright" and then...

* gnulib: Update included in this commit as copyright years
are the only change from the previous gnulib commit.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
* tests/sample-test: Adjust to use the single most recent year.
2025-01-01 09:33:08 +00:00
Pádraig Brady 193449b173 env: add -a,--argv0 to set the first argument passed to exec
Using the shell's exec -a feature can be awkward
so add support for setting overriding argv[0].
This gives env full control over the arguments it passes.

* src/env.c: Accept -a,--argv0 and set argv[0] appropriately.
* tests/env/env.sh: Add test cases.
* doc/coreutils.texi (env invocation): Describe -a,--argv0.
* NEWS: Mention the new feature.
2024-03-22 13:12:52 +00:00
Pádraig Brady a966dcdb69 maint: update all copyright year number ranges
Update to latest gnulib with new copyright year.
Run "make update-copyright" and then...

* gnulib: Update included in this commit as copyright years
are the only change from the previous gnulib commit.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Manually update copyright year,
until we fully sync with gnulib at a later stage.
* tests/sample-test: Adjust to use the single most recent year.
2024-01-01 13:27:23 +00:00
Paul Eggert 2dddc87214 maint: spelling fixes, including author names
Most of this just affects commentary and documentations.  The only
significant behavior change is translating author names via
proper_name_lite rather than proper_name_utf8, or not translating
them at all.  proper_name_lite is good enough for coreutils and
avoids the bloat that had coreutils not using Gnulib proper_name.
* bootstrap.conf (gnulib_modules): Use propername-lite instead
of propername.
(XGETTEXT_OPTIONS): Look for proper_name_lite instead of for
proper_name_utf8.
* cfg.mk (local-checks-to-skip): Remove
sc_proper_name_utf8_requires_ICONV, since we no longer use
proper_name_utf8.
(old_NEWS_hash): Update.
(sc_check-I18N-AUTHORS): Remove; no longer needed.
2023-08-28 14:06:43 -07:00
Sylvestre Ledru 15925d0e5b tests: move tests to a directory per utility
* cfg.mk: Adjust syntax check exclusion paths.
* tests/local.mk: Adjust for renamed tests.
2023-06-19 13:12:37 +01:00