Package org.apache.calcite.test
Class DiffTestCase
java.lang.Object
org.apache.calcite.test.DiffTestCase
DiffTestCase is an abstract base for JUnit tests which produce multi-line
output to be verified by diffing against a pre-existing reference file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable FileName of current .log file.protected @Nullable OutputStreamOutputStream for current test log.protected @Nullable FileName of current .ref file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDiffTestCase(String testCaseName) Initializes a new DiffTestCase. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDiffMask(String mask) Adds a diff mask.protected voidaddIgnorePattern(String javaPattern) static StringReturns a string containing the difference between the contents of two files.protected voidCompares a log file with its reference log.static StringReturns a string containing the difference between the two sets of lines.protected voidFinishes a diff-based test.protected static StringfileContents(File file) Returns the contents of a file as a string.protected abstract FileReturns the root directory under which test logs should be written.protected WriterInitializes a diff-based test.protected OutputStreamopenTestLogOutputStream(File testFileSansExt) Initializes a diff-based test, overriding the default log file naming scheme altogether.protected voidSets the diff masks that are common to .REF filesprotected voidsetUp()protected voidsetVerbose(boolean verbose) Sets whether to give verbose message if diff fails.protected voidtearDown()
-
Field Details
-
logFile
Name of current .log file. -
refFile
Name of current .ref file. -
logOutputStream
OutputStream for current test log.
-
-
Constructor Details
-
DiffTestCase
Initializes a new DiffTestCase.- Parameters:
testCaseName- Test case name
-
-
Method Details
-
setUp
@BeforeEach protected void setUp() -
tearDown
- Throws:
IOException
-
openTestLog
Initializes a diff-based test. Any existing .log and .dif files corresponding to this test case are deleted, and a new, empty .log file is created. The default log file location is a subdirectory under the result getTestlogRoot(), where the subdirectory name is based on the unqualified name of the test class. The generated log file name will be testMethodName.log, and the expected reference file will be testMethodName.ref.- Returns:
- Writer for log file, which caller should use as a destination for test output to be diffed
- Throws:
Exception
-
getTestlogRoot
Returns the root directory under which test logs should be written. -
openTestLogOutputStream
Initializes a diff-based test, overriding the default log file naming scheme altogether.- Parameters:
testFileSansExt- full path to log filename, without .log/.ref extension- Throws:
IOException
-
diffTestLog
Finishes a diff-based test. Output that was written to the Writer returned by openTestLog is diffed against a .ref file, and if any differences are detected, the test case fails. Note that the diff used is just a boolean test, and does not create any .dif ouput.NOTE: if you wrap the Writer returned by openTestLog() (e.g. with a PrintWriter), be sure to flush the wrapping Writer before calling this method.
- Throws:
IOException- See Also:
-
diffFile
Compares a log file with its reference log.Usually, the log file and the reference log are in the same directory, one ending with '.log' and the other with '.ref'.
If the files are identical, removes logFile.
- Parameters:
logFile- Log filerefFile- Reference log- Throws:
IOException
-
addDiffMask
Adds a diff mask. Strings matching the given regular expression will be masked before diffing. This can be used to suppress spurious diffs on a case-by-case basis.- Parameters:
mask- a regular expression, as per String.replaceAll
-
addIgnorePattern
-
diff
Returns a string containing the difference between the contents of two files. The string has a similar format to the UNIX 'diff' utility. -
diffLines
Returns a string containing the difference between the two sets of lines. -
fileContents
Returns the contents of a file as a string.- Parameters:
file- File- Returns:
- Contents of the file
-
setVerbose
protected void setVerbose(boolean verbose) Sets whether to give verbose message if diff fails. -
setRefFileDiffMasks
protected void setRefFileDiffMasks()Sets the diff masks that are common to .REF files
-