summaryrefslogtreecommitdiff
path: root/scalalib/test/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-11-05 03:00:04 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-11-05 21:14:58 +0800
commitbc9dc386625021fec517f2dbf0644ccafe1e32c2 (patch)
tree12db6817470708c7aa274aa231ef35eb79f2123a /scalalib/test/src
parent8afe79afe33be68f59f89b8410984e508c3e8d08 (diff)
downloadmill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.tar.gz
mill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.tar.bz2
mill-bc9dc386625021fec517f2dbf0644ccafe1e32c2.zip
WIP migrating over from `ammonite.ops` to `os` module.
__.compile works, haven't run tests yet
Diffstat (limited to 'scalalib/test/src')
-rw-r--r--scalalib/test/src/mill/scalalib/GenIdeaTests.scala7
-rw-r--r--scalalib/test/src/mill/scalalib/HelloJavaTests.scala24
-rw-r--r--scalalib/test/src/mill/scalalib/HelloWorldTests.scala110
-rw-r--r--scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala23
4 files changed, 81 insertions, 83 deletions
diff --git a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
index db70a325..d4a8cabd 100644
--- a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
+++ b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
@@ -1,6 +1,5 @@
package mill.scalalib
-import ammonite.ops._
import coursier.Cache
import mill._
import mill.util.{TestEvaluator, TestUtil}
@@ -8,7 +7,7 @@ import utest._
object GenIdeaTests extends TestSuite {
- val millSourcePath = pwd / 'target / 'workspace / "gen-idea"
+ val millSourcePath = os.pwd / 'target / 'workspace / "gen-idea"
trait HelloWorldModule extends scalalib.ScalaModule {
def scalaVersion = "2.12.4"
@@ -31,7 +30,7 @@ object GenIdeaTests extends TestSuite {
HelloWorld,
("JDK_1_8", "1.8 (1)"), fetchMillModules = false)
for((relPath, xml) <- layout){
- write.over(millSourcePath/ "generated"/ relPath, pp.format(xml))
+ os.write.over(millSourcePath/ "generated"/ relPath, pp.format(xml))
}
Seq(
@@ -49,7 +48,7 @@ object GenIdeaTests extends TestSuite {
millSourcePath / "generated" / ".idea" / "misc.xml"
).foreach { case (resource, generated) =>
val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n")
- val generatedString = normaliseLibraryPaths(read! generated)
+ val generatedString = normaliseLibraryPaths(os.read(generated))
assert(resourceString == generatedString)
}
diff --git a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala
index 7e044475..ff0de5a6 100644
--- a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala
+++ b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala
@@ -2,8 +2,6 @@ package mill
package scalalib
-import ammonite.ops.{%, %%, cp, ls, mkdir, pwd, rm, up}
-import ammonite.ops.ImplicitWd._
import mill.eval.Result
import mill.util.{TestEvaluator, TestUtil}
import utest._
@@ -27,14 +25,14 @@ object HelloJavaTests extends TestSuite {
object test extends Tests with JUnitTests
}
}
- val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-java"
+ val resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-java"
def init()(implicit tp: TestPath) = {
val eval = new TestEvaluator(HelloJava)
- rm(HelloJava.millSourcePath)
- rm(eval.outPath)
- mkdir(HelloJava.millSourcePath / up)
- cp(resourcePath, HelloJava.millSourcePath)
+ os.remove.all(HelloJava.millSourcePath)
+ os.remove.all(eval.outPath)
+ os.makeDir.all(HelloJava.millSourcePath / os.up)
+ os.copy(resourcePath, HelloJava.millSourcePath)
eval
}
def tests: Tests = Tests {
@@ -49,10 +47,10 @@ object HelloJavaTests extends TestSuite {
res1 == res2,
n1 != 0,
n2 != 0,
- ls.rec(res1.classes.path).exists(_.last == "Core.class"),
- !ls.rec(res1.classes.path).exists(_.last == "Main.class"),
- ls.rec(res3.classes.path).exists(_.last == "Main.class"),
- !ls.rec(res3.classes.path).exists(_.last == "Core.class")
+ os.walk(res1.classes.path).exists(_.last == "Core.class"),
+ !os.walk(res1.classes.path).exists(_.last == "Main.class"),
+ os.walk(res3.classes.path).exists(_.last == "Main.class"),
+ !os.walk(res3.classes.path).exists(_.last == "Core.class")
)
}
'docJar - {
@@ -62,8 +60,8 @@ object HelloJavaTests extends TestSuite {
val Right((ref2, _)) = eval.apply(HelloJava.app.docJar)
assert(
- %%("jar", "tf", ref1.path).out.lines.contains("hello/Core.html"),
- %%("jar", "tf", ref2.path).out.lines.contains("hello/Main.html")
+ os.proc("jar", "tf", ref1.path).call().out.lines.contains("hello/Core.html"),
+ os.proc("jar", "tf", ref2.path).call().out.lines.contains("hello/Main.html")
)
}
'test - {
diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
index 1839e275..67c4b433 100644
--- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
@@ -1,8 +1,8 @@
package mill.scalalib
+import java.io.ByteArrayOutputStream
import java.util.jar.JarFile
-import ammonite.ops._
import mill._
import mill.define.Target
import mill.eval.Result.Exception
@@ -265,7 +265,7 @@ object HelloWorldTests extends TestSuite {
}
}
- val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world"
+ val resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world"
def jarMainClass(jar: JarFile): Option[String] = {
import java.util.jar.Attributes._
@@ -279,10 +279,12 @@ object HelloWorldTests extends TestSuite {
def readFileFromJar(jar: JarFile, name: String): String = {
val is = jar.getInputStream(jar.getEntry(name))
- read(is)
+ val baos = new ByteArrayOutputStream()
+ os.Internals.transfer(is, baos)
+ new String(baos.toByteArray)
}
- def compileClassfiles = Seq[RelPath](
+ def compileClassfiles = Seq[os.RelPath](
"Main.class",
"Main$.class",
"Main0.class",
@@ -292,14 +294,14 @@ object HelloWorldTests extends TestSuite {
"Person$.class"
)
- def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: Path = resourcePath)
+ def workspaceTest[T](m: TestUtil.BaseModule, resourcePath: os.Path = resourcePath)
(t: TestEvaluator => T)
(implicit tp: TestPath): T = {
val eval = new TestEvaluator(m)
- rm(m.millSourcePath)
- rm(eval.outPath)
- mkdir(m.millSourcePath / up)
- cp(resourcePath, m.millSourcePath)
+ os.remove.all(m.millSourcePath)
+ os.remove.all(eval.outPath)
+ os.makeDir.all(m.millSourcePath / os.up)
+ os.copy(resourcePath, m.millSourcePath)
t(eval)
}
@@ -371,29 +373,29 @@ object HelloWorldTests extends TestSuite {
// make sure options are passed during ScalaDoc generation
'docJarWithTitle - workspaceTest(
HelloWorldDocTitle,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldDocTitle.core.docJar)
assert(
evalCount > 0,
- read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-title\">Hello World")
+ os.read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-title\">Hello World")
)
}
'docJarWithVersion - workspaceTest(
HelloWorldWithDocVersion,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world"
){ eval =>
// scaladoc generation fails because of "-Xfatal-warnings" flag
val Left(Result.Failure("docJar generation failed", None)) = eval.apply(HelloWorldWithDocVersion.core.docJar)
}
'docJarOnlyVersion - workspaceTest(
HelloWorldOnlyDocVersion,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldOnlyDocVersion.core.docJar)
assert(
evalCount > 0,
- read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-version\">1.2.3")
+ os.read(eval.outPath / 'core / 'docJar / 'dest / 'javadoc / "index.html").contains("<span id=\"doc-version\">1.2.3")
)
}
}
@@ -426,13 +428,13 @@ object HelloWorldTests extends TestSuite {
val Right((result, evalCount)) = eval.apply(HelloWorld.core.compile)
val analysisFile = result.analysisFile
- val outputFiles = ls.rec(result.classes.path)
+ val outputFiles = os.walk(result.classes.path)
val expectedClassfiles = compileClassfiles.map(
eval.outPath / 'core / 'compile / 'dest / 'classes / _
)
assert(
result.classes.path == eval.outPath / 'core / 'compile / 'dest / 'classes,
- exists(analysisFile),
+ os.exists(analysisFile),
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
evalCount > 0
@@ -447,13 +449,13 @@ object HelloWorldTests extends TestSuite {
val Right((_, freshCount)) = eval.apply(HelloWorld.core.compile)
assert(freshCount > 0)
- write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "\n")
+ os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "\n")
val Right((_, incCompileCount)) = eval.apply(HelloWorld.core.compile)
assert(incCompileCount > 0, incCompileCount < freshCount)
}
'failOnError - workspaceTest(HelloWorld){eval =>
- write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ")
+ os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ")
val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.compile)
@@ -464,13 +466,13 @@ object HelloWorldTests extends TestSuite {
)
assert(
- ls.rec(paths.dest / 'classes).isEmpty,
- !exists(paths.meta)
+ os.walk(paths.dest / 'classes).isEmpty,
+ !os.exists(paths.meta)
)
// Works when fixed
- write.over(
+ os.write.over(
HelloWorld.millSourcePath / 'core / 'src / "Main.scala",
- read(HelloWorld.millSourcePath / 'core / 'src / "Main.scala").dropRight("val x: ".length)
+ os.read(HelloWorld.millSourcePath / 'core / 'src / "Main.scala").dropRight("val x: ".length)
)
val Right((result, evalCount)) = eval.apply(HelloWorld.core.compile)
@@ -489,8 +491,8 @@ object HelloWorldTests extends TestSuite {
assert(evalCount > 0)
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
'runCross - {
@@ -506,8 +508,8 @@ object HelloWorldTests extends TestSuite {
assert(
- exists(runResult),
- read(runResult) == expectedOut
+ os.exists(runResult),
+ os.read(runResult) == expectedOut
)
}
'v210 - TestUtil.disableInJava9OrAbove(workspaceTest(CrossHelloWorld)(cross(_, "2.10.6", "2.10.6 rox")))
@@ -522,7 +524,7 @@ object HelloWorldTests extends TestSuite {
val Left(Result.Failure("subprocess failed", _)) = eval.apply(HelloWorld.core.runMain("Invalid"))
}
'notRunWhenCompileFailed - workspaceTest(HelloWorld){eval =>
- write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ")
+ os.write.append(HelloWorld.millSourcePath / 'core / 'src / "Main.scala", "val x: ")
val Left(Result.Failure("Compilation failed", _)) = eval.apply(HelloWorld.core.runMain("Main"))
@@ -540,13 +542,13 @@ object HelloWorldTests extends TestSuite {
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
'notRunWithoutMainClass - workspaceTest(
HelloWorldWithoutMain,
- pwd / 'scalalib / 'test / 'resources / "hello-world-no-main"
+ os.pwd / 'scalalib / 'test / 'resources / "hello-world-no-main"
){eval =>
val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.run())
}
@@ -563,8 +565,8 @@ object HelloWorldTests extends TestSuite {
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
}
@@ -580,8 +582,8 @@ object HelloWorldTests extends TestSuite {
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
'runWithDefaultMain - workspaceTest(HelloWorldDefaultMain){eval =>
@@ -594,13 +596,13 @@ object HelloWorldTests extends TestSuite {
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
'notRunWithoutMainClass - workspaceTest(
HelloWorldWithoutMain,
- pwd / 'scalalib / 'test / 'resources / "hello-world-no-main"
+ os.pwd / 'scalalib / 'test / 'resources / "hello-world-no-main"
){eval =>
val Left(Result.Failure(_, None)) = eval.apply(HelloWorldWithoutMain.core.runLocal())
@@ -612,15 +614,15 @@ object HelloWorldTests extends TestSuite {
val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.jar)
assert(
- exists(result.path),
+ os.exists(result.path),
evalCount > 0
)
val jarFile = new JarFile(result.path.toIO)
val entries = jarFile.entries().asScala.map(_.getName).toSet
- val otherFiles = Seq[RelPath](
- "META-INF" / "MANIFEST.MF",
+ val otherFiles = Seq[os.RelPath](
+ os.rel / "META-INF" / "MANIFEST.MF",
"reference.conf"
)
val expectedFiles = compileClassfiles ++ otherFiles
@@ -639,7 +641,7 @@ object HelloWorldTests extends TestSuite {
eval.apply(HelloWorld.core.compile)
val logFile = outPath / 'core / 'compile / 'log
- assert(exists(logFile))
+ assert(os.exists(logFile))
}
}
@@ -647,7 +649,7 @@ object HelloWorldTests extends TestSuite {
'assembly - workspaceTest(HelloWorldWithMain){ eval =>
val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly)
assert(
- exists(result.path),
+ os.exists(result.path),
evalCount > 0
)
val jarFile = new JarFile(result.path.toIO)
@@ -687,7 +689,7 @@ object HelloWorldTests extends TestSuite {
)
}
- val helloWorldMultiResourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-multi"
+ val helloWorldMultiResourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-multi"
def checkAppendMulti[M <: TestUtil.BaseModule](
module: M,
@@ -734,7 +736,7 @@ object HelloWorldTests extends TestSuite {
def checkExclude[M <: TestUtil.BaseModule](module: M,
target: Target[PathRef],
- resourcePath: Path = resourcePath
+ resourcePath: os.Path = resourcePath
) =
workspaceTest(module, resourcePath) { eval =>
val Right((result, _)) = eval.apply(target)
@@ -814,16 +816,16 @@ object HelloWorldTests extends TestSuite {
val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.core.assembly)
assert(
- exists(result.path),
+ os.exists(result.path),
evalCount > 0
)
val runResult = eval.outPath / "hello-mill"
- %%("java", "-jar", result.path, runResult)(wd = eval.outPath)
+ os.proc("java", "-jar", result.path, runResult).call(cwd = eval.outPath)
assert(
- exists(runResult),
- read(runResult) == "hello rockjam, your age is: 25"
+ os.exists(runResult),
+ os.read(runResult) == "hello rockjam, your age is: 25"
)
}
}
@@ -866,7 +868,7 @@ object HelloWorldTests extends TestSuite {
// make sure macros are applied when compiling/running
'runMain - workspaceTest(
HelloWorldMacros,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-macros"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-macros"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldMacros.core.runMain("Main"))
assert(evalCount > 0)
@@ -874,7 +876,7 @@ object HelloWorldTests extends TestSuite {
// make sure macros are applied when compiling during scaladoc generation
'docJar - workspaceTest(
HelloWorldMacros,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-macros"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-macros"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldMacros.core.docJar)
assert(evalCount > 0)
@@ -885,7 +887,7 @@ object HelloWorldTests extends TestSuite {
// make sure flags are passed when compiling/running
'runMain - workspaceTest(
HelloWorldFlags,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-flags"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-flags"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldFlags.core.runMain("Main"))
assert(evalCount > 0)
@@ -893,7 +895,7 @@ object HelloWorldTests extends TestSuite {
// make sure flags are passed during ScalaDoc generation
'docJar - workspaceTest(
HelloWorldFlags,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world-flags"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-world-flags"
){ eval =>
val Right((_, evalCount)) = eval.apply(HelloWorldFlags.core.docJar)
assert(evalCount > 0)
@@ -902,7 +904,7 @@ object HelloWorldTests extends TestSuite {
'scalacheck - workspaceTest(
HelloScalacheck,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-scalacheck"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-scalacheck"
){ eval =>
val Right((res, evalCount)) = eval.apply(HelloScalacheck.foo.test.test())
assert(
@@ -918,7 +920,7 @@ object HelloWorldTests extends TestSuite {
'dotty - workspaceTest(
HelloDotty,
- resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-dotty"
+ resourcePath = os.pwd / 'scalalib / 'test / 'resources / "hello-dotty"
){ eval =>
if (isJavaAtLeast("9")) {
// Skip the test because Dotty does not support Java >= 9 yet
diff --git a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala
index 89d549ff..dcbdb769 100644
--- a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala
+++ b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala
@@ -1,6 +1,5 @@
package mill.scalalib.scalafmt
-import ammonite.ops._
import mill.main.Tasks
import mill.scalalib.ScalaModule
import mill.util.{TestEvaluator, TestUtil}
@@ -20,17 +19,17 @@ object ScalafmtTests extends TestSuite {
}
}
- val resourcePath = pwd / 'scalalib / 'test / 'resources / 'scalafmt
+ val resourcePath = os.pwd / 'scalalib / 'test / 'resources / 'scalafmt
def workspaceTest[T](
m: TestUtil.BaseModule,
- resourcePath: Path = resourcePath)(t: TestEvaluator => T)(
+ resourcePath: os.Path = resourcePath)(t: TestEvaluator => T)(
implicit tp: TestPath): T = {
val eval = new TestEvaluator(m)
- rm(m.millSourcePath)
- rm(eval.outPath)
- mkdir(m.millSourcePath / up)
- cp(resourcePath, m.millSourcePath)
+ os.remove.all(m.millSourcePath)
+ os.remove.all(eval.outPath)
+ os.makeDir.all(m.millSourcePath / os.up)
+ os.copy(resourcePath, m.millSourcePath)
t(eval)
}
@@ -68,7 +67,7 @@ object ScalafmtTests extends TestSuite {
)
// reformat after change
- write.over(cached("Main.scala").path,
+ os.write.over(cached("Main.scala").path,
cached("Main.scala").content + "\n object Foo")
val Right(_) = eval.apply(reformatCommand)
@@ -89,16 +88,16 @@ object ScalafmtTests extends TestSuite {
}
}
- case class FileInfo(content: String, modifyTime: Long, path: Path)
+ case class FileInfo(content: String, modifyTime: Long, path: os.Path)
def getProjectFiles(m: ScalaModule, eval: TestEvaluator) = {
val Right((sources, _)) = eval.apply(m.sources)
val Right((resources, _)) = eval.apply(m.resources)
- val sourcesFiles = sources.flatMap(p => ls.rec(p.path))
- val resourcesFiles = resources.flatMap(p => ls.rec(p.path))
+ val sourcesFiles = sources.flatMap(p => os.walk(p.path))
+ val resourcesFiles = resources.flatMap(p => os.walk(p.path))
(sourcesFiles ++ resourcesFiles).map { p =>
- p.name -> FileInfo(read(p), p.mtime.toMillis, p)
+ p.last -> FileInfo(os.read(p), os.mtime(p), p)
}.toMap
}