- java.lang.Object
-
- javax0.jamal.testsupport.TestAll
-
public class TestAll extends java.lang.Object
Test support methods that read from resources, execute Jamal and compare the result with other resource content.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TestAll.AssertEquals
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
failAsExpected()
Test that all files that are processed fail.TestAll
filesWithExtension(java.lang.String extension)
Set the extension filter for selecting input or output files.java.lang.String
getActual()
When a test fails then the field 'actual' will contain the actual result.java.lang.String
getExpected()
When a test fails then the field 'expected' will contain the expected result.java.lang.String
getMessage()
When a test fails then the message is a user friendly text that help explain why the test failed.static TestAll
in(java.lang.Class<?> testClass)
Create a new instance that will work for the given test class.Input
inputFrom(java.lang.String testFileName)
Create an input from the file named.boolean
resultAsExpected()
Tests that the files are processed by Jamal just running OK and they all result the string that is in their expected file pair.TestAll
sep(java.lang.String open, java.lang.String close)
Set the macro opening and closing string as in the macro sep.static void
testExpected(java.lang.Object testThis, TestAll.AssertEquals asserter)
static void
testExpected(java.lang.Object testThis, TestAll.AssertEquals asserter, java.lang.String ext)
-
-
-
Method Detail
-
in
public static TestAll in(java.lang.Class<?> testClass)
Create a new instance that will work for the given test class. The test class is needed to know which directory the test resources are.- Parameters:
testClass
- the class that is using this utility.- Returns:
- a new TestAll instance initialized to be used from the given class
-
sep
public TestAll sep(java.lang.String open, java.lang.String close)
Set the macro opening and closing string as in the macro sep. The defaults are "{" and "}".- Parameters:
open
- the new opening stringclose
- the new closing string- Returns:
- this
-
filesWithExtension
public TestAll filesWithExtension(java.lang.String extension)
Set the extension filter for selecting input or output files.- Parameters:
extension
- is the ending of the files that we want to use in the test- Returns:
- this
-
resultAsExpected
public boolean resultAsExpected() throws java.io.IOException, BadSyntax
Tests that the files are processed by Jamal just running OK and they all result the string that is in their expected file pair.The typical use is
final TestAll tests = TestAll.in(this.getClass()).filesWithExtension(".expected"); if (!tests.resultAsExpected()) { Assertions.assertEquals(tests.getExpected(), tests.getActual(), tests.getMessage()); }
When the test fails on one of the files then the TestAll object will hold a meaningful message and also two different strings that show the difference between what we got and what we expected.
- Returns:
- true if the tests are ok, false otherwise
- Throws:
java.io.IOException
- if some of the files cannot be readBadSyntax
- if some of the files are bad
-
failAsExpected
public boolean failAsExpected() throws java.io.IOException, BadSyntax
Test that all files that are processed fail. The typical use is:final TestAll tests = TestAll.in(this.getClass()).filesWithExtension(".err"); if (!tests.failAsExpected()) { Assertions.assertEquals(tests.getExpected(), tests.getActual(), tests.getMessage()); }
The test checks that each file processing ends with a bad syntax exception thrown and that the exception is referring to a specific line and column. The test input should define the user defined macros
line
andcolumn
to hold the position of the error. For example:{@define line=4}{@define column=5}
to signal that this file should fail in the line 4 at the column 5. The input optionally can define a user defined macro
message
that may contain the start of the error message. If there is nomessage
defined then it is not checked and this is not an error.line
andcolumn
must be defined.When some of the files do not fail or fail at a different location or throw a different error message than defined in the input then the TestAll object will hold a meaningful message and also two different strings that show the difference between what we got and what we expected.
- Returns:
- true if the tests are ok, false otherwise
- Throws:
java.io.IOException
- if some of the files cannot be readBadSyntax
- if some of the files are bad
-
inputFrom
public Input inputFrom(java.lang.String testFileName) throws java.io.IOException
Create an input from the file named.- Parameters:
testFileName
- the name of the test file from which the input is created.- Returns:
- the content of the file as input.
- Throws:
java.io.IOException
- if the file cannot be opened.
-
testExpected
public static void testExpected(java.lang.Object testThis, TestAll.AssertEquals asserter) throws java.io.IOException, BadSyntax
- Throws:
java.io.IOException
BadSyntax
-
testExpected
public static void testExpected(java.lang.Object testThis, TestAll.AssertEquals asserter, java.lang.String ext) throws java.io.IOException, BadSyntax
- Throws:
java.io.IOException
BadSyntax
-
getMessage
public java.lang.String getMessage()
When a test fails then the message is a user friendly text that help explain why the test failed. This method is a getter.- Returns:
- the message. If there was no error then it is empty string
-
getExpected
public java.lang.String getExpected()
When a test fails then the field 'expected' will contain the expected result. This is a getter for that. The calling code can execute anassertEquals(getExpected(),getActual())
line to get a developer friendly output that shows the difference between what was expected and what was the actual result.- Returns:
- the expected result.
-
getActual
public java.lang.String getActual()
When a test fails then the field 'actual' will contain the actual result. This is a getter for that. The calling code can execute anassertEquals(getExpected(),getActual())
line to get a developer friendly output that shows the difference between what was expected and what was the actual result.- Returns:
- the actual result.
-
-