From 6c08ebe9b6d06195322ac250b2d7eca8c5aeb5b4 Mon Sep 17 00:00:00 2001
From: Joao Matos <joao@tritao.eu>
Date: Sat, 4 Feb 2023 23:16:00 +0000
Subject: [PATCH] Refactor non working JS tests with feature-based checks.

---
 tests/emscripten/test.mjs | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/tests/emscripten/test.mjs b/tests/emscripten/test.mjs
index 95b8b0bf..6e2f13c0 100644
--- a/tests/emscripten/test.mjs
+++ b/tests/emscripten/test.mjs
@@ -7,14 +7,23 @@ const test = await wasmModule({
     }
 });
 
+const features = {
+    // https://github.com/WebAssembly/proposals/issues/7
+    // https://github.com/emscripten-core/emscripten/issues/11140
+    supportsInt64: false,
+    supportsNull: false,
+}
+
 function builtins() {
     eq(test.ReturnsVoid(), undefined)
 
     eq(test.ReturnsBool(), true)
     eq(test.PassAndReturnsBool(false), false)
 
-    eq(test.ReturnsNullptr(), null)
-    eq(test.PassAndReturnsNullptr(null), null)
+    if (features.supportsNull) {
+        eq(test.ReturnsNullptr(), null)
+        eq(test.PassAndReturnsNullptr(null), null)
+    }
 
     eq(test.ReturnsChar(), ascii('a'));
     eq(test.ReturnsSChar(), ascii('a'));
@@ -41,11 +50,10 @@ function builtins() {
     eq(test.ReturnsInt32(), -5);
     eq(test.ReturnsUInt32(), 5);
 
-    // TODO: 
-    // https://github.com/WebAssembly/proposals/issues/7
-    // https://github.com/emscripten-core/emscripten/issues/11140
-    //eq(test.ReturnsInt64(), -5n);
-    //eq(test.ReturnsUInt64(), 5n);
+    if (features.supportsInt64) {
+        eq(test.ReturnsInt64(), -5n);
+        eq(test.ReturnsUInt64(), 5n);
+    }
 
     const int8 = { min: -(2 ** 7), max: (2 ** 7) - 1 };
     eq(test.PassAndReturnsInt8(int8.min), int8.min);
@@ -71,13 +79,15 @@ function builtins() {
     eq(test.PassAndReturnsUInt32(uint32.min), uint32.min);
     eq(test.PassAndReturnsUInt32(uint32.max), uint32.max);
 
-    //const int64 = { min: BigInt(2 ** 63) * -1n, max: BigInt(2 ** 63) - 1n };
-    //eq(test.PassAndReturnsInt64(int64.min), int64.min);
-    //eq(test.PassAndReturnsInt64(int64.max), int64.max);
+    if (features.supportsInt64) {
+        const int64 = { min: BigInt(2 ** 63) * -1n, max: BigInt(2 ** 63) - 1n };
+        eq(test.PassAndReturnsInt64(int64.min), int64.min);
+        eq(test.PassAndReturnsInt64(int64.max), int64.max)
 
-    //const uint64 = { min: BigInt(0), max: BigInt(2 ** 64) - 1n };
-    //eq(test.PassAndReturnsUInt64(uint64.min), uint64.min);
-    //eq(test.PassAndReturnsUInt64(uint64.max), uint64.max);
+        const uint64 = { min: BigInt(0), max: BigInt(2 ** 64) - 1n };
+        eq(test.PassAndReturnsUInt64(uint64.min), uint64.min);
+        eq(test.PassAndReturnsUInt64(uint64.max), uint64.max);
+    }
 }
 
 function enums() {