Skip to content

Commit

Permalink
Refactor out common test functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Dec 7, 2023
1 parent f1eb46f commit 57c523b
Showing 1 changed file with 23 additions and 40 deletions.
63 changes: 23 additions & 40 deletions tests/test/src/org/scalajs/cli/tests/Tests.scala
Expand Up @@ -11,6 +11,22 @@ class Tests extends munit.FunSuite {
sys.error("test.scala-js-cli.scala-js-version Java property not set")
)

def getScalaJsLibraryCp(cwd: os.Path) = os
.proc(
"cs",
"fetch",
"--classpath",
"-E",
"org.scala-lang:scala-library",
s"org.scala-js::scalajs-library:$scalaJsVersion"
)
.call(cwd = cwd)
.out
.trim()

def getScalaJsCompilerPlugin(cwd: os.Path) = os.proc("cs", "fetch", "--intransitive", s"org.scala-js:scalajs-compiler_2.13.6:$scalaJsVersion")
.call(cwd = cwd).out.trim()

test("tests") {
val dir = os.temp.dir()
os.write(
Expand All @@ -26,18 +42,7 @@ class Tests extends munit.FunSuite {
|""".stripMargin
)

val scalaJsLibraryCp = os
.proc(
"cs",
"fetch",
"--classpath",
"-E",
"org.scala-lang:scala-library",
s"org.scala-js::scalajs-library:$scalaJsVersion"
)
.call(cwd = dir)
.out
.trim()
val scalaJsLibraryCp = getScalaJsLibraryCp(dir)

os.makeDir.all(dir / "bin")
os.proc(
Expand All @@ -47,7 +52,7 @@ class Tests extends munit.FunSuite {
"--",
"-classpath",
scalaJsLibraryCp,
s"-Xplugin:${os.proc("cs", "fetch", "--intransitive", s"org.scala-js:scalajs-compiler_2.13.6:$scalaJsVersion").call(cwd = dir).out.trim()}",
s"-Xplugin:${getScalaJsCompilerPlugin(dir)}",
"-d",
"bin",
"foo.scala"
Expand Down Expand Up @@ -123,18 +128,7 @@ class Tests extends munit.FunSuite {
|""".stripMargin
)

val scalaJsLibraryCp = os
.proc(
"cs",
"fetch",
"--classpath",
"-E",
"org.scala-lang:scala-library",
s"org.scala-js::scalajs-library:$scalaJsVersion"
)
.call(cwd = dir)
.out
.trim()
val scalaJsLibraryCp = getScalaJsLibraryCp(dir)

os.makeDir.all(dir / "bin")
os.proc(
Expand All @@ -144,7 +138,7 @@ class Tests extends munit.FunSuite {
"--",
"-classpath",
scalaJsLibraryCp,
s"-Xplugin:${os.proc("cs", "fetch", "--intransitive", s"org.scala-js:scalajs-compiler_2.13.6:$scalaJsVersion").call(cwd = dir).out.trim()}",
s"-Xplugin:${getScalaJsCompilerPlugin(dir)}",
"-d",
"bin",
"foo.scala"
Expand All @@ -170,7 +164,7 @@ class Tests extends munit.FunSuite {
assert(testJsSize > 0)
assert(testJsMapSize > 0)

val runRes = os.proc("node", "test.js").call(cwd = dir, check = true)
os.proc("node", "test.js").call(cwd = dir, check = true)
}

test("fastLinkJs mode throws") {
Expand All @@ -188,18 +182,7 @@ class Tests extends munit.FunSuite {
|""".stripMargin
)

val scalaJsLibraryCp = os
.proc(
"cs",
"fetch",
"--classpath",
"-E",
"org.scala-lang:scala-library",
s"org.scala-js::scalajs-library:$scalaJsVersion"
)
.call(cwd = dir)
.out
.trim()
val scalaJsLibraryCp = getScalaJsLibraryCp(dir)

os.makeDir.all(dir / "bin")
os.proc(
Expand All @@ -209,7 +192,7 @@ class Tests extends munit.FunSuite {
"--",
"-classpath",
scalaJsLibraryCp,
s"-Xplugin:${os.proc("cs", "fetch", "--intransitive", s"org.scala-js:scalajs-compiler_2.13.6:$scalaJsVersion").call(cwd = dir).out.trim()}",
s"-Xplugin:${getScalaJsCompilerPlugin(dir)}",
"-d",
"bin",
"foo.scala"
Expand Down

0 comments on commit 57c523b

Please sign in to comment.