Skip to content

Commit

Permalink
Add EARL Turtle test result mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlehn committed Sep 18, 2023
1 parent bf241de commit 8bee49c
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
is recommeded to use this paramter instead of `maxDeepIterations` directly.
- **BREAKING**: Check output `format` parameter. Must be omitted, falsey, or
"application/n-quads".
- Add EARL Turtle test result mode.

### Changed
- **BREAKING**: Change algorithm name from "URDNA2015" to "RDFC-1.0" to match
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,27 @@ directory you can use the following:

npm run fetch-test-suite

Node.js tests can be run with a simple command:
Node.js tests:

npm test

Browser tests via Karma:

npm run test-karma

If you installed the test suites elsewhere, or wish to run other tests, use
the `TEST_DIR` environment var:

TEST_DIR="/tmp/tests" npm test

To generate earl reports:
To generate EARL reports:

# generate the earl report for node.js
# generate a JSON-LD EARL report with Node.js
EARL=earl-node.jsonld npm test

Browser testing with karma is done indirectly through [jsonld.js][].
# generate a Turtle EARL report with Node.js
# used for official reports
EARL=js-rdf-canonize-earl.ttl npm test

Benchmark
---------
Expand Down
80 changes: 75 additions & 5 deletions test/EarlReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class EarlReport {
this.now = new Date();
this.now.setMilliseconds(0);
this.env = options.env;
this.format = options.format;
this.version = options.version;
// test environment
this._environment = null;
/* eslint-disable quote-props */
Expand Down Expand Up @@ -104,7 +106,8 @@ class EarlReport {
'doap:homepage': 'https://github.com/digitalbazaar/rdf-canonize',
'doap:license':
'https://github.com/digitalbazaar/rdf-canonize/blob/master/LICENSE',
'doap:description': 'A JSON-LD processor for JavaScript',
'doap:description':
'A RDF Dataset Canonicalization processor for JavaScript',
'doap:programming-language': 'JavaScript',
'dc:creator': 'https://digitalbazaar.com/',
'doap:developer': {
Expand All @@ -117,7 +120,7 @@ class EarlReport {
'foaf:homepage': 'https://digitalbazaar.com/'
},
'doap:release': {
'doap:revision': '',
'doap:revision': `${this.version}`,
'doap:created': today
},
'subjectOf': []
Expand Down Expand Up @@ -154,11 +157,78 @@ class EarlReport {
}

report() {
return this._report;
if(this.format === 'json') {
return JSON.stringify(this._report, null, 2);
} else if(this.format === 'ttl') {
return this.asTurtle(this._report);
} else {
throw new Error(`Unknown report format: "${this.format}".`);
}
}

reportJson() {
return JSON.stringify(this._report, null, 2);
asTurtle() {
console.log(this._report);
console.log(this._report.subjectOf[0]);
const r = this._report;
let report = '';
// add prefixes
report += `\
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix earl: <http://www.w3.org/ns/earl#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
`;

// add test subject
report += `\
<> foaf:primaryTopic <${r['@id']}> ;
dc:issued "${r['doap:release']['doap:created']}"^^xsd:dateTime ;
foaf:maker <${r['doap:developer']['@id']}> .
<${r['@id']}> a doap:Project, earl:TestSubject, earl:Software ;
doap:name "${r['doap:name']}" ;
doap:release [
doap:name "${r['doap:name']}@${r['doap:release']['doap:revision']}";
doap:revision "${r['doap:release']['doap:revision']}" ;
doap:created "${r['doap:release']['doap:created']}" ;
] ;
doap:developer <${r['doap:developer']['@id']}> ;
doap:homepage <${r['doap:homepage']}> ;
doap:description "${r['doap:description']}"@en ;
doap:programming-language "${r['doap:programming-language']}" .
`;

// add software developer
report += `\
<${r['doap:developer']['@id']}> a foaf:Organization, earl:Assertor;
foaf:name "${r['doap:developer']['foaf:name']}";
foaf:homepage <${r['doap:developer']['foaf:homepage']}>;
`;

// add assertions
for(const a of r.subjectOf) {
report += `\
[ a earl:Assertion;
earl:assertedBy <${r['doap:developer']['@id']}>;
earl:subject <${r['@id']}>;
earl:test <https://w3c.github.io/rdf-canon/tests/${a['earl:test']}>;
earl:result [
a earl:TestResult;
earl:outcome ${a['earl:result']['earl:outcome']};
dc:date "${a['earl:result']['dc:date']}"^^xsd:dateTime];
earl:mode ${a['earl:mode']} ] .
`;
}

return report;
}

// setup @context and environment to handle benchmark data
Expand Down
10 changes: 7 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Set dirs, manifests, or js to run:
* TESTS="r1 r2 ..."
* Output an EARL report:
* EARL=filename
* EARL=filename (default: none)
* JSON or Turtle type determined by extension.
* Test environment details for EARL report:
* This is useful for benchmark comparison.
* By default no details are added for privacy reasons.
Expand Down Expand Up @@ -235,7 +236,10 @@ if(options.env.TEST_ENV) {
// create earl report
if(options.earl && options.earl.filename) {
options.earl.report = new EarlReport({
env: testEnv
env: testEnv,
format: options.earl.filename.endsWith('.ttl') ? 'ttl' : 'json',
// FIXME: enable easier override
version: options.testEnvDefaults.version
});
if(benchmarkOptions.enabled) {
options.earl.report.setupForBenchmarks({testEnv});
Expand All @@ -259,7 +263,7 @@ if(options.earl.report) {
const _it = result.hadOnly ? it.only : it;
_it('should print the earl report', function() {
return options.writeFile(
options.earl.filename, options.earl.report.reportJson());
options.earl.filename, options.earl.report.report());
});
});
}
Expand Down

0 comments on commit 8bee49c

Please sign in to comment.