Skip to content

Commit

Permalink
Merge pull request #5 from catseye/freestyle-input
Browse files Browse the repository at this point in the history
Support for input in freestyle format
  • Loading branch information
cpressey authored Oct 26, 2018
2 parents a561c48 + 32b9a80 commit 78c7399
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 24 deletions.
3 changes: 3 additions & 0 deletions HISTORY.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Version 0.12 "Schoenhofen Brewery" (current development version):
`string.replace` instead of `re.sub` so that backslash-escaping
is not perfomed on the replacement string. (Thanks to
James Holderness for bug report and patch.)
* In "freestyle" format, lines beginning with `<= `, `<== `, or
`<=== ` can supply a section of test input text (Thanks to
James Holderness for feature suggestion and patch.)

Version 0.11 "Dan Ryan Expressway" (current released version):

Expand Down
33 changes: 27 additions & 6 deletions doc/Falderal_Literate_Test_Format.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This document describes the proposed Falderal Literate Test Format.
Status
------

This document is a *draft*. It is nominally "version 0.11" because it
describes something that version 0.11 of `py-falderal` mostly implements.
This document is a *draft*. It is nominally "version 0.12" because it
describes something that version 0.12 of `py-falderal` mostly implements.
We will deign to note which sections of this document the current released
version of `py-falderal` implements, and which it does not. However,
this document is a work in progress, subject to change, and subject to get
Expand Down Expand Up @@ -89,10 +89,18 @@ introducers:
* `??> `: expected error text
* `???> `: expected error text

In addition, the following introducers may be used to mark a section
of test input text on the first of the final lines (but may not be
used to end a block):

* `<= `: test input text
* `<== `: test input text
* `<=== `: test input text

If a block is identified as a freestyle block, all lines preceding the
final lines with one of these introducers, are interpreted as having
no introducer at all (even if they begin with `| ` or some other sequence
already mentioned) and are used as the test body block.
first final line appearing with one of these introducers, are interpreted
as having no introducer at all (even if they begin with `| ` or some other
sequence already mentioned) and are used as the test body block.

Lines without introducers are called _intervening text_.
Lines of intervening text are classified as either blank or non-blank. A
Expand Down Expand Up @@ -265,6 +273,14 @@ Valid examples in the "freestyle" format:
thing to test
???> error to expect

thing to test
<=== input to give it
===> output to expect

thing to test
<=== input to give it
???> error to expect

Invalid examples:

| thing to test
Expand All @@ -274,7 +290,12 @@ Invalid examples:
+ input to give it
= output to expect

...test input must be preceded by a test body (if this is the first test.)
...test input must be preceded by a test body, if this is the first test.

<=== input to give it
???> output to expect

...test input must be preceded by a test body always, in freestyle format.

? error to expect

Expand Down
3 changes: 3 additions & 0 deletions src/falderal/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class Block(object):
"""

FREESTYLE_MAP = {
u'<= ': u'+ ',
u'<== ': u'+ ',
u'<=== ': u'+ ',
u'=> ': u'= ',
u'==> ': u'= ',
u'===> ': u'= ',
Expand Down
25 changes: 22 additions & 3 deletions tests/test-freestyle-format.expected
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,32 @@ Demonstrate error expectation (Intentional fail.)
Location: test-freestyle-format.markdown, line 68
Function: Cat
Impl : shell command "python cat.py"
Body : meow
Body :
| meow
? rreoww
Expected: error:
bow
wow
Actual : output:
meow
| meow
? rreoww

FAILED :

The trick of re-using the previous test body with a different
test input if the test body is omitted doesn't work with
freestyle-format test input sections (i.e., this will fail.)

Location: test-freestyle-format.markdown, line 111
Function: Silly Interpreter
Impl : shell command "python silly-interpreter.py %(test-body-file)"
Body :
Expected: output:
zang
zing
Actual : output:


--------------------------------
Total test runs: 10, failures: 3
Total test runs: 14, failures: 4
--------------------------------
72 changes: 58 additions & 14 deletions tests/test-freestyle-format.markdown
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Falderal Test: "new" format for tests
Falderal Test: "freestyle" format for tests
-------------------------------------

This document tests the alternate format for tests introduced in
the Falderal Literate Test Format version 0.11. This format allows
the test body to consist entirely of un-prefixed text, as long as
it is written in a single indented block, and the final line(s) of
the test begin with one of the prefixes `=> ` or `==> ` or `===> `
or `?> ` or `??> `or `???> `.
This document tests the alternate ("freestyle") format for tests
introduced in the Falderal Literate Test Format version 0.11. This
format allows the test body to consist entirely of un-prefixed text,
as long as it is written in a single indented block, and as long as
the final line(s) of the test begin with one of the prefixes
`=> ` or `==> ` or `===> ` or `?> ` or `??> `or `???> `.

-> Functionality "Cat" is implemented by shell command "python cat.py"

Expand Down Expand Up @@ -38,17 +38,17 @@ as prefixes.

| purr
| prrr
| prreow
==> | purr
==> | prrr
==> | prreow
= prreow
=> | purr
=> | prrr
=> = prreow

| purr
+ prrr
+ prreow
? prreow
=> | purr
=> + prrr
=> + prreow
=> ? prreow

purr
-> prrr
Expand All @@ -65,6 +65,50 @@ Demonstrate error expectation (Intentional fail.)
meow
??> woof

meow
| meow
? rreoww
???> bow
???> wow

Freestyle-format tests can also contain input sections.

-> Functionality "Silly Interpreter" is implemented by
-> shell command "python silly-interpreter.py %(test-body-file)"

-> Tests for functionality "Silly Interpreter"

read x
read y
print y
print x
<= meow
<= purr
=> purr
=> meow

read x
read y
print y
print x
<== meow
<== purr
==> purr
==> meow

read x
read y
print y
print x
<=== meow
<=== purr
===> purr
===> meow

The trick of re-using the previous test body with a different
test input if the test body is omitted doesn't work with
freestyle-format test input sections (i.e., this will fail.)

<== zing
<== zang
==> zang
==> zing
2 changes: 1 addition & 1 deletion tests/test-input-sections.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--------------------------------
Total test runs: 5, failures: 0
Total test runs: 6, failures: 0
--------------------------------
8 changes: 8 additions & 0 deletions tests/test-input-sections.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ Test tests that have test input sections.
+ purr
= purr
= meow

If the input section appears first (i.e. there is no test body),
the previous test body is re-used.

+ zing
+ zang
= zang
= zing

0 comments on commit 78c7399

Please sign in to comment.