diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-07-04 08:09:58 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-07-04 08:09:58 +0100 |
commit | 4f56f18ff4f98904bf881944f56dc4d133b2844c (patch) | |
tree | 3bc1caeda6e5afd6ba84bc19380c29f7a23b72d6 /yarn | |
parent | 71963a08d32daf5ffb356fa427f1499c4ca5b4cc (diff) | |
download | cmdtest-4f56f18ff4f98904bf881944f56dc4d133b2844c.tar.gz |
Add --shell-library
Diffstat (limited to 'yarn')
-rwxr-xr-x | yarn | 33 |
1 files changed, 27 insertions, 6 deletions
@@ -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: |