Skip to content

Commit

Permalink
Merge pull request #1225 from Gedochao/simplify-test-inputs
Browse files Browse the repository at this point in the history
NIT Tweak integration tests
  • Loading branch information
Gedochao authored Aug 2, 2022
2 parents cad549f + cc725b2 commit 34ab671
Show file tree
Hide file tree
Showing 44 changed files with 1,509 additions and 1,859 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class RunDockerTests extends munit.FunSuite {
val fileName = "simple.sc"
val message = "Hello"
val inputs = TestInputs(
Seq(
os.rel / fileName ->
s"""val msg = "$message"
|println(msg)
|""".stripMargin
)
os.rel / fileName ->
s"""val msg = "$message"
|println(msg)
|""".stripMargin
)
inputs.fromRoot { root =>
val termOpt = if (System.console() == null) Nil else Seq("-t")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import java.util.zip.{ZipEntry, ZipOutputStream}
import scala.cli.integration.TestInputs.compress
import scala.util.control.NonFatal

final case class TestInputs(
files: Seq[(os.RelPath, String)]
) {
def add(extraFiles: (os.RelPath, String)*): TestInputs =
copy(files = files ++ extraFiles)
final case class TestInputs(files: (os.RelPath, String)*) {
def add(extraFiles: (os.RelPath, String)*): TestInputs = TestInputs((files ++ extraFiles)*)

private def writeIn(dir: os.Path): Unit =
for ((relPath, content) <- files) {
val path = dir / relPath
Expand All @@ -38,6 +36,7 @@ final case class TestInputs(
}

object TestInputs {
def empty: TestInputs = TestInputs()

def compress(zipFilepath: os.Path, files: Seq[(os.RelPath, String)]) = {
val zip = new ZipOutputStream(new FileOutputStream(zipFilepath.toString()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import os.proc

import scala.cli.integration.util.BloopUtil

class BloopTests extends ScalaCliSuite {

def runScalaCli(args: String*) = os.proc(TestUtil.cli, args)
def runScalaCli(args: String*): proc = os.proc(TestUtil.cli, args)

private lazy val bloopDaemonDir =
BloopUtil.bloopDaemonDir(runScalaCli("directories").call().out.text())

val dummyInputs = TestInputs(
Seq(
os.rel / "Test.scala" ->
"""//> using scala "2.13"
|object Test {
| def main(args: Array[String]): Unit =
| println("Hello " + "from test")
|}
|""".stripMargin
)
val dummyInputs: TestInputs = TestInputs(
os.rel / "Test.scala" ->
"""//> using scala "2.13"
|object Test {
| def main(args: Array[String]): Unit =
| println("Hello " + "from test")
|}
|""".stripMargin
)

def testScalaTermination(
Expand Down Expand Up @@ -57,7 +56,7 @@ class BloopTests extends ScalaCliSuite {
}

test("invalid bloop options passed via cli cause bloop start failure") {
TestInputs(Seq()).fromRoot { root =>
TestInputs.empty.fromRoot { root =>
runScalaCli("bloop", "exit").call(cwd = root)
val res = runScalaCli("bloop", "start", "--bloop-java-opt", "-zzefhjzl").call(
cwd = root,
Expand All @@ -72,12 +71,10 @@ class BloopTests extends ScalaCliSuite {

test("invalid bloop options passed via global bloop config json file cause bloop start failure") {
val inputs = TestInputs(
Seq(
os.rel / "bloop.json" ->
"""|{
| "javaOptions" : ["-Xmx1k"]
| }""".stripMargin
)
os.rel / "bloop.json" ->
"""|{
| "javaOptions" : ["-Xmx1k"]
| }""".stripMargin
)

inputs.fromRoot { root =>
Expand All @@ -101,7 +98,7 @@ class BloopTests extends ScalaCliSuite {
javaProcesses.contains("bloop.Bloop")
}

val inputs = TestInputs(Seq.empty)
val inputs = TestInputs.empty
inputs.fromRoot { _ =>
BloopUtil.killBloop()
TestUtil.retry()(assert(!bloopRunning()))
Expand All @@ -118,14 +115,12 @@ class BloopTests extends ScalaCliSuite {

test("bloop projects and bloop compile works") {
val inputs = TestInputs(
Seq(
os.rel / "Hello.scala" ->
"""object Hello {
| def main(args: Array[String]): Unit =
| println("Hello")
|}
|""".stripMargin
)
os.rel / "Hello.scala" ->
"""object Hello {
| def main(args: Array[String]): Unit =
| println("Hello")
|}
|""".stripMargin
)
inputs.fromRoot { root =>

Expand Down
Loading

0 comments on commit 34ab671

Please sign in to comment.