-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf5364
commit 437ab8c
Showing
3 changed files
with
65 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ import { strictEqual } from 'node:assert'; | |
const DEBUG_TRACING = false; | ||
const LOG_DEBUGGING = false; | ||
|
||
const enableAot = process.env.WEVAL_TEST == '1'; | ||
const debugBuild = process.env.DEBUG_TEST == '1'; | ||
|
||
function maybeLogging(disableFeatures) { | ||
if (!LOG_DEBUGGING) return disableFeatures; | ||
if (disableFeatures && disableFeatures.includes('stdio')) { | ||
|
@@ -18,16 +21,14 @@ function maybeLogging(disableFeatures) { | |
|
||
const builtinsCases = await readdir(new URL('./builtins', import.meta.url)); | ||
suite('Builtins', () => { | ||
const enableAot = process.env.WEVAL_TEST == '1' | ||
|
||
for (const filename of builtinsCases) { | ||
const name = filename.slice(0, -3); | ||
test(name, async () => { | ||
const { | ||
source, | ||
test: runTest, | ||
disableFeatures, | ||
enableFeatures | ||
enableFeatures, | ||
} = await import(`./builtins/${filename}`); | ||
|
||
const { component } = await componentize( | ||
|
@@ -41,14 +42,18 @@ suite('Builtins', () => { | |
{ | ||
sourceName: `${name}.js`, | ||
// also test the debug build while we are about it (unless testing Weval) | ||
debugBuild: !enableAot, | ||
debugBuild, | ||
enableFeatures, | ||
disableFeatures: maybeLogging(disableFeatures), | ||
enableAot | ||
enableAot, | ||
} | ||
); | ||
|
||
const { files } = await transpile(component, { name, wasiShim: true, tracing: DEBUG_TRACING }); | ||
const { files } = await transpile(component, { | ||
name, | ||
wasiShim: true, | ||
tracing: DEBUG_TRACING, | ||
}); | ||
|
||
await mkdir(new URL(`./output/${name}/interfaces`, import.meta.url), { | ||
recursive: true, | ||
|
@@ -101,23 +106,26 @@ suite('Builtins', () => { | |
code === 0 ? resolve() : reject(new Error(stderr || stdout)) | ||
); | ||
timeout = setTimeout(() => { | ||
reject(new Error("test timed out with output:\n" + stdout + '\n\nstderr:\n' + stderr)); | ||
reject( | ||
new Error( | ||
'test timed out with output:\n' + | ||
stdout + | ||
'\n\nstderr:\n' + | ||
stderr | ||
) | ||
); | ||
}, 10_000); | ||
}); | ||
} | ||
catch (err) { | ||
} catch (err) { | ||
throw { err, stdout, stderr }; | ||
} | ||
finally { | ||
} finally { | ||
clearTimeout(timeout); | ||
} | ||
|
||
return { stdout, stderr }; | ||
}); | ||
} | ||
catch (err) { | ||
if (err.stderr) | ||
console.error(err.stderr); | ||
} catch (err) { | ||
if (err.stderr) console.error(err.stderr); | ||
throw err.err || err; | ||
} | ||
}); | ||
|
@@ -126,16 +134,17 @@ suite('Builtins', () => { | |
|
||
const bindingsCases = await readdir(new URL('./cases', import.meta.url)); | ||
suite('Bindings', () => { | ||
const enableAot = process.env.WEVAL_TEST == '1' | ||
|
||
for (const name of bindingsCases) { | ||
test(name, async () => { | ||
const source = await readFile( | ||
new URL(`./cases/${name}/source.js`, import.meta.url), | ||
'utf8' | ||
); | ||
|
||
let witWorld, witPath, worldName, isWasiTarget = false; | ||
let witWorld, | ||
witPath, | ||
worldName, | ||
isWasiTarget = false; | ||
try { | ||
witWorld = await readFile( | ||
new URL(`./cases/${name}/world.wit`, import.meta.url), | ||
|
@@ -165,7 +174,9 @@ suite('Bindings', () => { | |
const test = await import(`./cases/${name}/test.js`); | ||
|
||
const enableFeatures = test.enableFeatures || ['http']; | ||
const disableFeatures = test.disableFeatures || (isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']); | ||
const disableFeatures = | ||
test.disableFeatures || | ||
(isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']); | ||
|
||
let testArg; | ||
try { | ||
|
@@ -176,7 +187,8 @@ suite('Bindings', () => { | |
worldName, | ||
enableFeatures, | ||
disableFeatures: maybeLogging(disableFeatures), | ||
enableAot | ||
enableAot, | ||
debugBuild, | ||
}); | ||
const map = { | ||
'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*', | ||
|
@@ -191,19 +203,22 @@ suite('Bindings', () => { | |
}; | ||
for (let [impt] of imports) { | ||
if (impt.startsWith('wasi:')) continue; | ||
if (impt.startsWith('[')) | ||
impt = impt.slice(impt.indexOf(']') + 1); | ||
if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1); | ||
let importName = impt.split('/').pop(); | ||
if (importName === 'test') importName = 'imports'; | ||
map[impt] = `../../cases/${name}/${importName}.js`; | ||
} | ||
|
||
const { files, imports: componentImports, exports: componentExports } = await transpile(component, { | ||
const { | ||
files, | ||
imports: componentImports, | ||
exports: componentExports, | ||
} = await transpile(component, { | ||
name, | ||
map, | ||
wasiShim: true, | ||
validLiftingOptimization: false, | ||
tracing: DEBUG_TRACING | ||
tracing: DEBUG_TRACING, | ||
}); | ||
|
||
testArg = { imports, componentImports, componentExports }; | ||
|
@@ -240,8 +255,6 @@ suite('Bindings', () => { | |
|
||
suite('WASI', () => { | ||
test('basic app', async () => { | ||
const enableAot = process.env.WEVAL_TEST == '1' | ||
|
||
const { component } = await componentize( | ||
` | ||
import { now } from 'wasi:clocks/[email protected]'; | ||
|
@@ -259,7 +272,8 @@ suite('WASI', () => { | |
{ | ||
witPath: fileURLToPath(new URL('./wit', import.meta.url)), | ||
worldName: 'test1', | ||
enableAot | ||
enableAot, | ||
debugBuild, | ||
} | ||
); | ||
|
||
|