assertEqualsToFile() extracted as a common utility
This commit is contained in:
@@ -375,6 +375,24 @@ public class JetTestUtils {
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual) {
|
||||||
|
try {
|
||||||
|
if (!expectedFile.exists()) {
|
||||||
|
FileUtil.writeToFile(expectedFile, actual);
|
||||||
|
Assert.fail("Expected data file did not exist. Generating: " + expectedFile);
|
||||||
|
}
|
||||||
|
String expected = FileUtil.loadFile(expectedFile, 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));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface TestFileFactory<F> {
|
public interface TestFileFactory<F> {
|
||||||
F create(String fileName, String text, Map<String, String> directives);
|
F create(String fileName, String text, Map<String, String> directives);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,10 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.jvm.compiler.ExpectedLoadErrorsUtil;
|
import org.jetbrains.jet.jvm.compiler.ExpectedLoadErrorsUtil;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
@@ -38,7 +37,6 @@ import org.jetbrains.jet.utils.Printer;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -224,21 +222,7 @@ public class NamespaceComparator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (txtFile != null) {
|
if (txtFile != null) {
|
||||||
try {
|
JetTestUtils.assertEqualsToFile(txtFile, actualSerialized);
|
||||||
if (!txtFile.exists()) {
|
|
||||||
FileUtil.writeToFile(txtFile, actualSerialized);
|
|
||||||
Assert.fail("Expected data file did not exist. Generating: " + txtFile);
|
|
||||||
}
|
|
||||||
String expected = FileUtil.loadFile(txtFile, true);
|
|
||||||
|
|
||||||
// compare with hard copy: make sure nothing is lost in output
|
|
||||||
Assert.assertEquals("Expected and actual namespaces differ from " + txtFile.getName(),
|
|
||||||
StringUtil.convertLineSeparators(expected),
|
|
||||||
StringUtil.convertLineSeparators(actualSerialized));
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user