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
Modifier and TypeFieldDescriptionprotected File
Name of current .log file.protected OutputStream
OutputStream for current test log.protected File
Name of current .ref file. -
Constructor Summary
ModifierConstructorDescriptionprotected
DiffTestCase
(String testCaseName) Initializes a new DiffTestCase. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addDiffMask
(String mask) Adds a diff mask.protected void
addIgnorePattern
(String javaPattern) static String
Returns a string containing the difference between the contents of two files.protected void
Compares a log file with its reference log.static String
Returns a string containing the difference between the two sets of lines.protected void
Finishes a diff-based test.protected static String
fileContents
(File file) Returns the contents of a file as a string.protected abstract File
Returns the root directory under which testlogs should be written.protected Writer
Initializes a diff-based test.protected OutputStream
openTestLogOutputStream
(File testFileSansExt) Initializes a diff-based test, overriding the default log file naming scheme altogether.protected void
Sets the diff masks that are common to .REF filesprotected void
setUp()
protected void
setVerbose
(boolean verbose) Sets whether to give verbose message if diff fails.protected void
tearDown()
-
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- Throws:
Exception
-
-
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 testlogs should be written.- Throws:
Exception
-
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
-