summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-08-25 14:11:50 +0100
committerLars Wirzenius <liw@liw.fi>2013-08-25 14:12:03 +0100
commit3573f2213988fdc477d3cbf123981f7397f42cdb (patch)
treed89c9be6f462a5b47a8af129441c68c39cea30d2
parent1dbacde0bfa4463434abe3ecbccd2c03a29a3c16 (diff)
downloadcmdtest-3573f2213988fdc477d3cbf123981f7397f42cdb.tar.gz
Add --env option
Suggested by Daniel Silverstone
-rw-r--r--NEWS7
-rwxr-xr-xyarn16
-rwxr-xr-xyarn.tests/env-option.script15
3 files changed, 35 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 8f5f5df..15b29a1 100644
--- a/NEWS
+++ b/NEWS
@@ -9,9 +9,10 @@ Version 0.10, released UNRELEASED
* Yarn now cleans the environment when it runs shell commands for the
implementation steps. The PATH variable is kept from the user's
environment, every other variable is either removed or hardcoded to
- a specific value. Additionally yarn sets the `SRCDIR` environment
- variable to point at the root of the source tree (the directory
- where yarn was invoked from).
+ a specific value. More variables can be added explicitly to the test
+ environment with the new `--env NAME=VALUE` option. Additionally
+ yarn sets the `SRCDIR` environment variable to point at the root of
+ the source tree (the directory where yarn was invoked from).
* A new option, `--timings`, has been added to yarn to report how long
each scenario and each step took.
diff --git a/yarn b/yarn
index 2e02eb3..501d10e 100755
--- a/yarn
+++ b/yarn
@@ -64,6 +64,11 @@ class YarnRunner(cliapp.Application):
'it should be empty or not exist',
metavar='DIR')
+ self.settings.string_list(
+ ['env'],
+ 'add NAME=VALUE to the environment when tests are run',
+ metavar='NAME=VALUE')
+
self.settings.boolean(
['snapshot'],
'make snapshots of test working directory '
@@ -340,11 +345,22 @@ class YarnRunner(cliapp.Application):
}
env = {}
+
for key in whitelisted:
if key in os.environ:
env[key] = os.environ[key]
+
for key in hardcoded:
env[key] = hardcoded[key]
+
+ for option_arg in self.settings['env']:
+ if '=' not in option_arg:
+ raise cliapp.AppException(
+ '--env argument must contain "=" '
+ 'to separate environment variable name and value')
+ key, value = option_arg.split('=', 1)
+ env[key] = value
+
return env
def run_step(self, datadir, scenario, step, shell_prelude, report_error):
diff --git a/yarn.tests/env-option.script b/yarn.tests/env-option.script
new file mode 100755
index 0000000..9724ffc
--- /dev/null
+++ b/yarn.tests/env-option.script
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+set -eu
+
+
+cat <<EOF > "$DATADIR/test.yarn"
+ SCENARIO foo
+ THEN yoyo is set
+
+ IMPLEMENTS THEN yoyo is set
+ env | grep '^yoyo='
+EOF
+
+./run-yarn --env yoyo=something "$DATADIR/test.yarn"
+