mirror of https://github.com/japl-lang/japl.git
Removed test duplicates, fixed tests.
Added documentation for the JATS markup.
This commit is contained in:
parent
ad74c45213
commit
6ff9577f66
|
@ -1,10 +1,3 @@
|
|||
[Test: read_in_own_init]
|
||||
[source: mixed]
|
||||
var a = 1; { var a = a; }
|
||||
//stderr:A fatal error occurred while compiling '''', line 1, at ';' -> cannot read local variable in its own initializer
|
||||
[end]
|
||||
[end]
|
||||
|
||||
[Test: read_in_own_init_regex]
|
||||
[source: raw]
|
||||
var a = 1; { var a = a; }
|
||||
|
|
|
@ -1,15 +1,3 @@
|
|||
[Test: undefname]
|
||||
[source: mixed]
|
||||
var a = b;
|
||||
//stderr:An unhandled exception occurred, traceback below:
|
||||
|
||||
//stderr: File '''', line 1, in <module>:
|
||||
|
||||
//stderr:ReferenceError: undefined name 'b'
|
||||
|
||||
[end]
|
||||
[end]
|
||||
|
||||
[Test: undefname_raw]
|
||||
[source: raw]
|
||||
var a = b;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
[Test: unsup_binary_instr]
|
||||
[source: mixed]
|
||||
[source: raw]
|
||||
var a = 2 + "hey";
|
||||
//stderr:An unhandled exception occurred, traceback below:
|
||||
|
||||
//stderr: File '''', line 1, in <module>:
|
||||
|
||||
//stderr:TypeError: unsupported binary operator '+' for objects of type 'integer' and 'string'
|
||||
[end]
|
||||
[stderr]
|
||||
An unhandled exception occurred, traceback below:
|
||||
File '''', line 1, in <module>:
|
||||
TypeError: unsupported binary operator '+' for objects of type 'integer' and 'string'
|
||||
[end]
|
||||
[end]
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[Test: hello]
|
||||
[source:mixed]
|
||||
print("Hello, world.");
|
||||
//stdout:Hello, world.
|
||||
[end]
|
||||
[end]
|
|
@ -1,12 +1,3 @@
|
|||
[Test: inputtest]
|
||||
[skip]
|
||||
[source: mixed]
|
||||
//stdin:Hello world!
|
||||
print(readLine());
|
||||
//stdout:Hello world!
|
||||
[end]
|
||||
[end]
|
||||
|
||||
[Test: inputtesttwo]
|
||||
[skip]
|
||||
[source: raw]
|
||||
|
|
|
@ -89,9 +89,9 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test
|
|||
if inside:
|
||||
if parsed.mode == "end":
|
||||
# end inside
|
||||
if mode == "source" and (detail == "" or detail == "mixed"):
|
||||
if mode == "source" and (detail == "mixed"):
|
||||
result.parseMixed(body)
|
||||
elif mode == "source" and detail == "raw":
|
||||
elif mode == "source" and (detail == "raw" or detail == ""):
|
||||
result.parseSource(body)
|
||||
elif mode == "stdout" or mode == "stderr":
|
||||
let err = (mode == "stderr")
|
||||
|
@ -138,6 +138,7 @@ proc buildTest(lines: seq[string], i: var int, name: string, path: string): Test
|
|||
elif inside: # when not modal
|
||||
body &= line & "\n"
|
||||
inc i
|
||||
fatal &"Test mode unfinished (missing [end]?)."
|
||||
|
||||
proc buildTestFile(path: string): seq[Test] =
|
||||
log(LogLevel.Debug, &"Checking {path} for tests")
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
# JATS test markup specification
|
||||
|
||||
This document specifies the format tests are written
|
||||
in for JATS (Just Another Test Suite).
|
||||
|
||||
## Definitions
|
||||
|
||||
A **test file** represents a file inside the `~japl/tests/japl/` directory. All of these files are parsed
|
||||
to find any defined tests.
|
||||
|
||||
A test file can contain multiple tests. A **test** is a
|
||||
piece of JAPL source code, along with its input
|
||||
(given in stdin) and expected output (in stdout and stderr), or the means to construct these fields. It
|
||||
may also contain other metadata, such as the name
|
||||
of the test, or whether it is to be skipped.
|
||||
|
||||
The test files are parsed line by line. The parser
|
||||
switches **modes** during the parsing. The modes
|
||||
dictate the state of the parser, and where each line
|
||||
ends up (which field of which test).
|
||||
|
||||
There is a special mode, **root mode**, which describes
|
||||
the state of the parser when it just enters the file.
|
||||
It can stay in this state during parsing, can leave
|
||||
it by entering another mode and can
|
||||
return to it, by leaving any mode it has entered.
|
||||
|
||||
## Syntax
|
||||
|
||||
### Mode syntax
|
||||
|
||||
The modes are constructed from modelines,
|
||||
which are lines starting with the character '['.
|
||||
Modelines also have to be closed by a ']' character
|
||||
on the end of this line. These lines may not contain
|
||||
whitespace before the opening '[' nor after then ending
|
||||
']' characters. Inside the brackets, letters (case
|
||||
insensitive), numbers, underscores and dashes form\
|
||||
a name describing what the modeline does.
|
||||
|
||||
```
|
||||
[ name ]
|
||||
```
|
||||
|
||||
Optionally, an argument may be passed, which is
|
||||
separated by a colon.
|
||||
|
||||
```
|
||||
[ name : detail ]
|
||||
```
|
||||
|
||||
Whitespace inside the brackets is ignored (even inside
|
||||
names). More than one colon, or any character that
|
||||
is not whitespace, a letter, a digit, a colon, an
|
||||
underscore or a dash inside is a syntax error, which
|
||||
results in a fatal error, causing the whole test
|
||||
file to be invalid. The user is always warned when
|
||||
such a fatal syntax error occurs.
|
||||
|
||||
It is possible for lines beginning with '[' to not
|
||||
be modelines. When a line starts with '[[', it escapes
|
||||
the opening left bracket, as if the line was a regular
|
||||
one (the '[[' is reduced to '['). When a line starts
|
||||
with '[;' it is a comment, which is not a modeline nor
|
||||
a line that shows up in the current mode.
|
||||
|
||||
A different mode can be entered and left by the
|
||||
following syntax.
|
||||
|
||||
```
|
||||
[Modename]
|
||||
|
||||
[end]
|
||||
```
|
||||
|
||||
A modeline that is not defined to be a legal one
|
||||
for the current mode is a syntax error, which
|
||||
invalidates the whole test file. It also raises
|
||||
a visible warning to the user.
|
||||
|
||||
## Possible modes
|
||||
|
||||
### Root mode
|
||||
|
||||
Inside the root mode, all lines that are not modelines
|
||||
are assumed to be comments.
|
||||
|
||||
There is one possible mode to enter from the root mode,
|
||||
a test mode. The test modes are entered when the "test"
|
||||
mode line is specified. The detail for the modeline
|
||||
corresponds to the name of the test.
|
||||
|
||||
```
|
||||
[test: testname]
|
||||
|
||||
[end]
|
||||
```
|
||||
|
||||
### Test modes
|
||||
|
||||
Inside test modes, all lines that are not modelines are
|
||||
assumed to be comments.
|
||||
|
||||
There are different modelines that do actions or
|
||||
modes that can be entered from tests. They are all
|
||||
defined below.
|
||||
|
||||
#### Skipping a test
|
||||
|
||||
The modeline `skip` skips a test. It does not enter
|
||||
a different mode, so no `end` is neccessary.
|
||||
|
||||
```
|
||||
[skip]
|
||||
```
|
||||
|
||||
#### Adding JAPL source to a test
|
||||
|
||||
The modeline `source` enters the mode source, which
|
||||
is useful for appending to the JAPL source of the
|
||||
test.
|
||||
```
|
||||
[source]
|
||||
print("Hello from JAPL!");
|
||||
[end]
|
||||
```
|
||||
|
||||
There are two kinds of source modes, raw and mixed.
|
||||
Mixed source mode can be entered if the detail `mixed`
|
||||
is specified. Raw source mode can be entered if the
|
||||
detail `raw` is specified. When no detail is specified,
|
||||
raw source mode is entered.
|
||||
|
||||
In raw source mode, all lines in the mode are
|
||||
appended as they are to the JAPL source. In mixed
|
||||
mode, comments inside this JAPL source can be
|
||||
added to add lines to the expected stdout/stderr or
|
||||
the stdin of the test using the legacy test format.
|
||||
|
||||
They are defined by the sequences `//stdout:`,
|
||||
`//stderr:`, `//stdin:`, `//stdoutre:` and
|
||||
`//stderrre:`. Every character after the colon and
|
||||
before the end of the line is appended to the respective
|
||||
field of the test. `stdout` adds a raw line to be
|
||||
matched to the expected stdout of the test. `stdoutre`
|
||||
adds a regex to match a line of the stdout of the test.
|
||||
`stderr` and `stderrre` are the stderr equivalents.
|
||||
`stdin` adds a line to the stdin that the JAPL source
|
||||
can read from.
|
||||
|
||||
```
|
||||
[source: mixed]
|
||||
print("Hello from JAPL!");//stdout:Hello from JAPL!
|
||||
[end]
|
||||
```
|
||||
|
||||
#### Adding expected output to the test
|
||||
|
||||
The mode `stdout` can add standard output to expect
|
||||
from the JAPL source when it is ran.
|
||||
|
||||
```
|
||||
[test: hello]
|
||||
[source: raw]
|
||||
print("Banana.");
|
||||
[end]
|
||||
[stdout]
|
||||
Banana.
|
||||
[end]
|
||||
[end]
|
||||
```
|
||||
|
||||
The option `re` can be added if every line is to
|
||||
be a regex matched against a line of stdout.
|
||||
The option `nw` will strip leading and trailing
|
||||
whitespace from every line in the mode before
|
||||
adding it to the expected lines. The option `nwre`
|
||||
adds regex based matching lines after stripping
|
||||
whitespace.
|
||||
|
||||
The mode `stderr` does the same as `stdout`, but
|
||||
for the standard error. It accepts the same options.
|
||||
|
||||
#### Adding input to the test
|
||||
|
||||
The mode `stdin` can add standard input that the
|
||||
JAPL source of the test can read from.
|
||||
|
||||
```
|
||||
[test: inputtest]
|
||||
[source: raw]
|
||||
print(readLine());
|
||||
[end]
|
||||
[stdin]
|
||||
Hello there
|
||||
[end]
|
||||
[stdout]
|
||||
Hello there
|
||||
[end]
|
||||
```
|
||||
|
||||
#### Adding python to the tests
|
||||
|
||||
Coming soon.
|
||||
|
Loading…
Reference in New Issue