Skip to content

Commit d6e6a1b

Browse files
committed
Fast way to regenerate checked tree when needed
1 parent c3d8a6d commit d6e6a1b

File tree

1 file changed

+8
-6
lines changed
  • graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser

1 file changed

+8
-6
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/ParserTestBase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class ParserTestBase {
7474
protected boolean printFormatStringLiteralValues = false;
7575
protected int printOnlyDiffIfLenIsBigger = 1000;
7676

77+
private static final boolean REGENERATE_TREE = false;
78+
7779
@Rule public TestName name = new TestName();
7880

7981
private ScopeInfo lastGlobalScope;
@@ -155,7 +157,7 @@ public void saveNewTreeResult(File testFile, boolean goldenFileNextToTestFile) t
155157
File newGoldenFile = goldenFileNextToTestFile
156158
? new File(testFile.getParentFile(), getFileName(testFile) + NEW_GOLDEN_FILE_EXT)
157159
: getGoldenFile(NEW_GOLDEN_FILE_EXT);
158-
if (!newGoldenFile.exists()) {
160+
if (REGENERATE_TREE || !newGoldenFile.exists()) {
159161
try (FileWriter fw = new FileWriter(newGoldenFile)) {
160162
fw.write(tree);
161163
}
@@ -172,7 +174,7 @@ public void checkTreeFromFile(File testFile, boolean goldenFileNextToTestFile) t
172174
File goldenFile = goldenFileNextToTestFile
173175
? new File(testFile.getParentFile(), getFileName(testFile) + GOLDEN_FILE_EXT)
174176
: getGoldenFile(GOLDEN_FILE_EXT);
175-
if (!goldenFile.exists()) {
177+
if (REGENERATE_TREE || !goldenFile.exists()) {
176178
try (FileWriter fw = new FileWriter(goldenFile)) {
177179
fw.write(tree);
178180
}
@@ -192,7 +194,7 @@ public void saveNewScope(File testFile, boolean goldenFileNextToTestFile) throws
192194
File newScopeFile = goldenFileNextToTestFile
193195
? new File(testFile.getParentFile(), getFileName(testFile) + NEW_SCOPE_FILE_EXT)
194196
: getGoldenFile(NEW_SCOPE_FILE_EXT);
195-
if (!newScopeFile.exists()) {
197+
if (REGENERATE_TREE || !newScopeFile.exists()) {
196198
try (FileWriter fw = new FileWriter(newScopeFile)) {
197199
fw.write(scopes.toString());
198200
}
@@ -210,7 +212,7 @@ public void checkScopeFromFile(File testFile, boolean goldenFileNextToTestFile)
210212
File goldenScopeFile = goldenFileNextToTestFile
211213
? new File(testFile.getParentFile(), getFileName(testFile) + SCOPE_FILE_EXT)
212214
: getGoldenFile(SCOPE_FILE_EXT);
213-
if (!goldenScopeFile.exists()) {
215+
if (REGENERATE_TREE || !goldenScopeFile.exists()) {
214216
try (FileWriter fw = new FileWriter(goldenScopeFile)) {
215217
fw.write(scopes.toString());
216218
}
@@ -223,7 +225,7 @@ public void checkTreeResult(String source, PythonParser.ParserMode mode, Frame f
223225
Node resultNew = parse(source, name.getMethodName(), mode, frame);
224226
String tree = printTreeToString(resultNew);
225227
File goldenFile = getGoldenFile(GOLDEN_FILE_EXT);
226-
if (!goldenFile.exists()) {
228+
if (REGENERATE_TREE || !goldenFile.exists()) {
227229
try (FileWriter fw = new FileWriter(goldenFile)) {
228230
fw.write(tree);
229231
}
@@ -242,7 +244,7 @@ public void checkScopeResult(String source, PythonParser.ParserMode mode) throws
242244
StringBuilder scopes = new StringBuilder();
243245
scopeNew.debugPrint(scopes, 0);
244246
File goldenScopeFile = getGoldenFile(SCOPE_FILE_EXT);
245-
if (!goldenScopeFile.exists()) {
247+
if (REGENERATE_TREE || !goldenScopeFile.exists()) {
246248
try (FileWriter fw = new FileWriter(goldenScopeFile)) {
247249
fw.write(scopes.toString());
248250
}

0 commit comments

Comments
 (0)