summaryrefslogtreecommitdiff
path: root/contrib/buildinfo/test/src
diff options
context:
space:
mode:
authorbenjaminfrank <ben+github@pipsfrank.de>2018-08-16 21:28:43 +0200
committerGitHub <noreply@github.com>2018-08-16 21:28:43 +0200
commitd4de5f9646cb2005e79dd8f64ac20c66fa2baeda (patch)
tree2a7cddd22a0e868b577e19e21f59d46eef190578 /contrib/buildinfo/test/src
parentb9b133610f14cc7207e1a3efad43a06a1521b92a (diff)
downloadmill-d4de5f9646cb2005e79dd8f64ac20c66fa2baeda.tar.gz
mill-d4de5f9646cb2005e79dd8f64ac20c66fa2baeda.tar.bz2
mill-d4de5f9646cb2005e79dd8f64ac20c66fa2baeda.zip
Simple BuildInfo plugin (#325)
* Simple BuildInfo plugin * BuildInfo readme include other known yet external plugins * Add tests
Diffstat (limited to 'contrib/buildinfo/test/src')
-rw-r--r--contrib/buildinfo/test/src/mill/contrib/BuildInfoTests.scala112
1 files changed, 112 insertions, 0 deletions
diff --git a/contrib/buildinfo/test/src/mill/contrib/BuildInfoTests.scala b/contrib/buildinfo/test/src/mill/contrib/BuildInfoTests.scala
new file mode 100644
index 00000000..9e1549de
--- /dev/null
+++ b/contrib/buildinfo/test/src/mill/contrib/BuildInfoTests.scala
@@ -0,0 +1,112 @@
+package mill.contrib
+
+import ammonite.ops._
+import java.util.jar.JarFile
+import mill._
+import mill.define.Target
+import mill.eval.Result._
+import mill.eval.{Evaluator, Result}
+import mill.modules.Assembly
+import mill.scalalib.publish.VersionControl
+import mill.scalalib.publish._
+import mill.util.{TestEvaluator, TestUtil}
+import scala.collection.JavaConverters._
+import utest._
+import utest.framework.TestPath
+
+
+object BuildInfoTests extends TestSuite {
+
+ val scalaVersionString = "2.12.4"
+ trait BuildInfoModule extends TestUtil.BaseModule with scalalib.ScalaModule with BuildInfo {
+ def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.')
+ def scalaVersion = scalaVersionString
+ }
+
+ object EmptyBuildInfo extends BuildInfoModule
+
+ object BuildInfo extends BuildInfoModule {
+ def buildInfoMembers=T{
+ Map(
+ "scalaVersion" -> scalaVersion(),
+ )
+ }
+ }
+
+ object BuildInfoSettings extends BuildInfoModule {
+ def buildInfoPackageName = Some("foo")
+ def buildInfoObjectName = "bar"
+ def buildInfoMembers=T{
+ Map(
+ "scalaVersion" -> scalaVersion()
+ )
+ }
+ }
+
+ val resourcePath = pwd / 'contrib / 'buildinfo / 'test / 'resources / "buildinfo"
+
+ def workspaceTest[T, M <: TestUtil.BaseModule](m: M, resourcePath: Path = resourcePath)
+ (t: TestEvaluator[M] => T)
+ (implicit tp: TestPath): T = {
+ val eval = new TestEvaluator(m)
+ rm(m.millSourcePath)
+ rm(eval.outPath)
+ mkdir(m.millSourcePath / up)
+ cp(resourcePath, m.millSourcePath)
+ t(eval)
+ }
+
+ def tests: Tests = Tests {
+
+ 'buildinfo - {
+ 'createSourcefile - workspaceTest(BuildInfo){ eval =>
+ val expected =
+ s"""|
+ |object BuildInfo {
+ | def scalaVersion = "2.12.4"
+ |}""".stripMargin
+ val Right((result, evalCount)) = eval.apply(BuildInfo.buildInfo)
+ assert(
+ result.head.path == eval.outPath / 'buildInfo / 'dest / "BuildInfo.scala" &&
+ exists(result.head.path) &&
+ read! result.head.path == expected
+ )
+ }
+
+ 'notCreateEmptySourcefile - workspaceTest(EmptyBuildInfo){ eval =>
+ val Right((result, evalCount)) = eval.apply(EmptyBuildInfo.buildInfo)
+ assert(
+ result.isEmpty &&
+ !exists(eval.outPath / 'buildInfo / 'dest / "BuildInfo.scala")
+ )
+ }
+
+ 'supportCustomSettings - workspaceTest(BuildInfoSettings){ eval =>
+ val expected =
+ s"""|package foo
+ |object bar {
+ | def scalaVersion = "2.12.4"
+ |}""".stripMargin
+ val Right((result, evalCount)) = eval.apply(BuildInfoSettings.buildInfo)
+ assert(
+ result.head.path == eval.outPath / 'buildInfo / 'dest / "BuildInfo.scala" &&
+ exists(result.head.path) &&
+ read! result.head.path == expected
+ )
+ }
+
+ 'compile - workspaceTest(BuildInfo){ eval =>
+ val Right((result, evalCount)) = eval.apply(BuildInfo.compile)
+ assert(true)
+ }
+
+ 'run - workspaceTest(BuildInfo){ eval =>
+ val runResult = eval.outPath / "hello-mill"
+ val Right((result, evalCount)) = eval.apply(BuildInfo.run(runResult.toString))
+ assert(
+ exists(runResult),
+ read(runResult) == scalaVersionString)
+ }
+ }
+ }
+}