summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Nancekivell <stephennancekivell@gmail.com>2018-01-20 14:56:35 +1100
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-19 19:56:35 -0800
commit7f2dafaaa89d204c7bbe986f38fa5817ee7a091b (patch)
tree93b830806ebd27d4ca721f949b6120ca79776415
parent225ace260f614deb74c8770608c4c9109d336bba (diff)
downloadmill-7f2dafaaa89d204c7bbe986f38fa5817ee7a091b.tar.gz
mill-7f2dafaaa89d204c7bbe986f38fa5817ee7a091b.tar.bz2
mill-7f2dafaaa89d204c7bbe986f38fa5817ee7a091b.zip
add a basic test for gen-idea (#114)
* add a basic test for gen-idea * update GenIdeaTest with resources as source. * change .gitignore to allow .iml under src/test/resources. Ignore .idea_modules. * normalise library paths in GenIdeaTests
-rw-r--r--.gitignore4
-rw-r--r--scalalib/src/main/scala/mill/scalalib/GenIdea.scala10
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml7
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/misc.xml5
-rw-r--r--scalalib/src/test/resources/gen-idea/idea/modules.xml8
-rw-r--r--scalalib/src/test/resources/gen-idea/idea_modules/iml22
-rw-r--r--scalalib/src/test/resources/gen-idea/idea_modules/root.iml9
-rw-r--r--scalalib/src/test/scala/mill/scalalib/GenIdeaTests.scala78
15 files changed, 185 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 4b82f58d..a3d08f4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,6 @@
target/
output/
.DS_STORE
-*.iml
+.idea_modules
.idea
-out/ \ No newline at end of file
+out/
diff --git a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
index 73699a9e..4496c8c6 100644
--- a/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
+++ b/scalalib/src/main/scala/mill/scalalib/GenIdea.scala
@@ -165,21 +165,21 @@ object GenIdea {
<output url={"file://$MODULE_DIR$/" + relify(outputPath) + "/dest/classes"} />
<exclude-output />
{
- for (normalSourcePath <- normalSourcePaths.toSeq)
+ for (normalSourcePath <- normalSourcePaths.toSeq.sorted)
yield
<content url={"file://$MODULE_DIR$/" + relify(normalSourcePath)}>
<sourceFolder url={"file://$MODULE_DIR$/" + relify(normalSourcePath)} isTestSource="false" />
</content>
}
{
- for (generatedSourcePath <- generatedSourcePaths.toSeq)
+ for (generatedSourcePath <- generatedSourcePaths.toSeq.sorted)
yield
<content url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)}>
<sourceFolder url={"file://$MODULE_DIR$/" + relify(generatedSourcePath)} isTestSource="false" generated="true" />
</content>
}
{
- for (resourcePath <- resourcePaths.toSeq)
+ for (resourcePath <- resourcePaths.toSeq.sorted)
yield
<content url={"file://$MODULE_DIR$/" + relify(resourcePath)}>
<sourceFolder url={"file://$MODULE_DIR$/" + relify(resourcePath)} isTestSource="false" type="java-resource" />
@@ -189,12 +189,12 @@ object GenIdea {
<orderEntry type="sourceFolder" forTests="false" />
{
- for(name <- libNames.toSeq)
+ for(name <- libNames.toSeq.sorted)
yield <orderEntry type="library" name={name} level="project" />
}
{
- for(depName <- depNames.toSeq)
+ for(depName <- depNames.toSeq.sorted)
yield <orderEntry type="module" module-name={depName} exported="" />
}
</component>
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml
new file mode 100644
index 00000000..a6398d46
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6-sources.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml
new file mode 100644
index 00000000..5e21f3f3
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml
new file mode 100644
index 00000000..fe9d533a
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.4/scala-compiler-2.12.4-sources.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml
new file mode 100644
index 00000000..ec0460d7
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-compiler_2.12.4_scala-compiler-2.12.4.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.4/scala-compiler-2.12.4.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml
new file mode 100644
index 00000000..a1278e29
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-library_2.12.4_scala-library-2.12.4-sources.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4-sources.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4.jar.xml
new file mode 100644
index 00000000..bbd957f0
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-library_2.12.4_scala-library-2.12.4.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml
new file mode 100644
index 00000000..09db75bb
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.4/scala-reflect-2.12.4-sources.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml
new file mode 100644
index 00000000..f23b80f6
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml
@@ -0,0 +1,7 @@
+<component name="libraryTable">
+ <library name="scala-reflect_2.12.4_scala-reflect-2.12.4.jar">
+ <CLASSES>
+ <root url="jar:COURSIER_HOME/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.4/scala-reflect-2.12.4.jar!/"/>
+ </CLASSES>
+ </library>
+</component> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/misc.xml b/scalalib/src/test/resources/gen-idea/idea/misc.xml
new file mode 100644
index 00000000..2726692f
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/misc.xml
@@ -0,0 +1,5 @@
+<project version="4">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/target/idea_output"/>
+ </component>
+</project> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea/modules.xml b/scalalib/src/test/resources/gen-idea/idea/modules.xml
new file mode 100644
index 00000000..374b9a1f
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea/modules.xml
@@ -0,0 +1,8 @@
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea_modules/root.iml" filepath="$PROJECT_DIR$/.idea_modules/root.iml"/>
+ <module fileurl="file://$PROJECT_DIR$/.idea_modules/.iml" filepath="$PROJECT_DIR$/.idea_modules/.iml"/>
+ </modules>
+ </component>
+</project> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea_modules/iml b/scalalib/src/test/resources/gen-idea/idea_modules/iml
new file mode 100644
index 00000000..548865f1
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea_modules/iml
@@ -0,0 +1,22 @@
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/../target/workspace/gen-idea/out/compile/dest/classes"/>
+ <exclude-output/>
+ <content url="file://$MODULE_DIR$/../target/workspace/hello-world/src/src">
+ <sourceFolder url="file://$MODULE_DIR$/../target/workspace/hello-world/src/src" isTestSource="false"/>
+ </content>
+ <content url="file://$MODULE_DIR$/../target/workspace/hello-world/src/resources">
+ <sourceFolder url="file://$MODULE_DIR$/../target/workspace/hello-world/src/resources" isTestSource="false" type="java-resource"/>
+ </content>
+ <orderEntry type="inheritedJdk"/>
+ <orderEntry type="sourceFolder" forTests="false"/>
+ <orderEntry type="library" name="modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar" level="project"/>
+ <orderEntry type="library" name="modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar" level="project"/>
+ <orderEntry type="library" name="scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar" level="project"/>
+ <orderEntry type="library" name="scala-compiler_2.12.4_scala-compiler-2.12.4.jar" level="project"/>
+ <orderEntry type="library" name="scala-library_2.12.4_scala-library-2.12.4-sources.jar" level="project"/>
+ <orderEntry type="library" name="scala-library_2.12.4_scala-library-2.12.4.jar" level="project"/>
+ <orderEntry type="library" name="scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar" level="project"/>
+ <orderEntry type="library" name="scala-reflect_2.12.4_scala-reflect-2.12.4.jar" level="project"/>
+ </component>
+</module> \ No newline at end of file
diff --git a/scalalib/src/test/resources/gen-idea/idea_modules/root.iml b/scalalib/src/test/resources/gen-idea/idea_modules/root.iml
new file mode 100644
index 00000000..dcf5f7fc
--- /dev/null
+++ b/scalalib/src/test/resources/gen-idea/idea_modules/root.iml
@@ -0,0 +1,9 @@
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/../out"/>
+ <content url="file://$MODULE_DIR$/.."/>
+ <exclude-output/>
+ <orderEntry type="inheritedJdk"/>
+ <orderEntry type="sourceFolder" forTests="false"/>
+ </component>
+</module> \ No newline at end of file
diff --git a/scalalib/src/test/scala/mill/scalalib/GenIdeaTests.scala b/scalalib/src/test/scala/mill/scalalib/GenIdeaTests.scala
new file mode 100644
index 00000000..36945f65
--- /dev/null
+++ b/scalalib/src/test/scala/mill/scalalib/GenIdeaTests.scala
@@ -0,0 +1,78 @@
+package mill.scalalib
+
+import ammonite.ops._
+import mill._
+
+import mill.util.{TestEvaluator, TestUtil}
+import utest._
+
+object GenIdeaTests extends TestSuite {
+
+ val basePath = pwd / 'target / 'workspace / "gen-idea"
+ val outPath = basePath / 'out
+ val workingSrcPath = basePath / 'src
+
+ trait HelloWorldModule extends scalalib.ScalaModule {
+ def scalaVersion = "2.12.4"
+ def basePath = HelloWorldTests.workingSrcPath
+ }
+
+ object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
+
+ val helloWorldEvaluator = new TestEvaluator(
+ HelloWorld,
+ outPath,
+ workingSrcPath
+ )
+
+ def tests: Tests = Tests {
+ 'genIdeaTests - {
+ helloWorldEvaluator(HelloWorld.scalaVersion)
+ val x = GenIdea.xmlFileLayout(helloWorldEvaluator.evaluator, HelloWorld)
+ val pp = new scala.xml.PrettyPrinter(999, 4)
+
+ for((relPath, xml) <- GenIdea.xmlFileLayout(helloWorldEvaluator.evaluator, HelloWorld)){
+ write.over(basePath/ "generated"/ relPath, pp.format(xml))
+ }
+
+ Seq(
+ "gen-idea/idea_modules/iml" ->
+ basePath / "generated" / ".idea_modules" /".iml",
+ "gen-idea/idea_modules/root.iml" ->
+ basePath / "generated" / ".idea_modules" /"root.iml",
+ "gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-reflect_2.12.4_scala-reflect-2.12.4-sources.jar.xml",
+ "gen-idea/idea/libraries/scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-reflect_2.12.4_scala-reflect-2.12.4.jar.xml",
+ "gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-library_2.12.4_scala-library-2.12.4.jar.xml",
+ "gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6.jar.xml",
+ "gen-idea/idea/libraries/modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "modules_scala-xml_2.12_1.0.6_scala-xml_2.12-1.0.6-sources.jar.xml",
+ "gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-compiler_2.12.4_scala-compiler-2.12.4-sources.jar.xml",
+ "gen-idea/idea/libraries/scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-library_2.12.4_scala-library-2.12.4-sources.jar.xml",
+ "gen-idea/idea/libraries/scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml" ->
+ basePath / "generated" / ".idea" / "libraries" / "scala-compiler_2.12.4_scala-compiler-2.12.4.jar.xml",
+ "gen-idea/idea/modules.xml" ->
+ basePath / "generated" / ".idea" / "modules.xml",
+ "gen-idea/idea/misc.xml" ->
+ basePath / "generated" / ".idea" / "misc.xml",
+ ).foreach { case (resource, generated) =>
+ println("checking "+resource)
+ val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n")
+ val generatedString = normaliseLibraryPaths(read! generated)
+
+ assert(resourceString == generatedString)
+ }
+ }
+ }
+
+
+ private val libPathRegex = """([\w/]+)/.coursier""".r
+ private def normaliseLibraryPaths(in: String): String = {
+ libPathRegex.replaceAllIn(in, "COURSIER_HOME")
+ }
+}