summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-01-21 20:50:34 +0000
committerLars Wirzenius <liw@liw.fi>2014-01-21 20:50:34 +0000
commit058d1ae7730d8306242035347cacd1ca7b9787d7 (patch)
treeec6a893ba75d896b4c57c82c842cceebb7c43ae6
parent099c7d84298c12db09979903720fa44c615e1f7b (diff)
downloadcmdtest-058d1ae7730d8306242035347cacd1ca7b9787d7.tar.gz
Make yarn set $HOME to an existing directory
-rw-r--r--NEWS5
-rwxr-xr-xyarn8
-rwxr-xr-xyarn.tests/env.script5
3 files changed, 17 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 4b8bb58..555c610 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,11 @@ For yarn:
to include the names of those scenarios only, rather than all
scenarios. Patch by Pete Fotheringham.
+* Yarn now sets `$HOME` to a directory in `$DATADIR`, and creates
+ that directory. This means test suites can assume `$HOME` exists,
+ but don't use the user's real home directory, which is important for
+ test environment hygiene.
+
For cmdtest:
* The `--test` (`-t`) option should now work again. Thank you
diff --git a/yarn b/yarn
index 24e982b..ef19b94 100755
--- a/yarn
+++ b/yarn
@@ -289,6 +289,9 @@ class YarnRunner(cliapp.Application):
datadir = self.datadir(tempdir, scenario)
os.mkdir(datadir)
self.info('DATADIR is %s' % datadir)
+ homedir = self.homedir(datadir)
+ os.mkdir(homedir)
+ self.info('HOME for tests is %s' % homedir)
assuming = [s for s in scenario.steps if s.what == 'ASSUMING']
cleanup = [s for s in scenario.steps if s.what == 'FINALLY']
@@ -335,6 +338,9 @@ class YarnRunner(cliapp.Application):
self.remember_scenario_timing(time.time() - started)
return ok
+ def homedir(self, datadir):
+ return os.path.join(datadir, 'HOME')
+
def clean_env(self):
'''Return a clean environment for running tests.'''
@@ -349,7 +355,6 @@ class YarnRunner(cliapp.Application):
'USER': 'tomjon',
'USERNAME': 'tomjon',
'LOGNAME': 'tomjon',
- 'HOME': '/this/path/does/not/exist',
}
env = {}
@@ -384,6 +389,7 @@ class YarnRunner(cliapp.Application):
env = self.clean_env()
env['DATADIR'] = datadir
env['SRCDIR'] = os.getcwd()
+ env['HOME'] = self.homedir(datadir)
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
index d14a21a..d24172d 100755
--- a/yarn.tests/env.script
+++ b/yarn.tests/env.script
@@ -7,6 +7,7 @@ cat << 'EOF' > "$DATADIR/env.yarn"
THEN DATADIR is set
AND SRCDIR is set
AND NOTSET is not set
+ AND HOME is prefixed by DATADIR
IMPLEMENTS THEN (\S+) is set
env
@@ -14,6 +15,10 @@ cat << 'EOF' > "$DATADIR/env.yarn"
IMPLEMENTS THEN (\S+) is not set
! env | grep "^$MATCH_1="
+
+ IMPLEMENTS THEN (\S+) is prefixed by (\S+)
+ x=$(env | sed -n "/^$MATCH_2=/s///p")
+ env | grep "^$MATCH_1=$x/"
EOF
NOTSET=foo ./run-yarn "$DATADIR/env.yarn"