Throwing FileComparisonFailure enables opening test data file in diff dialog right from the test console
This commit is contained in:
@@ -27,10 +27,9 @@ import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.Tmpdir;
|
||||
import org.junit.ComparisonFailure;
|
||||
import org.junit.Rule;
|
||||
@@ -123,9 +122,8 @@ public abstract class KotlinIntegrationTestBase {
|
||||
fail("No .expected file " + expectedFile);
|
||||
}
|
||||
else {
|
||||
String goldContent = FileUtil.loadFile(expectedFile, CharsetToolkit.UTF8, true);
|
||||
try {
|
||||
assertEquals(goldContent, normalizedContent);
|
||||
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
|
||||
actualFile.delete();
|
||||
}
|
||||
catch (ComparisonFailure e) {
|
||||
|
||||
@@ -23,12 +23,14 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.ShutDownTracker;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -380,12 +382,15 @@ public class JetTestUtils {
|
||||
FileUtil.writeToFile(expectedFile, actual);
|
||||
Assert.fail("Expected data file did not exist. Generating: " + expectedFile);
|
||||
}
|
||||
String expected = FileUtil.loadFile(expectedFile, true);
|
||||
String expected = FileUtil.loadFile(expectedFile, CharsetToolkit.UTF8, true);
|
||||
|
||||
// compare with hard copy: make sure nothing is lost in output
|
||||
Assert.assertEquals("Expected and actual namespaces differ from " + expectedFile.getName(),
|
||||
StringUtil.convertLineSeparators(expected),
|
||||
StringUtil.convertLineSeparators(actual));
|
||||
String expectedText = StringUtil.convertLineSeparators(expected);
|
||||
String actualText = StringUtil.convertLineSeparators(actual);
|
||||
if (!Comparing.equal(expectedText, actualText)) {
|
||||
throw new FileComparisonFailure("Expected and actual namespaces differ from " + expectedFile.getName(),
|
||||
expected, actual, expectedFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.cfg;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -147,9 +146,8 @@ public class JetControlFlowTest extends JetLiteFixture {
|
||||
FileUtil.writeToFile(expectedInstructionsFile, instructionDump.toString());
|
||||
fail("No expected instructions for " + name + " generated result is written into " + expectedInstructionsFileName);
|
||||
}
|
||||
String expectedInstructions = StringUtil.convertLineSeparators(FileUtil.loadFile(expectedInstructionsFile));
|
||||
|
||||
assertEquals(expectedInstructions, instructionDump.toString());
|
||||
JetTestUtils.assertEqualsToFile(expectedInstructionsFile, instructionDump.toString());
|
||||
|
||||
// StringBuilder graphDump = new StringBuilder();
|
||||
// for (Pseudocode pseudocode : pseudocodes) {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public abstract class AbstractDiagnosticsTestWithEagerResolve extends AbstractJe
|
||||
ok &= testFile.getActualText(bindingContext, actualText);
|
||||
}
|
||||
|
||||
assertEquals(expectedText, actualText.toString());
|
||||
assertSameLinesWithFile(testDataFile.getAbsolutePath(), actualText.toString());
|
||||
|
||||
assertTrue("Diagnostics mismatch. See the output above", ok);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.modules.xml;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
@@ -56,6 +57,6 @@ public abstract class AbstractModuleXmlParserTest extends TestCase {
|
||||
fail("Expected data file does not exist. A new file created: " + txtFile);
|
||||
}
|
||||
|
||||
assertEquals(FileUtil.loadFile(txtFile, true), actual);
|
||||
JetTestUtils.assertEqualsToFile(txtFile, actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user