-
Notifications
You must be signed in to change notification settings - Fork 39
/
StackImportWizardTest.scala
84 lines (69 loc) · 3.01 KB
/
StackImportWizardTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.haskforce.importWizard.stack
import java.io.File
import java.util
import scala.collection.JavaConversions._
import com.intellij.ide.actions.ImportModuleAction
import com.intellij.ide.projectWizard.ProjectWizardTestCase
import com.intellij.ide.util.newProjectWizard.AddModuleWizard
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.projectImport.ProjectImportProvider
import com.intellij.testFramework.UsefulTestCase
import com.intellij.util.containers.ContainerUtil
import junit.framework.TestCase
import com.haskforce.HaskellModuleType
/**
* Tests for importing stack projects and modules.
*/
class StackImportWizardTest extends ProjectWizardTestCase[AddModuleWizard] {
import TestCase._
import UsefulTestCase._
val testDir = "tests/gold/importWizard/stack"
def testImportProjectDirectory(): Unit = {
val projectDir = s"$testDir/stack-ide"
val project = importProjectFrom(projectDir, null, newImportProvider()).getProject
val paths = HaskellModuleType.findModules(project).map(_.getModuleFilePath)
val expected = util.Arrays.asList(
"ide-backend/ide-backend-common/ide-backend-common.iml",
"ide-backend/ide-backend/ide-backend.iml",
"ide-backend/ide-backend-server/ide-backend-server.iml",
"stack-ide-api/stack-ide-api.iml",
"stack-ide/stack-ide.iml",
"stack-ide (root).iml"
).map(path => new File(s"$projectDir/$path").getCanonicalPath)
assertSameElements("Could not find module file(s)", paths, expected)
}
def testImportProjectDirectoryProblematic(): Unit = {
val projectDir = s"$testDir/stack-ide"
val modules = importProject(projectDir)
val paths = modules.map(_.getModuleFilePath)
val expected = util.Arrays.asList(
"ide-backend/ide-backend-common/ide-backend-common.iml",
"ide-backend/ide-backend/ide-backend.iml",
"ide-backend/ide-backend-server/ide-backend-server.iml",
"stack-ide-api/stack-ide-api.iml",
"stack-ide/stack-ide.iml",
"stack-ide (root).iml"
).map(path => new File(s"$projectDir/$path").getCanonicalPath)
assertSameElements("Could not find module file(s)", paths, expected)
}
private def importProject(path: String) = importFrom(path, None, newImportProvider())
private def importFrom(
path: String,
mbProject: Option[Project],
providers: ProjectImportProvider*): util.List[Module] = {
val file = LocalFileSystem.getInstance.refreshAndFindFileByPath(path)
assertNotNull(s"Can't find $path", file)
val project = mbProject.orNull
assertTrue(providers.head.canImport(file, project))
myWizard = ImportModuleAction.createImportWizard(project, null, file, providers: _*)
.asInstanceOf[AddModuleWizard]
assertNotNull(myWizard)
if (myWizard.getStepCount > 0) runWizard(null)
ImportModuleAction.createFromWizard(project, myWizard)
}
private def newImportProvider() = {
new StackProjectImportProvider(new StackProjectImportBuilder)
}
}