summaryrefslogtreecommitdiff
path: root/main/test/src/mill/util/ScriptTestSuite.scala
blob: 0d1ff43a1a25e2b2c75c0bfafbc8a48ec313b066 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package mill.util

import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream}

import ammonite.ops._
import utest._

abstract class ScriptTestSuite extends TestSuite{
  def workspaceSlug: String
  def scriptSourcePath: Path

  val workspacePath = pwd / 'target / 'workspace / workspaceSlug
//  val stdOutErr = new PrintStream(new ByteArrayOutputStream())
  val stdOutErr = new PrintStream(System.out)
  val stdIn = new ByteArrayInputStream(Array())
  val runner = new mill.main.MainRunner(
    ammonite.main.Cli.Config(wd = workspacePath),
    stdOutErr, stdOutErr, stdIn
  )
  def eval(s: String*) = runner.runScript(workspacePath / "build.sc", s.toList)
  def meta(s: String) = {
    val (List(selector), args) = ParseArgs.apply(Seq(s), multiSelect = false).right.get

    read(workspacePath / "out" / selector._2.value.flatMap(_.pathSegments) / "meta.json")
  }


  def initWorkspace() = {
    rm(workspacePath)
    mkdir(workspacePath / 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.

    cp(scriptSourcePath, workspacePath)
  }
}