diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-12-12 16:56:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 16:56:02 -0800 |
commit | 9ba4cb69331386dfde9bac69dc2d5b22401face3 (patch) | |
tree | 120349e8015ae5717d36bd44209cde6ff9543518 /main/test/src/util/ScriptTestSuite.scala | |
parent | ea7fceb6e56f53bde3517586dfc57e10a605a524 (diff) | |
download | mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.gz mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.tar.bz2 mill-9ba4cb69331386dfde9bac69dc2d5b22401face3.zip |
collapse boilerplate folder structure within src/ folders (#505)
* collapse boilerplate folder structure within src/ folders
* .
Diffstat (limited to 'main/test/src/util/ScriptTestSuite.scala')
-rw-r--r-- | main/test/src/util/ScriptTestSuite.scala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/main/test/src/util/ScriptTestSuite.scala b/main/test/src/util/ScriptTestSuite.scala new file mode 100644 index 00000000..f448aaaf --- /dev/null +++ b/main/test/src/util/ScriptTestSuite.scala @@ -0,0 +1,53 @@ +package mill.util + +import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream} + +import utest._ + +abstract class ScriptTestSuite(fork: Boolean) extends TestSuite{ + def workspaceSlug: String + def scriptSourcePath: os.Path + def buildPath: os.RelPath = "build.sc" + + val workspacePath = os.pwd / 'target / 'workspace / workspaceSlug + val wd = workspacePath / buildPath / os.up + val stdOutErr = System.out // new PrintStream(new ByteArrayOutputStream()) + val stdIn = new ByteArrayInputStream(Array()) + val disableTicker = false + val debugLog = false + lazy val runner = new mill.main.MainRunner( + ammonite.main.Cli.Config(wd = wd), disableTicker, + stdOutErr, stdOutErr, stdIn, None, Map.empty, + b => (), debugLog + ) + def eval(s: String*) = { + if (!fork) runner.runScript(workspacePath / buildPath , s.toList) + else{ + try { + os.proc(os.home / "mill-release", "-i", s).call( + wd, + stdin = os.Inherit, + stdout = os.Inherit, + stderr = os.Inherit, + ) + true + }catch{case e: Throwable => false} + } + } + def meta(s: String) = { + val (List(selector), args) = ParseArgs.apply(Seq(s), multiSelect = false).right.get + + os.read(wd / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json") + } + + + def initWorkspace() = { + os.remove.all(workspacePath) + os.makeDir.all(workspacePath / os.up) + // The unzipped git repo snapshots we get from github come with a + // wrapper-folder inside the zip file, so copy the wrapper folder to the + // destination instead of the folder containing the wrapper. + + os.copy(scriptSourcePath, workspacePath) + } +} |