From 9ba4cb69331386dfde9bac69dc2d5b22401face3 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 12 Dec 2018 16:56:02 -0800 Subject: collapse boilerplate folder structure within src/ folders (#505) * collapse boilerplate folder structure within src/ folders * . --- contrib/tut/test/src/TutTests.scala | 123 +++++++++++++++++++++ .../tut/test/src/mill/contrib/tut/TutTests.scala | 123 --------------------- 2 files changed, 123 insertions(+), 123 deletions(-) create mode 100644 contrib/tut/test/src/TutTests.scala delete mode 100644 contrib/tut/test/src/mill/contrib/tut/TutTests.scala (limited to 'contrib/tut/test/src') diff --git a/contrib/tut/test/src/TutTests.scala b/contrib/tut/test/src/TutTests.scala new file mode 100644 index 00000000..468654bb --- /dev/null +++ b/contrib/tut/test/src/TutTests.scala @@ -0,0 +1,123 @@ +package mill.contrib +package tut + +import mill._ +import mill.api.Result._ +import mill.scalalib._ +import mill.util.{TestEvaluator, TestUtil} +import utest._ +import utest.framework.TestPath + +object TutTests extends TestSuite { + + trait TutTestModule extends TestUtil.BaseModule with TutModule { + def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') + def scalaVersion = "2.12.4" + def tutVersion = "0.6.7" + } + + object TutTest extends TutTestModule + + object TutCustomTest extends TutTestModule { + def tutTargetDirectory = millSourcePath + } + + object TutLibrariesTest extends TutTestModule { + def ivyDeps = Agg(ivy"org.typelevel::cats-core:1.4.0") + def tutSourceDirectory = T.sources { resourcePathWithLibraries } + def scalacPluginIvyDeps = Agg(ivy"org.spire-math::kind-projector:0.9.8") + } + + val resourcePath = os.pwd / 'contrib / 'tut / 'test / 'tut + val resourcePathWithLibraries = os.pwd / 'contrib / 'tut / 'test / "tut-with-libraries" + + def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: os.Path = resourcePath) + (t: TestEvaluator => T) + (implicit tp: TestPath): T = { + val eval = new TestEvaluator(m) + os.remove.all(m.millSourcePath) + os.remove.all(eval.outPath) + os.makeDir.all(m.millSourcePath) + os.copy(resourcePath, m.millSourcePath / 'tut) + t(eval) + } + + def tests: Tests = Tests { + 'tut - { + 'createOutputFile - workspaceTest(TutTest) { eval => + val expectedPath = + eval.outPath / 'tutTargetDirectory / 'dest / "TutExample.md" + + val expected = + """ + |```scala + |scala> 1 + 1 + |res0: Int = 2 + |``` + | + """.trim.stripMargin + + val Right((result, evalCount)) = eval.apply(TutTest.tut) + + assert( + os.exists(expectedPath) && + os.read(expectedPath) == expected + ) + } + + 'supportCustomSettings - workspaceTest(TutCustomTest) { eval => + val defaultPath = + eval.outPath / 'tutTargetDirectory / 'dest / "TutExample.md" + val expectedPath = + TutCustomTest.millSourcePath / "TutExample.md" + + val expected = + """ + |```scala + |scala> 1 + 1 + |res0: Int = 2 + |``` + | + """.trim.stripMargin + + val Right((result, evalCount)) = eval.apply(TutCustomTest.tut) + + assert( + !os.exists(defaultPath) && + os.exists(expectedPath) && + os.read(expectedPath) == expected + ) + } + + 'supportUsingLibraries - workspaceTest(TutLibrariesTest, resourcePath = resourcePathWithLibraries) { eval => + val expectedPath = + eval.outPath / 'tutTargetDirectory / 'dest / "TutWithLibraries.md" + + val expected = + """ + |```scala + |import cats._ + |import cats.arrow.FunctionK + |import cats.implicits._ + |``` + | + |```scala + |scala> List(1, 2, 3).combineAll + |res0: Int = 6 + | + |scala> λ[FunctionK[List, Option]](_.headOption)(List(1, 2 ,3)) + |res1: Option[Int] = Some(1) + |``` + | + """.trim.stripMargin + + val Right(_) = eval.apply(TutLibrariesTest.tut) + + assert( + os.exists(expectedPath) && + os.read(expectedPath) == expected + ) + } + } + } +} diff --git a/contrib/tut/test/src/mill/contrib/tut/TutTests.scala b/contrib/tut/test/src/mill/contrib/tut/TutTests.scala deleted file mode 100644 index 468654bb..00000000 --- a/contrib/tut/test/src/mill/contrib/tut/TutTests.scala +++ /dev/null @@ -1,123 +0,0 @@ -package mill.contrib -package tut - -import mill._ -import mill.api.Result._ -import mill.scalalib._ -import mill.util.{TestEvaluator, TestUtil} -import utest._ -import utest.framework.TestPath - -object TutTests extends TestSuite { - - trait TutTestModule extends TestUtil.BaseModule with TutModule { - def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') - def scalaVersion = "2.12.4" - def tutVersion = "0.6.7" - } - - object TutTest extends TutTestModule - - object TutCustomTest extends TutTestModule { - def tutTargetDirectory = millSourcePath - } - - object TutLibrariesTest extends TutTestModule { - def ivyDeps = Agg(ivy"org.typelevel::cats-core:1.4.0") - def tutSourceDirectory = T.sources { resourcePathWithLibraries } - def scalacPluginIvyDeps = Agg(ivy"org.spire-math::kind-projector:0.9.8") - } - - val resourcePath = os.pwd / 'contrib / 'tut / 'test / 'tut - val resourcePathWithLibraries = os.pwd / 'contrib / 'tut / 'test / "tut-with-libraries" - - def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: os.Path = resourcePath) - (t: TestEvaluator => T) - (implicit tp: TestPath): T = { - val eval = new TestEvaluator(m) - os.remove.all(m.millSourcePath) - os.remove.all(eval.outPath) - os.makeDir.all(m.millSourcePath) - os.copy(resourcePath, m.millSourcePath / 'tut) - t(eval) - } - - def tests: Tests = Tests { - 'tut - { - 'createOutputFile - workspaceTest(TutTest) { eval => - val expectedPath = - eval.outPath / 'tutTargetDirectory / 'dest / "TutExample.md" - - val expected = - """ - |```scala - |scala> 1 + 1 - |res0: Int = 2 - |``` - | - """.trim.stripMargin - - val Right((result, evalCount)) = eval.apply(TutTest.tut) - - assert( - os.exists(expectedPath) && - os.read(expectedPath) == expected - ) - } - - 'supportCustomSettings - workspaceTest(TutCustomTest) { eval => - val defaultPath = - eval.outPath / 'tutTargetDirectory / 'dest / "TutExample.md" - val expectedPath = - TutCustomTest.millSourcePath / "TutExample.md" - - val expected = - """ - |```scala - |scala> 1 + 1 - |res0: Int = 2 - |``` - | - """.trim.stripMargin - - val Right((result, evalCount)) = eval.apply(TutCustomTest.tut) - - assert( - !os.exists(defaultPath) && - os.exists(expectedPath) && - os.read(expectedPath) == expected - ) - } - - 'supportUsingLibraries - workspaceTest(TutLibrariesTest, resourcePath = resourcePathWithLibraries) { eval => - val expectedPath = - eval.outPath / 'tutTargetDirectory / 'dest / "TutWithLibraries.md" - - val expected = - """ - |```scala - |import cats._ - |import cats.arrow.FunctionK - |import cats.implicits._ - |``` - | - |```scala - |scala> List(1, 2, 3).combineAll - |res0: Int = 6 - | - |scala> λ[FunctionK[List, Option]](_.headOption)(List(1, 2 ,3)) - |res1: Option[Int] = Some(1) - |``` - | - """.trim.stripMargin - - val Right(_) = eval.apply(TutLibrariesTest.tut) - - assert( - os.exists(expectedPath) && - os.read(expectedPath) == expected - ) - } - } - } -} -- cgit v1.2.3