Skip to content

Commit

Permalink
Added feature to test suite to dump actual result of running ecj / de…
Browse files Browse the repository at this point in the history
…lombok on things to a directory (use -Dlombok.tests.dump_actual_files=/path/to/dir).

Useful if you KNOW lombok is working but something changed in output, i.e. order of generated methods.
  • Loading branch information
rzwitserloot committed Jul 16, 2012
1 parent e642150 commit bd2d76b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/core/src/lombok/AbstractRunTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
Expand All @@ -35,6 +36,11 @@

public abstract class AbstractRunTests {
protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
private final File dumpActualFilesHere;

public AbstractRunTests() {
this.dumpActualFilesHere = findPlaceToDumpActualFiles();
}

public boolean compareFile(DirectoryRunner.TestParams params, File file) throws Throwable {
StringBuilder messages = new StringBuilder();
Expand Down Expand Up @@ -82,6 +88,25 @@ private String readFile(File dir, File file, boolean messages) throws IOExceptio
return readFile(new File(dir, file.getName() + (messages ? ".messages" : "")));
}

private static File findPlaceToDumpActualFiles() {
String location = System.getProperty("lombok.tests.dump_actual_files");
if (location != null) {
File dumpActualFilesHere = new File(location);
dumpActualFilesHere.mkdirs();
return dumpActualFilesHere;
}
return null;
}

private static void dumpToFile(File file, String content) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
try {
fos.write(content.getBytes("UTF-8"));
} finally {
fos.close();
}
}

private void compare(String name, String expectedFile, String actualFile, String expectedMessages, String actualMessages, boolean printErrors) throws Throwable {
try {
compareContent(name, expectedFile, actualFile);
Expand All @@ -99,6 +124,9 @@ private void compare(String name, String expectedFile, String actualFile, String
}
System.out.println("*******************");
}
if (dumpActualFilesHere != null) {
dumpToFile(new File(dumpActualFilesHere, name), actualFile);
}
throw e;
}
try {
Expand All @@ -113,6 +141,9 @@ private void compare(String name, String expectedFile, String actualFile, String
System.out.println(actualMessages);
System.out.println("*******************");
}
if (dumpActualFilesHere != null) {
dumpToFile(new File(dumpActualFilesHere, name + ".messages"), actualMessages);
}
throw e;
}
}
Expand Down

0 comments on commit bd2d76b

Please sign in to comment.