Commit 74fb1b87 authored by Mathieu Giraud's avatar Mathieu Giraud

src/should.py: breaking change, run and flush tests at each new set of commands

This allows to interleave commands and tests.
See #36.
parent 8d998381
...@@ -703,11 +703,15 @@ class TestSuite(): ...@@ -703,11 +703,15 @@ class TestSuite():
def test(self, should_lines, variables=[], verbose=0, colorize=True, only=None): def test(self, should_lines, variables=[], verbose=0, colorize=True, only=None):
name = '' name = ''
this_cmd_continues = False current_cmd = '' # multi-line command
current_cmds = [] # commands since the last command run
current_tests = [] # tests since the last command run
self.only = only self.only = only
self.variables_all = self.variables + variables self.variables_all = self.variables + variables
for l in should_lines: # Iterate over should_lines
# then use once DIRECTIVE_SCRIPT to flush the last tests
for l in list(should_lines) + [DIRECTIVE_SCRIPT]:
l = l.lstrip().rstrip(ENDLINE_CHARS) l = l.lstrip().rstrip(ENDLINE_CHARS)
if not l: if not l:
...@@ -782,29 +786,46 @@ class TestSuite(): ...@@ -782,29 +786,46 @@ class TestSuite():
if RE_TEST.search(l): if RE_TEST.search(l):
pos = l.find(TOKEN_TEST) pos = l.find(TOKEN_TEST)
modifiers, expression = l[:pos], l[pos+1:] modifiers, expression = l[:pos], l[pos+1:]
self.tests.append(TestCase(self.modifiers + modifiers, expression, name)) test = TestCase(self.modifiers + modifiers, expression, name)
current_tests.append(test)
self.tests.append(test)
continue continue
# Command : flush and test the previous tests
if current_tests:
# Test current_cmds with current_tests
if not self.skip:
test_lines = self.launch(current_cmds, verbose, colorize)
self.test_lines += test_lines
self.tests_on_lines(current_tests, test_lines, verbose, colorize)
self.debug(self.status, "\n".join(current_cmds), test_lines, verbose, colorize)
else:
self.skip_tests(current_tests)
current_cmds = []
current_tests = []
# Command # Command
l = l.strip() l = l.strip()
if not l:
continue
next_cmd_continues = l.endswith(CONTINUATION_CHAR) next_cmd_continues = l.endswith(CONTINUATION_CHAR)
if next_cmd_continues: if next_cmd_continues:
l = l[:-1] l = l[:-1]
if this_cmd_continues: current_cmd += l
self.cmds[-1] += l
else:
self.cmds.append(l)
this_cmd_continues = next_cmd_continues if not next_cmd_continues:
current_cmds.append(current_cmd)
self.cmds.append(current_cmd)
current_cmd = ''
# Test
if not self.skip: # end of loop on should_lines
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: if verbose > 1:
print_variables(self.variables_all) print_variables(self.variables_all)
......
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