[snap] Blow up if testfilter is not found in filter mode
No more failing silently when testfilter file is not found.
Sathya Gunasekaran committed
Jul 5, 2023 at 18:53 UTC
d10885ae0e7a33b198299d32b881a1bc96fb967f
1 file changed
+7
-9
compiler/forget/packages/snap/src/runner.ts
+7
-9
@@ -406,13 +406,11 @@ type TestFilter =
406
};
407
408
async function readTestFilter(): Promise<TestFilter | null> {
409
- const input = (await exists(FILTER_PATH))
410
- ? await fs.readFile(FILTER_PATH, "utf8")
411
- : null;
412
- if (input === null) {
413
- return null;
409
+ if (!(await exists(FILTER_PATH))) {
410
+ throw new Error(`testfilter file not found at ${FILTER_PATH}`);
411
}
412
413
+ const input = await fs.readFile(FILTER_PATH, "utf8");
414
const lines = input.trim().split("\n");
415
if (lines.length < 2) {
416
console.warn("Misformed filter file. Expected at least two lines.");
@@ -461,7 +459,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
459
let isCompilerValid = false;
460
let lastUpdate = -1;
461
let filterMode: boolean = false;
464
- let testFilter: TestFilter | null = await readTestFilter();
462
+ let testFilter: TestFilter | null;
463
464
function isRealUpdate(): boolean {
465
// Try to ignore changes that occurred as a result of our explicitly updating
@@ -487,7 +485,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
485
const results = await run(
486
worker,
487
opts,
490
- filterMode ? testFilter : null,
488
+ filterMode ? await readTestFilter() : null,
489
compilerVersion
490
);
491
if (mode === Mode.Update) {
@@ -508,7 +506,7 @@ export async function main(opts: RunnerOptions): Promise<void> {
506
console.log(
507
"\n" +
508
(filterMode
511
- ? `Current mode = FILTER, filter test fixtures by "${FILTER_FILENAME}".`
509
+ ? `Current mode = FILTER, filter test fixtures by "${FILTER_PATH}".`
510
: "Current mode = NORMAL, run all test fixtures.") +
511
"\nWaiting for input or file changes...\n" +
512
"u - update all fixtures\n" +
@@ -567,8 +565,8 @@ export async function main(opts: RunnerOptions): Promise<void> {
565
events.findIndex((event) => event.path.includes(FILTER_FILENAME)) !==
566
-1
567
) {
570
- testFilter = await readTestFilter();
568
if (filterMode) {
569
+ testFilter = await readTestFilter();
570
onChange({ mode: Mode.Test });
571
}
572
}