Do not display trivial sets of next/previous instructions in test data

For better readability of test failures
This commit is contained in:
Andrey Breslav
2013-12-04 14:04:52 +04:00
parent e8c94a9d1d
commit 6a4043c9a0
38 changed files with 1171 additions and 1156 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.jet.cfg;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
@@ -121,11 +122,6 @@ public abstract class AbstractControlFlowTest extends KotlinTestWithEnvironment
}
File expectedInstructionsFile = JetTestUtils.replaceExtension(file, "instructions");
if (!expectedInstructionsFile.exists()) {
FileUtil.writeToFile(expectedInstructionsFile, instructionDump.toString());
fail("No expected instructions for " + FileUtil.getNameWithoutExtension(file) + " generated result is written into " + expectedInstructionsFile);
}
JetTestUtils.assertEqualsToFile(expectedInstructionsFile, instructionDump.toString());
// StringBuilder graphDump = new StringBuilder();
@@ -226,7 +222,7 @@ public abstract class AbstractControlFlowTest extends KotlinTestWithEnvironment
maxNextLength = instructionListText.length();
}
}
for (int i = 0, instructionsSize = instructions.size(); i < instructionsSize; i++) {
for (int i = 0; i < instructions.size(); i++) {
Instruction instruction = instructions.get(i);
if (instruction instanceof LocalFunctionDeclarationInstruction) {
LocalFunctionDeclarationInstruction localFunctionDeclarationInstruction = (LocalFunctionDeclarationInstruction) instruction;
@@ -238,15 +234,34 @@ public abstract class AbstractControlFlowTest extends KotlinTestWithEnvironment
}
}
out.append(formatInstruction(instruction, maxLength, remainedAfterPostProcessInstructions)).
append(" NEXT:").append(String.format("%1$-" + maxNextLength + "s", formatInstructionList(instruction.getNextInstructions()))).
append(" PREV:").append(formatInstructionList(instruction.getPreviousInstructions())).append("\n");
out.append(formatInstruction(instruction, maxLength, remainedAfterPostProcessInstructions));
// Only print NEXT and PREV if the values are non-trivial
Instruction next = i == instructions.size() - 1 ? null : instructions.get(i + 1);
Collection<Instruction> nextInstructions = instruction.getNextInstructions();
if (!sameContents(next, nextInstructions)) {
out.append(" NEXT:").append(String.format("%1$-" + maxNextLength + "s", formatInstructionList(nextInstructions)));
}
Instruction prev = i == 0 ? null : instructions.get(i - 1);
Collection<Instruction> previousInstructions = instruction.getPreviousInstructions();
if (!sameContents(prev, previousInstructions)) {
out.append(" PREV:").append(formatInstructionList(previousInstructions));
}
out.append("\n");
}
for (PseudocodeImpl local : locals) {
dumpInstructions(local, out);
}
}
private static boolean sameContents(@Nullable Instruction natural, Collection<Instruction> actual) {
if (natural == null) {
return actual.isEmpty();
}
return Collections.singleton(natural).equals(new HashSet<Instruction>(actual));
}
public void dumpEdges(List<Instruction> instructions, final PrintStream out, final int[] count, final Map<Instruction, String> nodeToName) {
for (Instruction fromInst : instructions) {
fromInst.accept(new InstructionVisitor() {