This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tanishiking/testsuite
Setup a testing infrastructure
- Loading branch information
Showing
11 changed files
with
219 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cli | ||
|
||
object TestSuites { | ||
case class TestSuite(className: String, methodName: String) | ||
val suites = List( | ||
TestSuite("testsuite.core.simple.Simple", "simple"), | ||
TestSuite("testsuite.core.add.Add", "add") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package testsuite.core.add | ||
|
||
import scala.scalajs.js.annotation._ | ||
|
||
object Add { | ||
def main(): Unit = { val _ = test() } | ||
@JSExportTopLevel("add") | ||
def test(): Boolean = { | ||
1 + 1 == 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package testsuite.core.simple | ||
|
||
import scala.scalajs.js.annotation._ | ||
|
||
object Simple { | ||
def main(): Unit = { val _ = test() } | ||
@JSExportTopLevel("simple") | ||
def test(): Boolean = { | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tests | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation._ | ||
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._ | ||
|
||
class CoreTests extends munit.FunSuite { | ||
cli.TestSuites.suites.map { suite => | ||
test(suite.className) { | ||
val file = s"./target/${suite.className}.wasm" | ||
val wasmBuffer = FS.readFileSync(file) | ||
val wasmModule = | ||
js.Dynamic.global.WebAssembly.instantiate(wasmBuffer).asInstanceOf[js.Promise[js.Dynamic]] | ||
wasmModule.toFuture.map { module => | ||
val testFunction = | ||
module.instance.exports | ||
.selectDynamic(suite.methodName) | ||
.asInstanceOf[js.Function0[Int]] | ||
assert(testFunction() == 1) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private object FS { | ||
@js.native @JSImport("fs") | ||
def readFileSync(file: String): js.typedarray.Uint8Array = js.native | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.