summaryrefslogtreecommitdiff
path: root/subplot.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-05-02 09:59:06 +0300
committerLars Wirzenius <liw@liw.fi>2020-05-02 14:33:58 +0300
commitb27aca0817b24596f748b93fe2b52899247f23fb (patch)
tree23088a00f7284ebdb3dbd92c66c2335c7f8e39a0 /subplot.py
parentd9e1fa5cf7db06f3ef0a255d533f45900627b307 (diff)
downloadsubplot-b27aca0817b24596f748b93fe2b52899247f23fb.tar.gz
Fix: check that stdout matches expected pattern
The stdout_matches function in subplot.py was lacking an assert. This meant all steps checking that stdout contained a desired string passed, even when they shouldn't have. I did the original changes sloppily: I should've verified the test fails with a wrong pattern before finishing the stdout_matches function. Also, fix scenarios that were passing because of this, but shouldn't have been. Further, fixing this revealed another problem: the way subplot.md was checking that the simple and regex patterns were working was broken: they were using a step that looked for specific output to make sure a nested subplot was calling its function, but doing that in a way that assumed specific output. This wasn't just broken, but also very confusing to debug. This commit changes things so the generic stdout matching step is used instead and is clearer to me.
Diffstat (limited to 'subplot.py')
-rw-r--r--subplot.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/subplot.py b/subplot.py
index 6852411..45a5a45 100644
--- a/subplot.py
+++ b/subplot.py
@@ -66,14 +66,11 @@ def file_contains(ctx, filename=None, pattern=None):
content = f.read()
assert_eq(pattern in content, True)
-def function_got_arg(ctx, arg=None):
- stdout_matches(ctx, '\nfunction got arg {}\n'.format(arg))
-
def scenario_was_run(ctx, name=None):
- stdout_matches(ctx, '\nrunning scenario: {}\n'.format(name))
+ stdout_matches(ctx, pattern='\nscenario: {}\n'.format(name))
def step_was_run(ctx, keyword=None, name=None):
- stdout_matches(ctx, '\n step: {}\n'.format(name))
+ stdout_matches(ctx, pattern='\n step: {} {}\n'.format(keyword, name))
def exit_code_zero(ctx):
if ctx.get('exit') != 0:
@@ -86,9 +83,13 @@ def exit_code_nonzero(ctx):
def binary(basename):
return os.path.join(srcdir, 'target', 'debug', basename)
-def stdout_matches(ctx, pattern):
+def stdout_matches(ctx, pattern=None):
stdout = ctx.get('stdout', '')
- return pattern in stdout
+ if pattern not in stdout:
+ print('pattern:', repr(pattern))
+ print('stdout:', repr(stdout))
+ print('ctx:', ctx.as_dict())
+ assert_eq(pattern in stdout, True)
def _get_metadata(filename):
st = os.lstat(filename)