Skip to content

Commit b6c0149

Browse files
committed
NIT Refactor: simplify TestInputs creation
1 parent a03dc8d commit b6c0149

37 files changed

+1426
-1778
lines changed

modules/integration/docker/src/test/scala/scala/cli/integration/RunDockerTests.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ class RunDockerTests extends munit.FunSuite {
1515
val fileName = "simple.sc"
1616
val message = "Hello"
1717
val inputs = TestInputs(
18-
Seq(
19-
os.rel / fileName ->
20-
s"""val msg = "$message"
21-
|println(msg)
22-
|""".stripMargin
23-
)
18+
os.rel / fileName ->
19+
s"""val msg = "$message"
20+
|println(msg)
21+
|""".stripMargin
2422
)
2523
inputs.fromRoot { root =>
2624
val termOpt = if (System.console() == null) Nil else Seq("-t")

modules/integration/src/main/scala/scala/cli/integration/TestInputs.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import java.util.zip.{ZipEntry, ZipOutputStream}
99
import scala.cli.integration.TestInputs.compress
1010
import scala.util.control.NonFatal
1111

12-
final case class TestInputs(
13-
files: Seq[(os.RelPath, String)]
14-
) {
15-
def add(extraFiles: (os.RelPath, String)*): TestInputs =
16-
copy(files = files ++ extraFiles)
12+
final case class TestInputs(files: (os.RelPath, String)*) {
13+
def add(extraFiles: (os.RelPath, String)*): TestInputs = TestInputs((files ++ extraFiles)*)
14+
1715
private def writeIn(dir: os.Path): Unit =
1816
for ((relPath, content) <- files) {
1917
val path = dir / relPath
@@ -38,6 +36,7 @@ final case class TestInputs(
3836
}
3937

4038
object TestInputs {
39+
def empty: TestInputs = TestInputs()
4140

4241
def compress(zipFilepath: os.Path, files: Seq[(os.RelPath, String)]) = {
4342
val zip = new ZipOutputStream(new FileOutputStream(zipFilepath.toString()))

modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ class BloopTests extends ScalaCliSuite {
1212
BloopUtil.bloopDaemonDir(runScalaCli("directories").call().out.text())
1313

1414
val dummyInputs = TestInputs(
15-
Seq(
16-
os.rel / "Test.scala" ->
17-
"""//> using scala "2.13"
18-
|object Test {
19-
| def main(args: Array[String]): Unit =
20-
| println("Hello " + "from test")
21-
|}
22-
|""".stripMargin
23-
)
15+
os.rel / "Test.scala" ->
16+
"""//> using scala "2.13"
17+
|object Test {
18+
| def main(args: Array[String]): Unit =
19+
| println("Hello " + "from test")
20+
|}
21+
|""".stripMargin
2422
)
2523

2624
def testScalaTermination(
@@ -57,7 +55,7 @@ class BloopTests extends ScalaCliSuite {
5755
}
5856

5957
test("invalid bloop options passed via cli cause bloop start failure") {
60-
TestInputs(Seq()).fromRoot { root =>
58+
TestInputs.empty.fromRoot { root =>
6159
runScalaCli("bloop", "exit").call(cwd = root)
6260
val res = runScalaCli("bloop", "start", "--bloop-java-opt", "-zzefhjzl").call(
6361
cwd = root,
@@ -72,12 +70,10 @@ class BloopTests extends ScalaCliSuite {
7270

7371
test("invalid bloop options passed via global bloop config json file cause bloop start failure") {
7472
val inputs = TestInputs(
75-
Seq(
76-
os.rel / "bloop.json" ->
77-
"""|{
78-
| "javaOptions" : ["-Xmx1k"]
79-
| }""".stripMargin
80-
)
73+
os.rel / "bloop.json" ->
74+
"""|{
75+
| "javaOptions" : ["-Xmx1k"]
76+
| }""".stripMargin
8177
)
8278

8379
inputs.fromRoot { root =>
@@ -101,7 +97,7 @@ class BloopTests extends ScalaCliSuite {
10197
javaProcesses.contains("bloop.Bloop")
10298
}
10399

104-
val inputs = TestInputs(Seq.empty)
100+
val inputs = TestInputs.empty
105101
inputs.fromRoot { _ =>
106102
BloopUtil.killBloop()
107103
TestUtil.retry()(assert(!bloopRunning()))
@@ -118,14 +114,12 @@ class BloopTests extends ScalaCliSuite {
118114

119115
test("bloop projects and bloop compile works") {
120116
val inputs = TestInputs(
121-
Seq(
122-
os.rel / "Hello.scala" ->
123-
"""object Hello {
124-
| def main(args: Array[String]): Unit =
125-
| println("Hello")
126-
|}
127-
|""".stripMargin
128-
)
117+
os.rel / "Hello.scala" ->
118+
"""object Hello {
119+
| def main(args: Array[String]): Unit =
120+
| println("Hello")
121+
|}
122+
|""".stripMargin
129123
)
130124
inputs.fromRoot { root =>
131125

0 commit comments

Comments
 (0)