|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object junit.framework.Assert junit.framework.TestCase org.eigenbase.test.DiffTestCase
public abstract class 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 | |
---|---|
(package private) Matcher |
compiledDiffMatcher
|
(package private) Matcher |
compiledIgnoreMatcher
|
private String |
diffMasks
Diff masks defined so far |
(package private) int |
gcInterval
|
private String |
ignorePatterns
|
protected File |
logFile
Name of current .log file. |
protected OutputStream |
logOutputStream
OutputStream for current test log. |
protected File |
refFile
Name of current .ref file. |
private boolean |
verbose
Whether to give verbose message if diff fails. |
Constructor Summary | |
---|---|
protected |
DiffTestCase(String testCaseName)
Initializes a new DiffTestCase. |
Method Summary | |
---|---|
protected void |
addDiffMask(String mask)
Adds a diff mask. |
protected void |
addIgnorePattern(String javaPattern)
|
private String |
applyDiffMask(String s)
|
private static String |
diff(File file1,
File file2)
Returns a string containing the difference between the contents of two files. |
private void |
diffFail(File logFile,
int lineNumber)
|
protected void |
diffFile(File logFile,
File refFile)
Compares a log file with its reference log. |
static String |
diffLines(List<String> lines1,
List<String> lines2)
Returns a string containing the difference between the two sets of lines. |
protected void |
diffTestLog()
Finishes a diff-based test. |
protected static String |
fileContents(File file)
Returns the contents of a file as a string. |
private static List<String> |
fileLines(File file)
Returns a list of the lines in a given file. |
protected abstract File |
getTestlogRoot()
|
private static boolean |
inIde()
Returns whether this test is running inside the IntelliJ IDE. |
private boolean |
matchIgnorePatterns(String s)
|
protected Writer |
openTestLog()
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 |
setGC(int n)
set the number of lines for garbage collection. |
protected void |
setRefFileDiffMasks()
Sets the diff masks that are common to .REF files |
protected void |
setUp()
|
protected void |
setVerbose(boolean verbose)
Sets whether to give verbose message if diff fails. |
protected void |
tearDown()
|
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected File logFile
protected File refFile
protected OutputStream logOutputStream
private String diffMasks
Matcher compiledDiffMatcher
private String ignorePatterns
Matcher compiledIgnoreMatcher
int gcInterval
private boolean verbose
Constructor Detail |
---|
protected DiffTestCase(String testCaseName) throws Exception
testCaseName
- JUnit test case name
Exception
Method Detail |
---|
protected void setUp() throws Exception
setUp
in class TestCase
Exception
protected void tearDown() throws Exception
tearDown
in class TestCase
Exception
protected Writer openTestLog() throws Exception
Exception
protected abstract File getTestlogRoot() throws Exception
Exception
protected OutputStream openTestLogOutputStream(File testFileSansExt) throws IOException
testFileSansExt
- full path to log filename, without .log/.ref
extension
IOException
protected void diffTestLog() throws IOException
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.
IOException
diffFile(File, File)
protected void diffFile(File logFile, File refFile) throws IOException
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.
logFile
- Log filerefFile
- Reference log
IOException
protected void setGC(int n)
n
- an integer, the number of line for garbage collection, 0 means
no garbage collection.protected void addDiffMask(String mask)
mask
- a regular expression, as per String.replaceAllprotected void addIgnorePattern(String javaPattern)
private String applyDiffMask(String s)
private boolean matchIgnorePatterns(String s)
private void diffFail(File logFile, int lineNumber)
private static boolean inIde()
private static String diff(File file1, File file2)
public static String diffLines(List<String> lines1, List<String> lines2)
private static List<String> fileLines(File file)
file
- File
protected static String fileContents(File file)
file
- File
protected void setVerbose(boolean verbose)
protected void setRefFileDiffMasks()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |