2020-08-22 17:33:08 +02:00
|
|
|
export default class T {
|
2021-05-14 02:25:30 +02:00
|
|
|
|
2021-06-08 16:52:31 +02:00
|
|
|
public readonly failures : string[] = []
|
|
|
|
public readonly name : string;
|
2021-05-14 02:25:30 +02:00
|
|
|
|
|
|
|
constructor(testsuite: string, tests: [string, () => void][]) {
|
2021-06-08 16:52:31 +02:00
|
|
|
this.name = testsuite
|
2020-08-22 17:33:08 +02:00
|
|
|
for (const [name, test] of tests) {
|
|
|
|
try {
|
|
|
|
test();
|
|
|
|
} catch (e) {
|
2021-05-14 02:25:30 +02:00
|
|
|
this.failures.push(name);
|
2021-07-08 10:11:46 +02:00
|
|
|
console.warn(`>>> Failed test in ${this.name}: ${name}because${e}`);
|
2020-08-22 17:33:08 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-14 02:25:30 +02:00
|
|
|
if (this.failures.length == 0) {
|
2021-02-20 01:45:51 +01:00
|
|
|
console.log(`All tests of ${testsuite} done!`)
|
2020-08-22 17:33:08 +02:00
|
|
|
} else {
|
2021-05-14 02:25:30 +02:00
|
|
|
console.warn(this.failures.length, `tests of ${testsuite} failed :(`)
|
|
|
|
console.log("Failed tests: ", this.failures.join(","))
|
2020-08-22 17:33:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 02:25:30 +02:00
|
|
|
static assertContains(needle: string, actual: string) {
|
|
|
|
if (actual.indexOf(needle) < 0) {
|
2021-02-20 01:45:51 +01:00
|
|
|
throw `The substring ${needle} was not found`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 13:59:49 +02:00
|
|
|
static isTrue(b: boolean, msg: string) {
|
2021-05-14 02:25:30 +02:00
|
|
|
if (!b) {
|
|
|
|
throw "Expected true, but got false: " + msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static isFalse(b: boolean, msg: string) {
|
|
|
|
if (b) {
|
|
|
|
throw "Expected false, but got true: " + msg
|
2021-04-09 13:59:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-22 17:33:08 +02:00
|
|
|
}
|