From 8443dc250bb58091c435db2b29e2029c434d1750 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 31 Jul 2013 18:37:33 +0100 Subject: Set SRCDIR and clean environment --- yarn | 28 +++++++++++++++++++++++++++- yarn.tests/env.script | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 yarn.tests/env.script 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" -- cgit v1.2.1