summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-07-31 18:42:15 +0100
committerLars Wirzenius <liw@liw.fi>2013-07-31 18:42:15 +0100
commit6c7f6690a4485c9043cf5f21ea15cac51b5a2273 (patch)
treee27f4fea6c15482c50d8b132c335f79ece61149d
parent3fb60d86c01ef3bc615d39e69ee0011aef906685 (diff)
parent02fe4bfce7b93c54e7e0e1a68a822dcd7764b30f (diff)
downloadcmdtest-6c7f6690a4485c9043cf5f21ea15cac51b5a2273.tar.gz
Merge branch 'liw/yarn-srcdir'
-rw-r--r--NEWS8
-rw-r--r--README.yarn9
-rwxr-xr-xyarn28
-rwxr-xr-xyarn.tests/env.script18
4 files changed, 62 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index ca4d551..4951f4c 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,14 @@ NEWS for cmdtest
This file summarizes changes between releases of cmdtest.
+Version 0.10, released UNRELEASED
+---------------------------------
+
+* Yarn now cleans the environment when it runs shell commands for the
+ implementation steps. It also sets the `SRCDIR` environment variable
+ to point at the root of the source tree (the directory where yarn
+ was invoked from).
+
Version 0.9, released 2013-07-23
--------------------------------
diff --git a/README.yarn b/README.yarn
index 76d57b5..16f7522 100644
--- a/README.yarn
+++ b/README.yarn
@@ -136,6 +136,15 @@ The following keywords are defined.
The test runner creates a temporary directory, whose name is
given to the shell code in the `DATADIR` environment variable.
+ The test runner sets the `SRCDIR` environment variable to the
+ path to the directory it was invoked from (by convention, the
+ root of the source tree of the project).
+
+ The test runner removes all other environment variables, except
+ `TERM`, `USER`, `USERNAME`, `LOGNAME`, `HOME`, and `PATH`. It also
+ forces `SHELL` set to `/bin/sh`, and `LC_ALL` set to `C`, in order
+ to have as clean an environment as possible for tests to run in.
+
The shell commands get invoked with `/bin/sh -eu`, and need to
be written accordingly. Be careful about commands that return a
non-zero exit code. There will eventually be a library of shell
diff --git a/yarn b/yarn
index 288e23b..6fbd63a 100755
--- a/yarn
+++ b/yarn
@@ -267,6 +267,31 @@ class YarnRunner(cliapp.Application):
return ok
+ def clean_env(self):
+ '''Return a clean environment for running tests.'''
+
+ whitelisted = [
+ 'TERM',
+ 'USER',
+ 'USERNAME',
+ 'PATH',
+ 'HOME',
+ 'LOGNAME',
+ ]
+
+ hardcoded = {
+ 'SHELL': '/bin/sh',
+ 'LC_ALL': 'C',
+ }
+
+ env = {}
+ for key in whitelisted:
+ if key in os.environ:
+ env[key] = os.environ[key]
+ for key in hardcoded:
+ env[key] = hardcoded[key]
+ return env
+
def run_step(self, datadir, scenario, step, shell_prelude, report_error):
self.info('Running step "%s %s"' % (step.what, step.text))
self.ts['step'] = step
@@ -274,8 +299,9 @@ class YarnRunner(cliapp.Application):
m = re.match(step.implementation.regexp, step.text)
assert m is not None
- env = os.environ.copy()
+ env = self.clean_env()
env['DATADIR'] = datadir
+ env['SRCDIR'] = os.getcwd()
for i, match in enumerate(m.groups('')):
env['MATCH_%d' % (i+1)] = match
diff --git a/yarn.tests/env.script b/yarn.tests/env.script
new file mode 100755
index 0000000..2ef35c6
--- /dev/null
+++ b/yarn.tests/env.script
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -eu
+
+cat << 'EOF' > "$DATADIR/env.yarn"
+ SCENARIO check environment
+ THEN DATADIR is set
+ AND SRCDIR is set
+ AND NOTSET is not set
+
+ IMPLEMENTS THEN (\S+) is set
+ env | grep "^$MATCH_1="
+
+ IMPLEMENTS THEN (\S+) is not set
+ ! env | grep "^$MATCH_1="
+EOF
+
+NOTSET=foo ./run-yarn "$DATADIR/env.yarn"