From: Brendan Hansen Date: Wed, 16 Sep 2020 02:46:25 +0000 (-0500) Subject: started working on automated regression tests X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=38a2cdbcc2abbaa7119c089f2150fe6837144d11;p=onyx.git started working on automated regression tests --- diff --git a/onyx b/onyx index d5bdd4ef..4e38d8d6 100755 Binary files a/onyx and b/onyx differ diff --git a/onyxcmd.js b/onyxcmd.js new file mode 100644 index 00000000..3b99f343 --- /dev/null +++ b/onyxcmd.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const buf = fs.readFileSync(process.argv[2]); + +let wasm_memory; + +const ENV = { + host: { + print_str(ptr, len) { + const data = new Uint8Array(wasm_memory, ptr, len); + const str = new TextDecoder().decode(data); + console.log(str); + } + } +} + +WebAssembly.instantiate(new Uint8Array(buf), ENV) + .then(res => { + const lib = res.instance.exports; + wasm_memory = lib.memory.buffer; + + lib._start(); + }); + diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 00000000..dad60902 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +success=1 +for test_file in ./tests/*.onyx ; do + filename=$(basename -- "$test_file") + name="${filename%.*}" + + echo "⏲ Checking $name.onyx" + + if ! ./onyx "$test_file" -o "./tests/$name.wasm" >/dev/null; then + echo "❌ Failed to compile $name.onyx." + success=0 + continue + fi + + if ! node onyxcmd.js "./tests/$name.wasm" > ./tmpoutput; then + echo "❌ Failed to run $name.onyx." + success=0 + continue + fi + + if ! diff ./tmpoutput "./tests/$name" >/dev/null; then + echo "❌ Test output did not match." + success=0 + continue + fi +done +rm ./tmpoutput + +([ $success = 1 ] && echo "✔ All tests passed.") \ + || echo "❌ Some tests failed." diff --git a/tests/hello_world b/tests/hello_world new file mode 100644 index 00000000..8ab686ea --- /dev/null +++ b/tests/hello_world @@ -0,0 +1 @@ +Hello, World! diff --git a/tests/hello_world.onyx b/tests/hello_world.onyx new file mode 100644 index 00000000..b222ac43 --- /dev/null +++ b/tests/hello_world.onyx @@ -0,0 +1,9 @@ +package main + +#include_file "core/std/js" + +use package core + +main :: proc (args: [] cstring) { + print("Hello, World!"); +} \ No newline at end of file