From 92f3d5058344759a2e63e70785b91f6870ed189c Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Mon, 6 Nov 2017 10:25:28 -0500 Subject: [PATCH] Ignore indented lines that aren't part of a test --- cram/_test.py | 6 +++++- tests/test.t | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cram/_test.py b/cram/_test.py index 27ef99c5..4e4dbaeb 100644 --- a/cram/_test.py +++ b/cram/_test.py @@ -126,6 +126,7 @@ def test(lines, shell='/bin/sh', indent=2, testname=None, env=None, refout, postout = [], [] i = pos = prepos = -1 stdin = [] + in_test = False for i, line in enumerate(lines): if not line.endswith(b('\n')): line += b('\n') @@ -136,11 +137,14 @@ def test(lines, shell='/bin/sh', indent=2, testname=None, env=None, pos = i stdin.append(b('echo %s %s $?\n' % (usalt, i))) stdin.append(line[len(cmdline):]) + in_test = True elif line.startswith(conline): after.setdefault(prepos, []).append(line) stdin.append(line[len(conline):]) - elif not line.startswith(indent): + in_test = True + elif not line.startswith(indent) or not in_test: after.setdefault(pos, []).append(line) + in_test = False stdin.append(b('echo %s %s $?\n' % (usalt, i + 1))) output, retcode = execute(shell + ['-'], stdin=b('').join(stdin), diff --git a/tests/test.t b/tests/test.t index e1f74b12..4f9ec874 100644 --- a/tests/test.t +++ b/tests/test.t @@ -121,6 +121,8 @@ Custom indentation: > > $ echo foo > bar + > + > Nor is this! > EOF $ cram --indent=4 indent.t .