Skip to content

Commit 9a14183

Browse files
committed
actually fail on test failure
1 parent 9109691 commit 9a14183

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

test/cases/iife.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
function something_long_call() {}
2+
const foo = { bar() {} };
3+
14
(function (q) {
25
console.info('Kuto should extract this long statement', q);
36
something_long_call(123, 'hello there long');

test/index.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@ import * as process from 'node:process';
77
const dir = path.dirname(url.fileURLToPath(new URL(import.meta.url)));
88
process.chdir(dir);
99

10+
const onlyRun = process.argv.slice(2);
11+
1012
// #1: run simple test cases; these just confirm they can compile once, and run
1113

1214
const casesDir = 'cases';
1315
try {
1416
fs.rmSync('dist/', { recursive: true });
15-
} catch { }
17+
} catch {}
1618

1719
let lastSoloFailure: string = '';
1820

21+
const success: string[] = [];
1922
const errors: string[] = [];
20-
const cases = fs.readdirSync(casesDir).filter((x) => x.endsWith('.js')).toSorted();
23+
const cases = fs
24+
.readdirSync(casesDir)
25+
.filter((x) => x.endsWith('.js'))
26+
.toSorted();
2127
for (const caseToRun of cases) {
2228
const { name } = path.parse(caseToRun);
2329

2430
// strip any trailing number: test "foo2" will run after "foo1"
2531
const soloName = name.replace(/\d+$/, '');
32+
if (onlyRun.length && !onlyRun.includes(soloName)) {
33+
continue;
34+
}
35+
2636
try {
2737
if (soloName === lastSoloFailure) {
2838
continue;
@@ -36,6 +46,7 @@ for (const caseToRun of cases) {
3646
const script = path.join('test', casesDir, caseToRun);
3747
await $`npx tsx ./app split ${script} test/dist/${soloName} -n index`;
3848
await $`node test/dist/${soloName}/index.js`;
49+
success.push(caseToRun);
3950
} catch {
4051
errors.push(caseToRun);
4152
lastSoloFailure = soloName;
@@ -44,4 +55,12 @@ for (const caseToRun of cases) {
4455
console.info();
4556
}
4657

47-
console.info(cases.length - errors.length + '/' + cases.length, 'passed');
58+
const total = success.length + errors.length;
59+
if (total === 0) {
60+
console.warn('no tests matched');
61+
process.exit(2); // no test run
62+
}
63+
console.info(success.length + '/' + total, 'passed');
64+
if (errors.length) {
65+
process.exit(1);
66+
}

0 commit comments

Comments
 (0)