Fix test. Add not only JS libraries but also libraries that could be JS headers.

This commit is contained in:
Nikolay Krasko
2013-03-07 19:12:39 +04:00
parent 86886b79c3
commit 8fc5676c95
2 changed files with 44 additions and 14 deletions
@@ -36,13 +36,11 @@ public abstract class IDECompilerMessagingTest extends PlatformTestCase {
protected void performTest(@NotNull Function1<MessageChecker, Void> whatToExpect, protected void performTest(@NotNull Function1<MessageChecker, Void> whatToExpect,
@NotNull TranslatingCompiler compiler, @NotNull String testDataPath) { @NotNull TranslatingCompiler compiler, @NotNull String testDataPath) {
String pathToTestDir = testDataPath + "/" + getTestName(true); String pathToTestDir = testDataPath + "/" + getTestName(true);
VirtualFile testDir = LocalFileSystem.getInstance().findFileByPath(pathToTestDir);
Assert.assertNotNull(testDir); VirtualFile testDir = getFile(testDataPath, "");
VirtualFile sampleFile = LocalFileSystem.getInstance().findFileByPath(pathToTestDir + "/src/test.kt"); VirtualFile sampleFile = getFile(testDataPath, "/src/test.kt");
VirtualFile outDirectory = getOutDirectory(pathToTestDir, testDir); VirtualFile outDirectory = getOutDirectory(pathToTestDir, testDir);
String pathToSrc = pathToTestDir + "/src/"; VirtualFile root = getFile(testDataPath, "/src");
VirtualFile root = LocalFileSystem.getInstance().findFileByPath(pathToSrc);
Assert.assertNotNull(root);
MockCompileContext mockCompileContext = new MockCompileContext(myModule, outDirectory, root); MockCompileContext mockCompileContext = new MockCompileContext(myModule, outDirectory, root);
MockModuleChunk mockModuleChunk = new MockModuleChunk(myModule); MockModuleChunk mockModuleChunk = new MockModuleChunk(myModule);
setSourceEntryForModule(root); setSourceEntryForModule(root);
@@ -51,6 +49,14 @@ public abstract class IDECompilerMessagingTest extends PlatformTestCase {
checkMessages(whatToExpect, mockCompileContext); checkMessages(whatToExpect, mockCompileContext);
} }
protected VirtualFile getFile(@NotNull String testDataPath, @NotNull String relativePath) {
String pathToFile = testDataPath + "/" + getTestName(true) + relativePath;
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(pathToFile);
Assert.assertNotNull("Can't find path " + pathToFile, file);
return file;
}
private void checkMessages(@NotNull Function1<MessageChecker, Void> whatToExpect, @NotNull MockCompileContext mockCompileContext) { private void checkMessages(@NotNull Function1<MessageChecker, Void> whatToExpect, @NotNull MockCompileContext mockCompileContext) {
MessageChecker checker = new MessageChecker(mockCompileContext); MessageChecker checker = new MessageChecker(mockCompileContext);
checkHeader(checker); checkHeader(checker);
@@ -16,10 +16,17 @@
package org.jetbrains.jet.plugin.compilerMessages; package org.jetbrains.jet.plugin.compilerMessages;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.util.PathUtil;
import jet.Function1; import jet.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.PluginTestCaseBase; import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.plugin.compiler.K2JSCompiler; import org.jetbrains.jet.plugin.compiler.K2JSCompiler;
import org.jetbrains.jet.testing.ConfigLibraryUtil;
import java.io.File;
import static org.jetbrains.jet.plugin.compilerMessages.Message.*; import static org.jetbrains.jet.plugin.compilerMessages.Message.*;
@@ -60,14 +67,31 @@ public final class K2JSCompilerMessagingTest extends IDECompilerMessagingTest {
} }
public void testLib() { public void testLib() {
throw new UnsupportedOperationException("Under construction"); NewLibraryEditor editor = new NewLibraryEditor(null, null);
//doTest(new Function1<MessageChecker, Void>() { editor.setName("testLib");
// @Override
// public Void invoke(MessageChecker checker) { String path = PathUtil.getLocalPath(getFile(TEST_DATA_PATH, "/src/lib.zip"));
// //nothing apart from header assert path != null : "Can't get local path";
// return null;
// } String libUrl = VfsUtil.getUrlForLibraryRoot(new File(path));
//});
editor.addRoot(libUrl, OrderRootType.CLASSES);
editor.addRoot(libUrl, OrderRootType.SOURCES);
try {
ConfigLibraryUtil.addLibrary(editor, myModule);
doTest(new Function1<MessageChecker, Void>() {
@Override
public Void invoke(MessageChecker checker) {
//nothing apart from header
return null;
}
});
}
finally {
ConfigLibraryUtil.removeLibrary(myModule, "testLib");
}
} }
private void doTest(@NotNull Function1<MessageChecker, Void> whatToExpect) { private void doTest(@NotNull Function1<MessageChecker, Void> whatToExpect) {