-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
47 lines (35 loc) · 1.44 KB
/
test.js
File metadata and controls
47 lines (35 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { nodeAdapter as adapter } from './adapters/nodeAdapter.js';
import { Mimo } from './index.js';
async function runTest() {
const testName = process.argv[2] || 'all';
const filePath = findTestFile(testName);
if (!filePath) {
console.error(`Error: Test file "${testName}" not found.`);
return;
}
console.log(`\n=== Running Test: ${path.basename(filePath)} ===\n`);
const source = fs.readFileSync(filePath, 'utf-8');
const mimo = new Mimo(adapter);
try {
mimo.run(source, filePath);
console.log(`\n=== Test Passed: ${path.basename(filePath)} ===\n`);
} catch (err) {
console.error(err.message || err); // Show error even if it's a string
console.error(`\n=== Test FAILED: ${path.basename(filePath)} ===\n`);
process.exit(1);
}
}
function findTestFile(fileName) {
const directPath = path.resolve(process.cwd(), fileName);
if (fs.existsSync(directPath)) return directPath;
const withExt = directPath.endsWith('.mimo') ? '' : '.mimo';
if (fs.existsSync(`${directPath}${withExt}`)) return `${directPath}${withExt}`;
const testSourcePath = path.resolve(process.cwd(), 'test/source', fileName);
if (fs.existsSync(testSourcePath)) return testSourcePath;
if (fs.existsSync(`${testSourcePath}.mimo`)) return `${testSourcePath}.mimo`;
return null;
}
runTest();