Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Mar 15, 2022
1 parent d0ad8ef commit 22f99af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

if (TestUtil.canRunJs) {
test("simple script JS") {
simpleJsTest()
}
test("simple script JS in release mode") {
simpleJsTest("--js-mode", "release")
}
test("simple script JS") {
simpleJsTest()
}
test("simple script JS in release mode") {
simpleJsTest("--js-mode", "release")
}

def simpleJsViaConfigFileTest(): Unit = {
test("simple script JS via config file") {
val message = "Hello"
val inputs = TestInputs(
Seq(
Expand All @@ -97,11 +95,6 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

if (TestUtil.canRunJs)
test("simple script JS via config file") {
simpleJsViaConfigFileTest()
}

def platformNl = if (Properties.isWin) "\\r\\n" else "\\n"

def canRunScWithNative(): Boolean =
Expand Down Expand Up @@ -248,7 +241,7 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

def multipleScriptsJs(): Unit = {
test("Multiple scripts JS") {
val message = "Hello"
val inputs = TestInputs(
Seq(
Expand All @@ -270,11 +263,6 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

if (TestUtil.canRunJs)
test("Multiple scripts JS") {
multipleScriptsJs()
}

def multipleScriptsNative(): Unit = {
val message = "Hello"
val inputs = TestInputs(
Expand Down Expand Up @@ -389,7 +377,7 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
passArgumentsScala3()
}

def directoryJs(): Unit = {
test("Directory JS") {
val message = "Hello"
val inputs = TestInputs(
Seq(
Expand All @@ -411,11 +399,6 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
}
}

if (TestUtil.canRunJs)
test("Directory JS") {
directoryJs()
}

def directoryNative(): Unit = {
val message = "Hello"
val inputs = TestInputs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,14 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
}
}

def successfulJsTest(): Unit =
test("successful test JS") {
successfulTestInputs.fromRoot { root =>
val output = os.proc(TestUtil.cli, "test", extraOptions, ".", "--js")
.call(cwd = root)
.out.text()
expect(output.contains("Hello from tests"))
}

if (TestUtil.canRunJs)
test("successful test JS") {
successfulJsTest()
}
}

def successfulNativeTest(): Unit =
successfulTestInputs.fromRoot { root =>
Expand All @@ -212,18 +208,14 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
}
}

def failingJsTest(): Unit =
test("failing test JS") {
failingTestInputs.fromRoot { root =>
val output = os.proc(TestUtil.cli, "test", extraOptions, ".", "--js")
.call(cwd = root, check = false)
.out.text()
expect(output.contains("Hello from tests"))
}

if (TestUtil.canRunJs)
test("failing test JS") {
failingJsTest()
}
}

def failingNativeTest(): Unit =
failingTestInputs.fromRoot { root =>
Expand Down Expand Up @@ -257,18 +249,14 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
}
}

def utestJs(): Unit =
test("utest JS") {
successfulUtestJsInputs.fromRoot { root =>
val output = os.proc(TestUtil.cli, "test", extraOptions, ".", "--js")
.call(cwd = root)
.out.text()
expect(output.contains("Hello from tests"))
}

if (TestUtil.canRunJs)
test("utest JS") {
utestJs()
}
}

def utestNative(): Unit =
successfulUtestNativeInputs.fromRoot { root =>
Expand Down Expand Up @@ -314,7 +302,7 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
}

val platforms = {
val maybeJs = if (TestUtil.canRunJs) Seq("JS" -> Seq("--js")) else Nil
val maybeJs = Seq("JS" -> Seq("--js"))
val maybeNative =
if (actualScalaVersion.startsWith("2."))
Seq("Native" -> Seq("--native"))
Expand Down Expand Up @@ -453,9 +441,7 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
test("Cross-tests") {
val supportsNative = actualScalaVersion.startsWith("2.")
val platforms = {
var pf = Seq("\"jvm\"")
if (TestUtil.canRunJs)
pf = pf :+ "\"js\""
var pf = Seq("\"jvm\"", "\"js\"")
if (supportsNative)
pf = pf :+ "\"native\""
pf.mkString(", ")
Expand All @@ -481,11 +467,7 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
| println("Hello from " + "jvm")
| }
|}
|""".stripMargin
)
)
if (TestUtil.canRunJs)
inputs0 = inputs0.add(
|""".stripMargin,
os.rel / "MyJsTests.scala" ->
"""//> using target.platform "js"
|
Expand All @@ -496,6 +478,7 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
|}
|""".stripMargin
)
)
if (supportsNative)
inputs0 = inputs0.add(
os.rel / "MyNativeTests.scala" ->
Expand All @@ -513,11 +496,10 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
inputs.fromRoot { root =>
val res = os.proc(TestUtil.cli, "test", extraOptions, ".", "--cross").call(cwd = root)
val output = res.out.text()
val expectedCount = 1 + (if (TestUtil.canRunJs) 1 else 0) + (if (supportsNative) 1 else 0)
val expectedCount = 2 + (if (supportsNative) 1 else 0)
expect(countSubStrings(output, "Hello from shared") == expectedCount)
expect(output.contains("Hello from jvm"))
if (TestUtil.canRunJs)
expect(output.contains("Hello from js"))
expect(output.contains("Hello from js"))
if (supportsNative)
expect(output.contains("Hello from native"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ object TestUtil {
)
// format: on

lazy val canRunJs = true

def fromPath(app: String): Option[String] = {

val pathExt =
Expand Down

0 comments on commit 22f99af

Please sign in to comment.