Permalink
Browse files

Fix tests in 171 branch

  • Loading branch information...
1 parent 889de6d commit 17a4ac2eaa60c869296d1323e9ae639a1ec49c6c @zolotov zolotov committed Oct 20, 2016
Showing with 50 additions and 10 deletions.
  1. +50 −10 tests/com/goide/sdk/GoPathLibraryTest.java
@@ -20,11 +20,9 @@
import com.goide.GoModuleType;
import com.goide.project.GoApplicationLibrariesService;
import com.goide.project.GoModuleLibrariesInitializer;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.ModuleType;
-import com.intellij.openapi.roots.LibraryOrderEntry;
-import com.intellij.openapi.roots.ModifiableRootModel;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.OrderRootType;
+import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.OrderEntryUtil;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.util.io.FileUtil;
@@ -54,21 +52,56 @@ public ModuleType getModuleType() {
}
};
}
+ private final Collection<VirtualFile> contentRootsToClean = ContainerUtil.newHashSet();
+ private final Collection<VirtualFile> tempRootsToClean = ContainerUtil.newHashSet();
@Override
protected void setUp() throws Exception {
super.setUp();
GoModuleLibrariesInitializer.setTestingMode(getTestRootDisposable());
}
+ @Override
+ protected void tearDown() throws Exception {
+ try {
+ for (VirtualFile file : tempRootsToClean) {
+ ApplicationManager.getApplication().runWriteAction(() -> {
+ try {
+ file.delete(this);
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+ }
+ finally {
+ tempRootsToClean.clear();
+ }
+ ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
+ try {
+ for (ContentEntry entry : model.getContentEntries()) {
+ if (contentRootsToClean.contains(entry.getFile())) {
+ model.removeContentEntry(entry);
+ }
+ }
+ ApplicationManager.getApplication().runWriteAction(model::commit);
+ }
+ finally {
+ contentRootsToClean.clear();
+ if (!model.isDisposed()) model.dispose();
+ }
+ super.tearDown();
+ }
+
/**
* src <content root>
* goPath <gopath>
* - src
* -- test
*/
public void testAddGoPathAsLibrary() throws IOException {
- VirtualFile goPath = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "path"), true);
+ VirtualFile goPath = createGoPath();
VirtualFile goPathContent = goPath.createChildDirectory(this, "src").createChildDirectory(this, "test");
GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl());
assertLibrary(Collections.singletonList(goPathContent.getUrl()), "temp:///src");
@@ -82,7 +115,7 @@ public void testAddGoPathAsLibrary() throws IOException {
* -- notContentRoot
*/
public void testExcludeChildContentRootFromLibrary() throws IOException {
- VirtualFile goPath = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "path"), true);
+ VirtualFile goPath = createGoPath();
VirtualFile src = goPath.createChildDirectory(this, "src");
VirtualFile contentRoot = src.createChildDirectory(this, "contentRoot");
VirtualFile notContentRoot = src.createChildDirectory(this, "notContentRoot");
@@ -102,11 +135,11 @@ public void testExcludeChildContentRootFromLibrary() throws IOException {
* --- test
*/
public void testExcludeParentContentRootFromLibrary() throws IOException {
- VirtualFile contentRoot = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "contentRoot"), true);
+ VirtualFile contentRoot = createGoPath();
VirtualFile goPath = contentRoot.createChildDirectory(this, "gopath");
VirtualFile goPathContent = goPath.createChildDirectory(this, "src").createChildDirectory(this, "test");
- VirtualFile otherGoPath = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "otherGoPath"), true);
+ VirtualFile otherGoPath = createGoPath();
VirtualFile otherGoPathContent = otherGoPath.createChildDirectory(this, "src").createChildDirectory(this, "test");
GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl(), otherGoPath.getUrl());
assertLibrary(ContainerUtil.newHashSet(goPathContent.getUrl(), otherGoPathContent.getUrl()), "temp:///src");
@@ -123,7 +156,7 @@ public void testExcludeParentContentRootFromLibrary() throws IOException {
* --- contentRoot <content root>
*/
public void testUpdateLibraryOnAddingContentRoot() throws IOException {
- VirtualFile goPath = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "path"), true);
+ VirtualFile goPath = createGoPath();
VirtualFile goPathContent = goPath.createChildDirectory(this, "src").createChildDirectory(this, "subdir");
GoApplicationLibrariesService.getInstance().setLibraryRootUrls(goPath.getUrl());
@@ -136,8 +169,9 @@ public void testUpdateLibraryOnAddingContentRoot() throws IOException {
private void addContentRoot(@NotNull VirtualFile contentRoot) {
ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
- try {
+ try {
model.addContentEntry(contentRoot);
+ contentRootsToClean.add(contentRoot);
model.commit();
}
finally {
@@ -161,6 +195,12 @@ private void assertLibrary(@NotNull Collection<String> libUrls, String... exclus
assertSameElements(library.getExcludedRootUrls(), exclusionUrls);
}
+ private VirtualFile createGoPath() throws IOException {
+ VirtualFile goPath = VfsUtil.findFileByIoFile(FileUtil.createTempDirectory("go", "path"), true);
+ tempRootsToClean.add(goPath);
+ return goPath;
+ }
+
@Override
protected boolean isWriteActionRequired() {
return true;

0 comments on commit 17a4ac2

Please sign in to comment.