Skip to content

Commit c48ebe3

Browse files
committed
Move PASS, FAIL to suite.js
1 parent e9578d4 commit c48ebe3

File tree

4 files changed

+19
-40
lines changed

4 files changed

+19
-40
lines changed

test/ebnf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import color from "cli-color";
33
import difflib from "difflib";
44
import ebnf from "../lib/ebnf.js";
5-
import {PASS, FAIL} from "./util.js";
5+
import {PASS, FAIL} from "./suite.js";
66

77
let args = process.argv.slice(2);
88

test/parser.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import assert from "assert";
22
import path from "path";
33
import fs from "fs";
4-
import {diffString} from "json-diff";
54
import {Resource} from "../syntax/grammar.js";
6-
import {PASS, FAIL} from "./util.js";
5+
import {print_generic_error, print_assert_error, exit_summary, PASS, FAIL}
6+
from "./suite.js";
77

88
const bail = process.argv[2] === "--bail";
99
const fixtures_dir = process.argv[bail ? 3 : 2];
@@ -78,32 +78,3 @@ function validate(actual_ast, expected_serialized) {
7878
const expected_json = JSON.parse(expected_serialized);
7979
assert.deepEqual(actual_json, expected_json);
8080
}
81-
82-
function print_assert_error(ftl_path, err) {
83-
console.log(`
84-
========================================================================
85-
${FAIL} ${ftl_path}
86-
------------------------------------------------------------------------
87-
${diffString(err.expected, err.actual)}
88-
`);
89-
}
90-
91-
function print_generic_error(ftl_path, err) {
92-
console.log(`
93-
========================================================================
94-
${FAIL} ${ftl_path}
95-
------------------------------------------------------------------------
96-
${err.message}
97-
`);
98-
}
99-
100-
function exit_summary(error_count) {
101-
const message = error_count
102-
? `Tests ${FAIL}: ${error_count}.`
103-
: `All tests ${PASS}.`;
104-
console.log(`
105-
========================================================================
106-
${message}
107-
`);
108-
process.exit(Number(error_count > 0));
109-
}

test/suite.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import assert from "assert";
22
import {diffString} from "json-diff";
3-
import {PASS, FAIL} from "./util.js";
3+
import color from "cli-color";
44

5-
export default
6-
function suite(fn) {
5+
export const PASS = color.green("PASS");
6+
export const FAIL = color.red("FAIL");
7+
8+
export default function suite(fn) {
79
let errors = new Map();
810
fn(create_tester(errors));
911

@@ -35,7 +37,16 @@ function create_tester(errors) {
3537
};
3638
}
3739

38-
function print_assert_error(title, err) {
40+
export function print_generic_error(ftl_path, err) {
41+
console.log(`
42+
========================================================================
43+
${FAIL} ${ftl_path}
44+
------------------------------------------------------------------------
45+
${err.message}
46+
`);
47+
}
48+
49+
export function print_assert_error(title, err) {
3950
console.log(`
4051
========================================================================
4152
${FAIL} ${title}
@@ -44,7 +55,7 @@ ${diffString(err.expected, err.actual)}
4455
`);
4556
}
4657

47-
function exit_summary(error_count) {
58+
export function exit_summary(error_count) {
4859
const message = error_count
4960
? `Tests ${FAIL}: ${error_count}.`
5061
: `All tests ${PASS}.`;

test/util.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)