summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2013-07-04 08:14:08 +0100
committerLars Wirzenius <liw@liw.fi>2013-07-04 08:14:08 +0100
commitfaff7b2b536218669216593068f063611cf80dab (patch)
treeb63724d13330df17ffa3fca018768270d3e9e550
parent71963a08d32daf5ffb356fa427f1499c4ca5b4cc (diff)
parent76f626af6ba1bbaf3e922b7799fbe49c7d73f20b (diff)
downloadcmdtest-faff7b2b536218669216593068f063611cf80dab.tar.gz
Merge branch 'shlib'
-rw-r--r--NEWS2
-rw-r--r--shell-lib.sh6
-rw-r--r--shell-lib.yarn25
-rwxr-xr-xyarn33
-rw-r--r--yarn.1.in10
-rwxr-xr-xyarn.tests/shell-lib.script5
6 files changed, 75 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 5cc5100..ec9275f 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Version 0.X, released UNRELEASED
--------------------------------
* Yarn now warns if an input file has no code blocks.
+* There is no a `--shell-library` option for the user to use, which
+ includes a shell library when running any IMPLEMENTS section.
Bug fixes:
diff --git a/shell-lib.sh b/shell-lib.sh
new file mode 100644
index 0000000..767918e
--- /dev/null
+++ b/shell-lib.sh
@@ -0,0 +1,6 @@
+# A shell library for the shell-lib.yarn test.
+
+implement()
+{
+ echo "$@"
+}
diff --git a/shell-lib.yarn b/shell-lib.yarn
new file mode 100644
index 0000000..f9b9ca9
--- /dev/null
+++ b/shell-lib.yarn
@@ -0,0 +1,25 @@
+A simple test scenario with shell libraries
+======================
+
+This is a very simple test scenario, which exists only to test
+the scenario test runner itself.
+
+ SCENARIO a shell library scenario
+
+The following is the actual test in this scenario:
+
+ GIVEN a given
+ WHEN a when
+ THEN a then
+
+And the implementations follow.
+
+ IMPLEMENTS GIVEN a given
+ implement a given
+
+ IMPLEMENTS WHEN a when
+ implement a when
+
+ IMPLEMENTS THEN a then
+ implement a then
+
diff --git a/yarn b/yarn
index 4244222..8d19b68 100755
--- a/yarn
+++ b/yarn
@@ -41,6 +41,10 @@ class YarnRunner(cliapp.Application):
['quiet', 'q'],
'be quiet, avoid progress reporting, only show errors')
+ self.settings.string_list(
+ ['shell-library', 's'],
+ 'include a shell library for the IMPLEMENTS sections to use')
+
def setup(self):
self.ts = ttystatus.TerminalStatus(period=0.001)
if not self.settings['quiet']:
@@ -52,6 +56,7 @@ class YarnRunner(cliapp.Application):
def process_args(self, args):
scenarios, implementations = self.parse_scenarios(args)
self.connect_implementations(scenarios, implementations)
+ shell_prelude = self.load_shell_libraries()
self.ts['scenarios'] = scenarios
self.ts['num_scenarios'] = len(scenarios)
@@ -60,7 +65,7 @@ class YarnRunner(cliapp.Application):
start_time = time.time()
failed_scenarios = []
for scenario in scenarios:
- if not self.run_scenario(scenario):
+ if not self.run_scenario(scenario, shell_prelude):
failed_scenarios.append(scenario)
duration = time.time() - start_time
@@ -118,7 +123,21 @@ class YarnRunner(cliapp.Application):
assert step.implementation is None
step.implementation = matching[0]
- def run_scenario(self, scenario):
+ def load_shell_libraries(self):
+ if not self.settings['shell-library']:
+ logging.info('No shell libraries defined')
+ return ''
+
+ libs = []
+ for filename in self.settings['shell-library']:
+ logging.info('Loading shell library %s')
+ with open(filename) as f:
+ text = f.read()
+ libs.append('# Loaded from %s\n\n%s\n\n' % (filename, text))
+
+ return ''.join(libs)
+
+ def run_scenario(self, scenario, shell_prelude):
logging.info('Running scenario %s' % scenario.name)
self.ts['scenario'] = scenario
self.ts['scenario_name'] = scenario.name
@@ -135,13 +154,13 @@ class YarnRunner(cliapp.Application):
ok = True
for step in normal:
- exit = self.run_step(datadir, scenario, step)
+ exit = self.run_step(datadir, scenario, step, shell_prelude)
if exit != 0:
ok = False
break
for step in cleanup:
- exit = self.run_step(datadir, scenario, step)
+ exit = self.run_step(datadir, scenario, step, shell_prelude)
if exit != 0:
ok = False
break
@@ -150,7 +169,7 @@ class YarnRunner(cliapp.Application):
return ok
- def run_step(self, datadir, scenario, step):
+ def run_step(self, datadir, scenario, step, shell_prelude):
logging.info('Running step "%s %s"' % (step.what, step.text))
logging.info('DATADIR is %s' % datadir)
self.ts['step'] = step
@@ -163,8 +182,10 @@ class YarnRunner(cliapp.Application):
for i, match in enumerate(m.groups('')):
env['MATCH_%d' % (i+1)] = match
+ shell_script = '%s\n\n%s\n' % (
+ shell_prelude, step.implementation.shell)
exit, stdout, stderr = cliapp.runcmd_unchecked(
- ['sh', '-euc', step.implementation.shell], env=env)
+ ['sh', '-euc', shell_script], env=env)
logging.debug('Exit code: %d' % exit)
if stdout:
diff --git a/yarn.1.in b/yarn.1.in
index d1789b1..86838bc 100644
--- a/yarn.1.in
+++ b/yarn.1.in
@@ -112,6 +112,16 @@ yarn *.scenario
.fi
.PP
All the files will be treated together as if they had been one file.
+.PP
+To add a shell library to be included when running any IMPLEMENTS section:
+.IP
+.nf
+yarn \-\-shell\-library mylib.sh *.scenario
+.fi
+.PP
+You can repeat
+.B \-\-shell\-library
+as many times as necessary.
.SH "SEE ALSO"
.BR cmdtest (1),
.BR cliapp (5).
diff --git a/yarn.tests/shell-lib.script b/yarn.tests/shell-lib.script
new file mode 100755
index 0000000..fb820d4
--- /dev/null
+++ b/yarn.tests/shell-lib.script
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set -eu
+
+./yarn -q --shell-library shell-lib.sh shell-lib.yarn