summaryrefslogtreecommitdiff
path: root/scalalib/test/src/GenIdeaTests.scala
blob: 60c9f9a85004a1dbac3c7af113090eeaf2db063b (plain) (blame)
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
package mill.scalalib

import mill._
import mill.util.{TestEvaluator, TestUtil}
import utest._

object GenIdeaTests extends TestSuite {

  val millSourcePath = os.pwd / 'target / 'workspace / "gen-idea"

  trait HelloWorldModule extends scalalib.ScalaModule {
    def scalaVersion = "2.12.4"
    def millSourcePath = GenIdeaTests.millSourcePath
    object test extends super.Tests {
      def testFrameworks = Seq("utest.runner.Framework")
    }
  }

  object HelloWorld extends TestUtil.BaseModule with HelloWorldModule

  val helloWorldEvaluator = TestEvaluator.static(HelloWorld)

  def tests: Tests = Tests {
    'genIdeaTests - {
      val pp = new scala.xml.PrettyPrinter(999, 4)

      val layout = GenIdeaImpl.xmlFileLayout(
        helloWorldEvaluator.evaluator,
        HelloWorld,
        ("JDK_1_8", "1.8 (1)"), None, fetchMillModules = false)
      for((relPath, xml) <- layout){
        os.write.over(millSourcePath/ "generated"/ relPath, pp.format(xml), createFolders = true)
      }

      Seq(
        "gen-idea/idea_modules/iml" ->
          millSourcePath / "generated" / ".idea_modules" /".iml",
        "gen-idea/idea_modules/test.iml" ->
          millSourcePath / "generated" / ".idea_modules" /"test.iml",
        "gen-idea/idea_modules/mill-build.iml" ->
          millSourcePath / "generated" / ".idea_modules" /"mill-build.iml",
        "gen-idea/idea/libraries/scala-library-2.12.4.jar.xml" ->
          millSourcePath / "generated" / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml",
        "gen-idea/idea/modules.xml" ->
          millSourcePath / "generated" / ".idea" / "modules.xml",
        "gen-idea/idea/misc.xml" ->
          millSourcePath / "generated" / ".idea" / "misc.xml"
      ).foreach { case (resource, generated) =>
          val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n")
          val generatedString = normaliseLibraryPaths(os.read(generated))

          assert(resourceString == generatedString)
        }
    }
  }


  private def normaliseLibraryPaths(in: String): String = {
    in.replaceAll(coursier.paths.CoursierPaths.cacheDirectory().toString, "COURSIER_HOME")
  }
}