Commit 289ca9dd authored by Mathieu Giraud's avatar Mathieu Giraud

src/should.py: refactor, extract and move skip_{set,tests} from skip_all, move variables_all

Prepares #36.
parent 5eb1d6d3
......@@ -680,9 +680,11 @@ class TestSuite():
self.stdin = []
self.stdout = []
self.test_lines = []
self.skip = False
self.status = None
self.modifiers = modifiers
self.variables = []
self.status = None
self.stats = Stats('test')
self.source = None
self.cd = cd
......@@ -702,6 +704,9 @@ class TestSuite():
def test(self, should_lines, variables=[], verbose=0, colorize=True, only=None):
name = ''
this_cmd_continues = False
self.only = only
self.variables_all = self.variables + variables
for l in should_lines:
l = l.lstrip().rstrip(ENDLINE_CHARS)
......@@ -715,16 +720,29 @@ class TestSuite():
# Directive -- Requires
if l.startswith(DIRECTIVE_REQUIRES):
self.requires_cmd = l[len(DIRECTIVE_REQUIRES):].strip()
self.variables_all = self.variables + variables
requires_cmd = self.cmd_variables_cd(self.requires_cmd, verbose, colorize)
p = subprocess.Popen(requires_cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
self.requires = (p.wait() == 0)
self.requires_stderr = [l.decode(errors='replace') for l in p.stderr.readlines()]
if not self.requires:
self.skip_set('Condition is not met: %s' % self.requires_cmd, verbose)
if verbose > 0:
print(color(ANSI.CYAN, ''.join(self.requires_stderr), colorize))
continue
# Directive -- No launcher
if l.startswith(DIRECTIVE_NO_LAUNCHER):
self.use_launcher = False
if replace_variables(VAR_LAUNCHER, self.variables_all):
self.skip_set('%s while %s is given' % (DIRECTIVE_NO_LAUNCHER, VAR_LAUNCHER), verbose)
continue
# Directive -- No extra options
if l.startswith(DIRECTIVE_NO_EXTRA):
self.variables = [(VAR_EXTRA, '')] + self.variables
self.variables_all = self.variables + variables
continue
# Directive -- Source
......@@ -736,6 +754,7 @@ class TestSuite():
if l.startswith(DIRECTIVE_OPTIONS):
opts, unknown = options.parse_known_args(l[len(DIRECTIVE_OPTIONS):].split())
self.variables = populate_variables(opts.var) + self.variables
self.variables_all = self.variables + variables
if opts.mod:
self.modifiers += ''.join(opts.mod)
continue
......@@ -780,34 +799,16 @@ class TestSuite():
this_cmd_continues = next_cmd_continues
# Test
self.only = only
self.variables_all = self.variables + variables
if not self.skip:
self.test_lines += self.launch(self.cmds, verbose, colorize)
self.tests_on_lines(self.tests, self.test_lines, verbose, colorize)
self.debug(self.status, "\n".join(self.cmds), self.test_lines, verbose, colorize)
else:
self.skip_tests(self.tests)
if verbose > 1:
print_variables(self.variables_all)
self.status = None
if self.requires_cmd:
requires_cmd = self.cmd_variables_cd(self.requires_cmd, verbose, colorize)
p = subprocess.Popen(requires_cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
self.requires = (p.wait() == 0)
self.requires_stderr = [l.decode(errors='replace') for l in p.stderr.readlines()]
if verbose > 0:
print(color(ANSI.CYAN, ''.join(self.requires_stderr), colorize))
if not self.requires:
self.skip_all('Condition is not met: %s' % self.requires_cmd, verbose)
return self.status
if not self.use_launcher:
if replace_variables(VAR_LAUNCHER, self.variables_all):
self.skip_all('%s while %s is given' % (DIRECTIVE_NO_LAUNCHER, VAR_LAUNCHER), verbose)
return self.status
self.test_lines += self.launch(self.cmds, verbose, colorize)
self.tests_on_lines(self.tests, self.test_lines, verbose, colorize)
self.debug(self.status, "\n".join(self.cmds), self.test_lines, verbose, colorize)
return self.status
......@@ -875,13 +876,16 @@ class TestSuite():
print(' stderr --> %s lines' % len(self.stderr))
print(color(ANSI.CYAN, ''.join(self.stderr), colorize))
def skip_all(self, reason, verbose=1):
def skip_set(self, reason, verbose=1):
if verbose > 0:
print('Skipping tests: %s' % reason)
for test in self.tests:
self.skip = True
self.status = combine_status(self.status, SKIP)
def skip_tests(self, tests):
for test in tests:
test.status = SKIP
self.stats.up(test.status)
self.status = SKIP
def debug(self, status, cmd, test_lines, verbose, colorize):
if status in FAIL_STATUS and verbose <= 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment