git @ Cat's Eye Technologies Falderal / b1983ce
Allow giving differing inputs to multiple tests with same body. Chris Pressey 7 years ago
5 changed file(s) with 33 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
8080 that stdout and stderr will always be combined deterministically, and
8181 having both kinds of expectations would allow non-deterministic combinations
8282 of the two to be matched.)
83
84 ### Support specifying different input to multiple tests with same body
85
86 We can currently say
87
88 | (* 5 (read))
89 + 100
90 = 500
91
92 It would be nice if the same test body block could be re-used with multiple
93 test input blocks.
94
95 | (* 5 (read))
96 + 100
97 = 500
98
99 + 5
100 = 25
10183
10284 ### Allow expectations to be transformed during comparison
10385
55 Status
66 ------
77
8 This document is a *draft*. It is nominally "version 0.9" because it
9 describes something that version 0.9 of `py-falderal` mostly implements.
8 This document is a *draft*. It is nominally "version 0.10" because it
9 describes something that version 0.10 of `py-falderal` mostly implements.
1010 We will deign to note which sections of this document the current released
11 version of `pt-falderal` implements, and which it does not. However,
11 version of `py-falderal` implements, and which it does not. However,
1212 this document is a work in progress, subject to change, and subject to get
1313 out of sync with `py-falderal`. It should not be considered to be
1414 anything except a draft until it is described as "version 1.0".
5656
5757 * Test body text should occur after intervening text.
5858 * Test body test may be optionally followed by test input text.
59 Test input text must be immediately preceded by test body text,
59 * The first test input text must be immediately preceded by test body text,
6060 with no intervening text.
61 * Subsequent test input texts need not be preceded by a test body text;
62 in this case, the previously-defined test body text will be used again.
6163 * Test body text must be followed by either test input text, expected
6264 output text, or expected error text, with no intervening text.
6365 * Either expected output or error text must follow either test body
230232 + input to give it
231233 ? error to expect
232234
235 + different input to give the immediately previously defined test body
236 ? different error to expect
237
233238 Invalid examples:
234239
235240 | thing to test
239244 + input to give it
240245 = output to expect
241246
242 ...test input must be preceded by a test body.
247 ...test input must be preceded by a test body (if this is the first test.)
243248
244249 ? error to expect
245250
317317 >>> d.append(u' | Test with input')
318318 >>> d.append(u' + input-for-test')
319319 >>> d.append(u' = Expected result on output')
320 >>> d.append(u' + Other input-for-test')
321 >>> d.append(u' = Other Expected result on output')
320322 >>> d.append(u' -> Tests for functionality "Run Thing"')
321323 >>> d.append(u" | Thing")
322324 >>> d.append(u' ? Oops')
323325 >>> tests = d.parse_blocks_to_tests(funs)
324326 >>> [t.body for t in tests]
325327 [u'This is some test input.\nIt extends over two lines.',
326 u'Test with input', u'Thing']
328 u'Test with input', u'Test with input', u'Thing']
327329 >>> [t.input_block for t in tests]
328 [None, TestInput(u' + ', line_num=7, filename=None), None]
330 [None, TestInput(u' + ', line_num=7, filename=None),
331 TestInput(u' + ', line_num=9, filename=None), None]
329332 >>> tests[1].input_block.text()
330333 u'input-for-test'
334 >>> tests[2].input_block.text()
335 u'Other input-for-test'
331336 >>> [t.expectation for t in tests]
332 [ErrorOutcome(u'Expected Error'), OutputOutcome(u'Expected result on output'),
337 [ErrorOutcome(u'Expected Error'),
338 OutputOutcome(u'Expected result on output'),
339 OutputOutcome(u'Other Expected result on output'),
333340 ErrorOutcome(u'Oops')]
334341 >>> [t.functionality.name for t in tests]
335 [u'Parse Thing', u'Parse Thing', u'Run Thing']
342 [u'Parse Thing', u'Parse Thing', u'Parse Thing', u'Run Thing']
336343 >>> sorted(funs.keys())
337344 [u'Parse Thing', u'Run Thing']
338345
397404 prev_block = None
398405 last_desc_block = None
399406 last_test_body_block = None
407 last_used_test_body_block = None
400408 last_test_input_block = None
401409 for block in self.blocks:
402410 # First, handle ExpectedError/ExpectedOutcome blocks.
421429 functionality=current_functionality,
422430 desc_block=last_desc_block)
423431 tests.append(test)
432 last_used_test_body_block = last_test_body_block
424433 last_test_body_block = None
425434 last_test_input_block = None
426435 elif isinstance(block, TestInput):
427 # Test input must be preceded by TestBody.
436 # First test input must be preceded by TestBody.
428437 if not isinstance(prev_block, TestBody):
429 raise FalderalSyntaxError(
430 ("line %d: " % block.line_num) +
431 "test input must be preceded by test body")
438 if last_used_test_body_block is None:
439 raise FalderalSyntaxError(
440 ("line %d: " % block.line_num) +
441 "test input must be preceded by test body")
442 else:
443 # Subsequent test input not preceded by body
444 # shares most recently defined body.
445 last_test_body_block = last_used_test_body_block
432446 # If we see a TestInput block, record it.
433447 last_test_input_block = block
434448 elif isinstance(block, TestBody):
11
22 # Really crude test harness for py-falderal itself...
33
4 bin/falderal -t || exit 1
4 bin/falderal -v -t || exit 1
55
66 cd tests
77
+0
-1
tests/test-shared-body.actual less more
0 FalderalSyntaxError: line 19: test input must be preceded by test body