Skip to content

Commit f4dd80d

Browse files
committed
NIT Refactor existing resources tests
1 parent cd84ae9 commit f4dd80d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,10 @@ abstract class RunTestDefinitions
560560
forbiddenDirTest()
561561
}
562562

563-
private def resourcesInputs(directive: String = "") = {
564-
val resourceContent = "Hello from resources"
563+
protected def resourcesInputs(
564+
directive: String = "",
565+
resourceContent: String = "Hello from resources"
566+
): TestInputs =
565567
TestInputs(
566568
os.rel / "src" / "proj" / "resources" / "test" / "data" -> resourceContent,
567569
os.rel / "src" / "proj" / "Test.scala" ->
@@ -571,24 +573,30 @@ abstract class RunTestDefinitions
571573
| val cl = Thread.currentThread().getContextClassLoader
572574
| val is = cl.getResourceAsStream("test/data")
573575
| val content = scala.io.Source.fromInputStream(is)(scala.io.Codec.UTF8).mkString
574-
| assert(content == "$resourceContent")
576+
| println(content)
575577
| }
576578
|}
577579
|""".stripMargin
578580
)
579-
}
580581

581-
test("resources") {
582-
resourcesInputs().fromRoot { root =>
583-
os.proc(TestUtil.cli, "run", "src", "--resource-dirs", "./src/proj/resources").call(cwd =
584-
root
585-
)
582+
test("resources via command line") {
583+
val expectedMessage = "hello"
584+
resourcesInputs(resourceContent = expectedMessage).fromRoot { root =>
585+
val res = os.proc(TestUtil.cli, "run", "src", "--resource-dirs", "./src/proj/resources")
586+
.call(cwd = root)
587+
expect(res.out.trim() == expectedMessage)
586588
}
587589
}
588590
test("resources via directive") {
589-
resourcesInputs("//> using resourceDirs \"./resources\"").fromRoot { root =>
590-
os.proc(TestUtil.cli, "run", ".").call(cwd = root)
591-
}
591+
val expectedMessage = "hello"
592+
resourcesInputs(
593+
directive = "//> using resourceDirs \"./resources\"",
594+
resourceContent = expectedMessage
595+
)
596+
.fromRoot { root =>
597+
val res = os.proc(TestUtil.cli, "run", ".").call(cwd = root)
598+
expect(res.out.trim() == expectedMessage)
599+
}
592600
}
593601

594602
def argsAsIsTest(): Unit = {

0 commit comments

Comments
 (0)