The current unit tests force the developer to inherit from JUnitTest and then uses an overloaded method to actually execute the test.
Following snippet builds the test a bit more slowly but it clearly states what are the individual strings (note that newlines are added automatically to individual arguments of the setSource to decrease occurrences of the escape sequences). The first test uses fluent interface to make the code more compact.
@Test
public void copy() {
TruppleTest
.create()
.setSource(
"program copy;",
"var i : integer;",
"begin readln(i); writeln(i); end."
)
.setInput("42");
.expectsOutput("42");
.run();
}
@Test
public void simpleUnit() {
TruppleTest test = new TruppleTest();
test.addImport(
"UNIT math;",
"",
"INTERFACE",
"",
"function add(a,b:integer): integer;",
/* etc. */
);
test.setStandard("tp6");
test.setSource(
"uses math;",
"begin",
" write(add(3,5));",
"end."
);
test.expectsOutput("8");
test.run();
}
The current unit tests force the developer to inherit from
JUnitTestand then uses an overloaded method to actually execute the test.Following snippet builds the test a bit more slowly but it clearly states what are the individual strings (note that newlines are added automatically to individual arguments of the
setSourceto decrease occurrences of the escape sequences). The first test uses fluent interface to make the code more compact.