summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-07-06 09:22:44 +0100
committerLars Wirzenius <liw@liw.fi>2013-07-06 13:55:58 +0100
commit2f3b41e6bf867ec7dd09cf8ae8bbc74db7a50029 (patch)
tree5acad6bc8ef221d959e70998e60a66cd5a350e51
parenta6fb61972ccc6c790f2ec45f12eca770419b6e80 (diff)
downloadcmdtest-2f3b41e6bf867ec7dd09cf8ae8bbc74db7a50029.tar.gz
Implement --snapshot
-rwxr-xr-xyarn53
-rwxr-xr-xyarn.tests/snapshot.script71
2 files changed, 97 insertions, 27 deletions
diff --git a/yarn b/yarn
index 224fd88..c25a929 100755
--- a/yarn
+++ b/yarn
@@ -56,6 +56,12 @@ class YarnRunner(cliapp.Application):
'it should be empty or not exist',
metavar='DIR')
+ self.settings.boolean(
+ ['snapshot'],
+ 'make snapshots of test working directory '
+ 'after each scenario step; you probably '
+ 'want to use this with --tempdir')
+
def setup(self):
self.ts = ttystatus.TerminalStatus(period=0.001)
if not self.settings['quiet']:
@@ -182,27 +188,37 @@ class YarnRunner(cliapp.Application):
os.mkdir(tempdir)
else:
tempdir = tempfile.mkdtemp()
- datadir = os.path.join(tempdir, 'datadir')
+
+ os.mkdir(self.scenario_dir(tempdir, scenario))
+ datadir = self.datadir(tempdir, scenario)
os.mkdir(datadir)
cleanup = [s for s in scenario.steps if s.what == 'FINALLY']
normal = [s for s in scenario.steps if s not in cleanup]
ok = True
+ step_number = 0
for step in normal:
exit = self.run_step(datadir, scenario, step, shell_prelude)
+ step_number += 1
+ self.snapshot_datadir(
+ tempdir, datadir, scenario, step_number, step)
if exit != 0:
ok = False
break
for step in cleanup:
exit = self.run_step(datadir, scenario, step, shell_prelude)
+ step_number += 1
+ self.snapshot_datadir(
+ tempdir, datadir, scenario, step_number, step)
if exit != 0:
ok = False
break
- shutil.rmtree(datadir)
+ if not self.settings['snapshot']:
+ shutil.rmtree(tempdir)
return ok
@@ -245,6 +261,39 @@ class YarnRunner(cliapp.Application):
return exit
+ def scenario_dir(self, tempdir, scenario):
+ return os.path.join(tempdir, self.nice(scenario.name))
+
+ def datadir(self, tempdir, scenario):
+ sd = self.scenario_dir(tempdir, scenario)
+ return os.path.join(sd, 'datadir')
+
+ def snapshot_dir(self, tempdir, scenario, step, step_number):
+ sd = self.scenario_dir(tempdir, scenario)
+ base = '%03d-%s-%s' % (step_number, step.what, self.nice(step.text))
+ return os.path.join(sd, base)
+
+ def snapshot_datadir(self, tempdir, datadir, scenario, step_number, step):
+ # Use --reflink in case of CoW support, e.g., btrfs.
+ snapshot = self.snapshot_dir(tempdir, scenario, step, step_number)
+ cliapp.runcmd(
+ ['cp', '-a', '--reflink=auto', datadir, snapshot])
+
+ def nice(self, name):
+ # Quote a scenario or step name so it forms a nice filename.
+ nice_chars = "abcdefghijklmnopqrstuvwxyz"
+ nice_chars += nice_chars.upper()
+ nice_chars += "0123456789-."
+
+ nice = []
+ for c in name:
+ if c in nice_chars:
+ nice.append(c)
+ elif not nice or nice[-1] != '_':
+ nice.append('_')
+ nice = ''.join(nice)
+ return nice
+
def indent(self, s):
return ''.join(' %s\n' % line for line in s.splitlines())
diff --git a/yarn.tests/snapshot.script b/yarn.tests/snapshot.script
index 90db93e..e8947ad 100755
--- a/yarn.tests/snapshot.script
+++ b/yarn.tests/snapshot.script
@@ -8,34 +8,55 @@ cat << EOF > "$DATADIR/foo.yarn"
WHEN foo
THEN foo
- IMPLEMENTS GIVEN foo
- touch "\$DATADIR/foo.given"
+ SCENARIO bar
+ GIVEN bar
+ WHEN bar
+ THEN bar
- IMPLEMENTS WHEN foo
- touch "\$DATADIR/foo.when"
+ IMPLEMENTS GIVEN (.*)
+ touch "\$DATADIR/\$MATCH_1.given"
- IMPLEMENTS THEN foo
- touch "\$DATADIR/foo.then"
+ IMPLEMENTS WHEN (.*)
+ touch "\$DATADIR/\$MATCH_1.when"
+
+ IMPLEMENTS THEN (.*)
+ touch "\$DATADIR/\$MATCH_1.then"
EOF
./yarn -q --snapshot --tempdir "$DATADIR/tmp" "$DATADIR/foo.yarn"
-test -e "$DATADIR/tmp/001-GIVEN-foo"
-test -e "$DATADIR/tmp/001-GIVEN-foo/foo.given"
-! test -e "$DATADIR/tmp/datadir/foo.when"
-! test -e "$DATADIR/tmp/datadir/foo.then"
-
-test -e "$DATADIR/tmp/002-WHEN-foo"
-test -e "$DATADIR/tmp/002-WHEN-foo/foo.given"
-test -e "$DATADIR/tmp/002-WHEN-foo/foo.when"
-! test -e "$DATADIR/tmp/002-WHEN-foo/foo.then"
-
-test -e "$DATADIR/tmp/003-THEN-foo"
-test -e "$DATADIR/tmp/003-THEN-foo/foo.given"
-test -e "$DATADIR/tmp/003-THEN-foo/foo.when"
-test -e "$DATADIR/tmp/003-THEN-foo/foo.then"
-
-test -e "$DATADIR/tmp/datadir"
-test -e "$DATADIR/tmp/datadir/foo.given"
-test -e "$DATADIR/tmp/datadir/foo.when"
-test -e "$DATADIR/tmp/datadir/foo.then"
+test -e "$DATADIR/tmp/bar"
+test -e "$DATADIR/tmp/bar/datadir"
+test -e "$DATADIR/tmp/bar/datadir/bar.given"
+test -e "$DATADIR/tmp/bar/datadir/bar.when"
+test -e "$DATADIR/tmp/bar/datadir/bar.then"
+
+test -e "$DATADIR/tmp/bar/001-GIVEN-bar"
+test -e "$DATADIR/tmp/bar/001-GIVEN-bar/bar.given"
+! test -e "$DATADIR/tmp/bar/001-GIVEN-bar/bar.when"
+! test -e "$DATADIR/tmp/bar/001-GIVEN-bar/bar.then"
+
+test -e "$DATADIR/tmp/bar/002-WHEN-bar"
+test -e "$DATADIR/tmp/bar/002-WHEN-bar/bar.given"
+test -e "$DATADIR/tmp/bar/002-WHEN-bar/bar.when"
+! test -e "$DATADIR/tmp/bar/002-WHEN-bar/bar.then"
+
+test -e "$DATADIR/tmp/bar/003-THEN-bar"
+test -e "$DATADIR/tmp/bar/003-THEN-bar/bar.given"
+test -e "$DATADIR/tmp/bar/003-THEN-bar/bar.when"
+test -e "$DATADIR/tmp/bar/003-THEN-bar/bar.then"
+
+test -e "$DATADIR/tmp/foo/001-GIVEN-foo"
+test -e "$DATADIR/tmp/foo/001-GIVEN-foo/foo.given"
+! test -e "$DATADIR/tmp/foo/001-GIVEN-foo/foo.when"
+! test -e "$DATADIR/tmp/foo/001-GIVEN-foo/foo.then"
+
+test -e "$DATADIR/tmp/foo/002-WHEN-foo"
+test -e "$DATADIR/tmp/foo/002-WHEN-foo/foo.given"
+test -e "$DATADIR/tmp/foo/002-WHEN-foo/foo.when"
+! test -e "$DATADIR/tmp/foo/002-WHEN-foo/foo.then"
+
+test -e "$DATADIR/tmp/foo/003-THEN-foo"
+test -e "$DATADIR/tmp/foo/003-THEN-foo/foo.given"
+test -e "$DATADIR/tmp/foo/003-THEN-foo/foo.when"
+test -e "$DATADIR/tmp/foo/003-THEN-foo/foo.then"