-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/testscript: allow -e flag to pass env value
The -e flag for testscript currently allows the caller to specify that environment variables are inherited from the current environment. However this falls when the current environment does not have a value set and you need to set a specific value. For example: GOBUILD=$(go env GOBUILD) testscript -e GOBUILD script.txt Instead, allow -e to also specify a value: testscript -e GOBUILD=$(go env GOBUILD) script.txt which feels more fluent/natural.
- Loading branch information
Showing
4 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Test that passing env values, e.g. ENV1=val, works | ||
|
||
unquote test.txt | ||
|
||
env BLAH1= | ||
env BLAH2=junk | ||
|
||
# Normal operation | ||
testscript -e BLAH1=rubbish -e BLAH2 test.txt | ||
|
||
# It is an error to specify WORK. Note the error message | ||
# appears on stdout because it is written to the log output | ||
# of testscript, which has no concept of stderr. | ||
! testscript -e BLAH1=rubbish -e BLAH2 -e WORK test.txt | ||
stdout 'cannot override WORK variable' | ||
|
||
-- test.txt -- | ||
>exec printf $BLAH1'\n' | ||
>cmp stdout stdout1.txt | ||
> | ||
>exec printf $BLAH2'\n' | ||
>cmp stdout stdout2.txt | ||
> | ||
>-- stdout1.txt -- | ||
>rubbish | ||
>-- stdout2.txt -- | ||
>junk |