started working on automated regression tests
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 16 Sep 2020 02:46:25 +0000 (21:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 16 Sep 2020 02:46:25 +0000 (21:46 -0500)
onyx
onyxcmd.js [new file with mode: 0644]
runtests.sh [new file with mode: 0755]
tests/hello_world [new file with mode: 0644]
tests/hello_world.onyx [new file with mode: 0644]

diff --git a/onyx b/onyx
index d5bdd4ef19bdaa92e0604caa5d72edfe47af2228..4e38d8d637a4e465862b3ce199b1f5b860b1366c 100755 (executable)
Binary files a/onyx and b/onyx differ
diff --git a/onyxcmd.js b/onyxcmd.js
new file mode 100644 (file)
index 0000000..3b99f34
--- /dev/null
@@ -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 (executable)
index 0000000..dad6090
--- /dev/null
@@ -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 (file)
index 0000000..8ab686e
--- /dev/null
@@ -0,0 +1 @@
+Hello, World!
diff --git a/tests/hello_world.onyx b/tests/hello_world.onyx
new file mode 100644 (file)
index 0000000..b222ac4
--- /dev/null
@@ -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