Skip to content

Commit

Permalink
Allow tests to be skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Feb 7, 2019
1 parent 770f249 commit 9ae22af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from "./lib/IManifest";
export * from "./lib/ManifestLoader";
export * from "./lib/TestSuiteRunner";
export * from "./lib/Util";
export * from "./lib/ErrorSkipped";
12 changes: 12 additions & 0 deletions lib/ErrorSkipped.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* An error to indicate if a test should be skipped.
*/
export class ErrorSkipped extends Error {

public readonly skipped: boolean = true;

constructor(message: string) {
super(message);
}

}
22 changes: 16 additions & 6 deletions lib/TestSuiteRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class TestSuiteRunner {
try {
await test.test(handler, injectArguments);
} catch (error) {
results.push({ test, ok: false, error });
results.push({ test, ok: false, error, skipped: error.skipped });
continue;
}
results.push({ test, ok: true });
Expand All @@ -88,13 +88,19 @@ export class TestSuiteRunner {
public resultsToText(stdout: WriteStream, results: ITestResult[], compact: boolean) {
const failedTests: ITestResult[] = [];
let success: number = 0;
let skipped: number = 0;
for (const result of results) {
if (result.ok) {
success++;
stdout.write(`${LogSymbols.success} ${result.test.name} (${result.test.uri})\n`);
} else {
failedTests.push(result);
stdout.write(`${LogSymbols.error} ${result.test.name} (${result.test.uri})\n`);
if (result.skipped) {
skipped++;
stdout.write(`${LogSymbols.info} ${result.test.name} (${result.test.uri})\n`);
} else {
failedTests.push(result);
stdout.write(`${LogSymbols.error} ${result.test.name} (${result.test.uri})\n`);
}
}
}

Expand All @@ -110,10 +116,12 @@ ${LogSymbols.error} ${result.test.name}
}
}

const skippedString = skipped ? ` (skipped ${skipped})` : '';
success += skipped;
if (success === results.length) {
stdout.write(`${LogSymbols.success} ${success} / ${results.length} tests succeeded!\n`);
stdout.write(`${LogSymbols.success} ${success} / ${results.length} tests succeeded!${skippedString}\n`);
} else {
stdout.write(`${LogSymbols.error} ${success} / ${results.length} tests succeeded!\n`);
stdout.write(`${LogSymbols.error} ${success} / ${results.length} tests succeeded!${skippedString}\n`);
}
}

Expand Down Expand Up @@ -203,7 +211,8 @@ ${LogSymbols.error} ${result.test.name}
quads.push(quad('_:assertion' + id, p.earl + 'mode', p.earl + 'automatic'));
quads.push(quad('_:assertion' + id, p.earl + 'result', '_:result' + id));
quads.push(quad('_:result' + id, p.rdf + 'type', p.earl + 'TestResult'));
quads.push(quad('_:result' + id, p.earl + 'outcome', p.earl + (result.ok ? 'passed' : 'failed')));
quads.push(quad('_:result' + id, p.earl + 'outcome',
p.earl + (result.ok ? 'passed' : result.skipped ? 'inapplicable' : 'failed')));
quads.push(quad('_:result' + id, p.dc + 'date', date));
id++;
}
Expand Down Expand Up @@ -263,4 +272,5 @@ export interface ITestResult {
test: ITestCase<any>;
ok: boolean;
error?: Error;
skipped?: boolean;
}
4 changes: 4 additions & 0 deletions lib/testcase/rdfsyntax/TestCaseSyntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class TestCaseSyntax implements ITestCaseRdfSyntax {
try {
await parser.parse(this.data, this.baseIRI, injectArguments);
} catch (e) {
if (e.skipped) {
throw e;
}

if (this.expectNoError) {
throw new Error(`Expected not throw an error when parsing.
Input: ${this.data}
Expand Down

0 comments on commit 9ae22af

Please sign in to comment.