diff options
-rw-r--r-- | shell-lib.sh | 6 | ||||
-rw-r--r-- | shell-lib.yarn | 25 | ||||
-rwxr-xr-x | yarn | 33 | ||||
-rwxr-xr-x | yarn.tests/shell-lib.script | 5 |
4 files changed, 63 insertions, 6 deletions
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 + @@ -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.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 |