11cmake_minimum_required (VERSION 3.20 )
22
3- foreach (_req TEST_NAME WASM_TCC SOURCE_DIR BINARY_DIR)
3+ foreach (_req TEST_NAME WASM_TCC SOURCE_DIR BINARY_DIR NODE_EXECUTABLE )
44 if (NOT DEFINED ${_req} OR "${${_req} }" STREQUAL "" )
55 message (FATAL_ERROR "RunWasmCompileFailTest.cmake: missing required -D${_req} =..." )
66 endif ()
@@ -24,17 +24,27 @@ execute_process(
2424 ERROR_VARIABLE _cc_stderr
2525)
2626
27- if (_cc_rv EQUAL 0)
27+ if (NOT _cc_rv EQUAL 0)
2828 message (FATAL_ERROR
29- "Expected wasm compile to fail for ${TEST_NAME} , but it succeeded.\n "
29+ "Expected wasm compile to succeed for ${TEST_NAME} , but it failed.\n "
30+ "exit code: ${_cc_rv} \n "
3031 "stdout:\n ${_cc_stdout} \n "
3132 "stderr:\n ${_cc_stderr} " )
3233endif ()
3334
34- if (NOT _cc_stderr MATCHES "unresolved direct call" )
35+ execute_process (
36+ COMMAND "${NODE_EXECUTABLE} " -e
37+ "const fs=require('fs');const p=process.argv[1];const m=new WebAssembly.Module(fs.readFileSync(p));const imports=WebAssembly.Module.imports(m);const ok=imports.some(i=>i.kind==='function'&&i.module==='env'&&i.name==='missing');if(!ok){console.error(JSON.stringify(imports));process.exit(2);}"
38+ "${_out_wasm} "
39+ RESULT_VARIABLE _node_rv
40+ OUTPUT_VARIABLE _node_stdout
41+ ERROR_VARIABLE _node_stderr
42+ )
43+
44+ if (NOT _node_rv EQUAL 0)
3545 message (FATAL_ERROR
36- "Expected unresolved direct call diagnostic for ${TEST_NAME} .\n "
37- "exit code: ${_cc_rv } \n "
38- "stdout:\n ${_cc_stdout } \n "
39- "stderr:\n ${_cc_stderr } " )
46+ "Expected wasm import env.missing for ${TEST_NAME} .\n "
47+ "node exit code: ${_node_rv } \n "
48+ "stdout:\n ${_node_stdout } \n "
49+ "stderr:\n ${_node_stderr } " )
4050endif ()
0 commit comments