env: trace the environment changes under -v - #14401
Open
Socialpranker wants to merge 1 commit into
Open
Conversation
-v printed only the exec, not what it did to the environment first, so
the three lines GNU emits before it were missing:
$ env -v -u A FOO=1 true
unset: A
setenv: FOO=1
executing: true
arg[0]= 'true'
and 'cleaning environ' for -i. The individual unsets are not logged when
-i is in effect, since it has already emptied the environment.
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-vprinted only the exec, not what it had just done to the environment:The fix
apply_removal_of_all_env_vars,apply_unset_env_varsandapply_specified_env_varstake the existingdo_debug_printingflag andemit their line, in the order they already run — which is the order GNU
prints them in. Column padding matches GNU (
unset:andsetenv:pad tothe width of
executing:), and neither name nor value is quoted.-iis a special case: it has already emptied the environment, so GNUprints
cleaning environand nounset:lines at all. That is reproduced.How the GNU behavior was established
By running the installed GNU coreutils 9.11 binary (Homebrew,
genv) as ablack box over 11 combinations of
-v,-i,-uandNAME=VALUE,including
-iwith-u, several-u, a value containing a space and aquote, and
-v -iwith no command, diffing stderr byte for byte againstuutils. All 11 now match. I did not read GNU coreutils source.
Testing
test_debug_traces_environment_changesintests/by-util/test_env.rs: the-u/assignment trace, the-itrace,the
-iplus-ucase that must log no unset, and the no--vcasethat must stay silent. Mutation-checked: reverting
env.rsalone makesit fail.
test_debug2_part_of_string_arggains thesetenv:line it now emits.cargo test --features env --test tests test_env: 103 passed, 0 failed.cargo clippy -p uu_env --all-targets -- -D warnings: clean.cargo fmt --check: clean.envinvocations in my harness: mismatches 3 -> 2.
Not in scope
The two remaining mismatches are unrelated to
-v:env A=1 -- printenv Aadds a
use -[v]S to pass options in shebang linesline GNU does notprint, and
env -S '\techo x'unescapes the\tin the program name itreports as missing.
Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. Every GNU behavior quoted above came from
running the installed binary, not from reading GPL source. All testing was
run locally.