diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-06-23 09:27:41 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-06-23 09:27:41 +0100 |
commit | 1a3c15fd5d2bc6bd9a28179a61f6f138ec261d44 (patch) | |
tree | 91eae72a0b700fd632da5329e250a9afc461920e | |
parent | 4d5992fd7bc2a49cd31a8eb36c01b9dc3c2480e5 (diff) | |
parent | c54bcf443bb1243d9cb14fef598b3901dd66f51e (diff) | |
download | cmdtest-1a3c15fd5d2bc6bd9a28179a61f6f138ec261d44.tar.gz |
Merge branch 'liw/warn-if-empty-input'
-rwxr-xr-x | yarn | 4 | ||||
-rwxr-xr-x | yarn.tests/warn-if-empty.script | 10 | ||||
-rw-r--r-- | yarnlib/mdparser.py | 1 | ||||
-rw-r--r-- | yarnlib/mdparser_tests.py | 9 |
4 files changed, 20 insertions, 4 deletions
@@ -68,7 +68,9 @@ class YarnRunner(cliapp.Application): def parse_scenarios(self, filenames): mdparser = yarnlib.MarkdownParser() for filename in filenames: - mdparser.parse_file(filename) + blocks = mdparser.parse_file(filename) + if not blocks: + logging.warning('No scenario code blocks in %s' % filename) block_parser = yarnlib.BlockParser() block_parser.parse_blocks(mdparser.blocks) diff --git a/yarn.tests/warn-if-empty.script b/yarn.tests/warn-if-empty.script new file mode 100755 index 0000000..7a5c028 --- /dev/null +++ b/yarn.tests/warn-if-empty.script @@ -0,0 +1,10 @@ +#!/bin/sh + +set -eu + +touch "$DATADIR/empty.yarn" + +# The grep below will fail unless the string exists, thereby failing the +# entire test. +./yarn --log=/dev/stdout "$DATADIR/empty.yarn" | + grep 'No scenario code blocks' > /dev/null diff --git a/yarnlib/mdparser.py b/yarnlib/mdparser.py index 9917f8b..7884630 100644 --- a/yarnlib/mdparser.py +++ b/yarnlib/mdparser.py @@ -68,6 +68,7 @@ class MarkdownParser(object): f = StringIO.StringIO() markdown.markdown(text, output=f, extensions=[ext]) self.blocks.extend(ext.blocks) + return ext.blocks def parse_file(self, filename): # pragma: no cover with open(filename) as f: diff --git a/yarnlib/mdparser_tests.py b/yarnlib/mdparser_tests.py index a9b9cb7..099ff2b 100644 --- a/yarnlib/mdparser_tests.py +++ b/yarnlib/mdparser_tests.py @@ -27,7 +27,7 @@ class MarkdownParserTests(unittest.TestCase): self.parser = yarnlib.MarkdownParser() def test_finds_code_block(self): - self.parser.parse_string(''' + result = self.parser.parse_string(''' This is blah blah text. this is a code block @@ -35,6 +35,7 @@ This is blah blah text. More text. ''') self.assertEqual(self.parser.blocks, ['this is a code block\n']) + self.assertEqual(result, ['this is a code block\n']) def test_finds_consecutive_code_blocks_as_one(self): self.parser.parse_string(''' @@ -83,11 +84,13 @@ More text. self.assertEqual(self.parser.blocks, ['this is a code block\n']) def test_parses_multiple_files(self): - self.parser.parse_string(''' + result1 = self.parser.parse_string(''' block 1 ''') - self.parser.parse_string(''' + result2 = self.parser.parse_string(''' block 2 ''') + self.assertEqual(result1, ['block 1\n']) + self.assertEqual(result2, ['block 2\n']) self.assertEqual(self.parser.blocks, ['block 1\n', 'block 2\n']) |