forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutoFormatTests.java
More file actions
64 lines (55 loc) · 1.7 KB
/
AutoFormatTests.java
File metadata and controls
64 lines (55 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package processing.mode.java;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static processing.mode.java.ProcessingTestUtil.res;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
public class AutoFormatTests {
@BeforeClass
public static void init() {
ProcessingTestUtil.init();
}
static void expectGood(final String id) {
try {
final String formattedProgram = ProcessingTestUtil.format(res(id + ".pde"));
final File goldenFile = res(id + ".expected");
checkGolden(formattedProgram, goldenFile);
// check that the formatted text doesn't change
checkGolden(ProcessingTestUtil.format(formattedProgram), goldenFile);
} catch (Exception e) {
if (!e.equals(e.getCause()) && e.getCause() != null)
fail(e.getCause().toString());
else
e.printStackTrace(System.err);
fail(e.toString());
}
}
private static void checkGolden(final String expectedText,
final File goldenFile) throws IOException {
if (goldenFile.exists()) {
final String expected = ProcessingTestUtil.read(goldenFile);
assertEquals(expected, expectedText);
} else {
System.err.println("WARN: golden file " + goldenFile
+ " does not exist. Generating.");
final FileWriter sug = new FileWriter(goldenFile);
sug.write(ProcessingTestUtil.normalize(expectedText));
sug.close();
}
}
@Test
public void bug109() {
expectGood("bug109");
}
@Test
public void bug405() {
expectGood("bug405");
}
@Test
public void bug420() {
expectGood("bug420");
}
}