summaryrefslogtreecommitdiff
path: root/integration
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-11 14:13:16 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-11 14:13:16 -0800
commit04552a462b67a6f17dfa13035334561eac4787ad (patch)
treedf3151a8b448c81e524013f899ed28d8a2603dba /integration
parent82459ab66f7a1b97653991513521817c9fe9c308 (diff)
downloadmill-04552a462b67a6f17dfa13035334561eac4787ad.tar.gz
mill-04552a462b67a6f17dfa13035334561eac4787ad.tar.bz2
mill-04552a462b67a6f17dfa13035334561eac4787ad.zip
add uPickle to our integration test suite
Diffstat (limited to 'integration')
-rw-r--r--integration/test/resources/upickle/build.sc148
-rw-r--r--integration/test/src/mill/integration/UpickleTests.scala23
2 files changed, 171 insertions, 0 deletions
diff --git a/integration/test/resources/upickle/build.sc b/integration/test/resources/upickle/build.sc
new file mode 100644
index 00000000..39742562
--- /dev/null
+++ b/integration/test/resources/upickle/build.sc
@@ -0,0 +1,148 @@
+import mill._, mill.scalalib._, mill.scalalib.publish._, mill.scalajslib._
+
+
+trait UpickleModule extends CrossSbtModule with PublishModule{
+
+ def millSourcePath = build.millSourcePath / "upickle"
+
+ def artifactName = "mill-" + super.artifactName()
+ def publishVersion = "0.5.1"
+
+ def pomSettings = PomSettings(
+ description = artifactName(),
+ organization = "com.lihaoyi",
+ url = "https://github.com/lihaoyi/upickle",
+ licenses = Seq(
+ License("MIT license", "http://www.opensource.org/licenses/mit-license.php")
+ ),
+ scm = SCM(
+ "git://github.com/lihaoyi/upickle.git",
+ "scm:git://github.com/lihaoyi/upickle.git"
+ ),
+ developers = Seq(
+ Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
+ )
+ )
+ def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg(
+ ivy"com.lihaoyi::acyclic:0.1.5"
+ )
+ def compileIvyDeps = Agg(
+ ivy"com.lihaoyi::acyclic:0.1.5",
+ ivy"org.scala-lang:scala-reflect:${scalaVersion()}",
+ ivy"org.scala-lang:scala-compiler:${scalaVersion()}"
+ )
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::sourcecode::0.1.3"
+ )
+ def scalacOptions = Seq("-unchecked",
+ "-deprecation",
+ "-encoding", "utf8",
+ "-feature"
+ )
+
+ def sources = T.sources(
+ millSourcePath / platformSegment / "src" / "main",
+ millSourcePath / "shared" / "src" / "main"
+ )
+
+ def generatedSources = T{
+ val dir = T.ctx().dest
+ val file = dir / "upickle" / "Generated.scala"
+ ammonite.ops.mkdir(dir / "upickle")
+ val tuplesAndCases = (1 to 22).map{ i =>
+ def commaSeparated(s: Int => String) = (1 to i).map(s).mkString(", ")
+ val writerTypes = commaSeparated(j => s"T$j: Writer")
+ val readerTypes = commaSeparated(j => s"T$j: Reader")
+ val typeTuple = commaSeparated(j => s"T$j")
+ val written = commaSeparated(j => s"writeJs(x._$j)")
+ val pattern = commaSeparated(j => s"x$j")
+ val read = commaSeparated(j => s"readJs[T$j](x$j)")
+ val caseReader =
+ if(i == 1) s"f(readJs[Tuple1[T1]](x)._1)"
+ else s"f.tupled(readJs[Tuple$i[$typeTuple]](x))"
+ (s"""
+ implicit def Tuple${i}W[$writerTypes] = makeWriter[Tuple${i}[$typeTuple]](
+ x => Js.Arr($written)
+ )
+ implicit def Tuple${i}R[$readerTypes] = makeReader[Tuple${i}[$typeTuple]](
+ validate("Array(${i})"){case Js.Arr($pattern) => Tuple${i}($read)}
+ )
+ """, s"""
+ def Case${i}R[$readerTypes, V]
+ (f: ($typeTuple) => V, names: Array[String], defaults: Array[Js.Value])
+ = RCase[V](names, defaults, {case x => $caseReader})
+ def Case${i}W[$writerTypes, V]
+ (g: V => Option[Tuple${i}[$typeTuple]], names: Array[String], defaults: Array[Js.Value])
+ = WCase[V](names, defaults, x => writeJs(g(x).get))
+ """)
+ }
+ val (tuples, cases) = tuplesAndCases.unzip
+ ammonite.ops.write(file, s"""
+ package upickle
+ import acyclic.file
+ import language.experimental.macros
+ /**
+ * Auto-generated picklers and unpicklers, used for creating the 22
+ * versions of tuple-picklers and case-class picklers
+ */
+ trait Generated extends GeneratedUtil{
+ ${tuples.mkString("\n")}
+ }
+ """)
+ Seq(PathRef(dir))
+ }
+
+ def platformSegment: String
+}
+
+trait UpickleTestModule extends TestModule{
+ def platformSegment: String
+
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::utest::0.5.4",
+ ivy"com.lihaoyi::acyclic:0.1.5"
+ )
+
+ def sources = T.sources(
+ millSourcePath / platformSegment / "src" / "test",
+ millSourcePath / "shared" / "src" / "test"
+ )
+ def testFramework = "utest.runner.Framework"
+}
+
+object upickleJvm extends Cross[UpickleJvmModule]("2.11.11", "2.12.4")
+class UpickleJvmModule(val crossScalaVersion: String) extends UpickleModule{
+ def platformSegment = "jvm"
+
+ def ivyDeps = T{
+ super.ivyDeps() ++ Seq(ivy"org.spire-math::jawn-parser:0.11.0")
+ }
+ object test extends Tests with UpickleTestModule{
+ def platformSegment = "js"
+ def millSourcePath = build.millSourcePath / "upickle"
+ }
+}
+
+object upickleJs extends Cross[UpickleJsModule]("2.11.11", "2.12.4")
+class UpickleJsModule(val crossScalaVersion: String) extends UpickleModule with ScalaJSModule {
+ def platformSegment = "js"
+
+ def scalaJSVersion = "0.6.22"
+ def scalacOptions = T{
+ super.scalacOptions() ++ Seq({
+ val a = build.millSourcePath.toString.replaceFirst("[^/]+/?$", "")
+ val g = "https://raw.githubusercontent.com/lihaoyi/upickle"
+ s"-P:scalajs:mapSourceURI:$a->$g/v${publishVersion()}/"
+ })
+ }
+ object test extends Tests with UpickleTestModule{
+ def platformSegment = "js"
+ def millSourcePath = build.millSourcePath / "upickle"
+ }
+}
+
+object test extends ScalaModule{
+ def scalaVersion = "2.12.4"
+ def moduleDeps = Seq(upickleJvm("2.12.4"))
+ def sources = T.sources{millSourcePath}
+}
diff --git a/integration/test/src/mill/integration/UpickleTests.scala b/integration/test/src/mill/integration/UpickleTests.scala
new file mode 100644
index 00000000..7c6778ad
--- /dev/null
+++ b/integration/test/src/mill/integration/UpickleTests.scala
@@ -0,0 +1,23 @@
+package mill.integration
+
+import ammonite.ops._
+import utest._
+
+object UpickleTests extends IntegrationTestSuite("MILL_UPICKLE_REPO", "upickle") {
+ val tests = Tests{
+ initWorkspace()
+ 'test - {
+ assert(eval("upickleJvm[2.11.11].test"))
+ assert(eval("upickleJs[2.12.4].test"))
+
+ val jvmMeta = meta("upickleJvm[2.11.11].test.test")
+ assert(jvmMeta.contains("example.ExampleTests.simple"))
+ assert(jvmMeta.contains("upickle.MacroTests.commonCustomStructures.simpleAdt"))
+
+ val jsMeta = meta("upickleJs[2.12.4].test.test")
+ assert(jsMeta .contains("example.ExampleTests.simple"))
+ assert(jsMeta .contains("upickle.MacroTests.commonCustomStructures.simpleAdt"))
+ }
+
+ }
+}