The ShEx Test extension is a very simple extension intended for testing ShEx extension frameworks. Test participates in validate and has side-effects.


The Test extension has two functions:

Take a sample input schema with ShEx Test directives and input data:

PREFIX ex: <http://ex.example/#>
PREFIX foaf: <>
PREFIX xsd: <>
PREFIX test: <>

%test:{  %}

start = <IssueShape>

<IssueShape> {
    ex:reportedBy @<UserShape>
        %test:{ fail("some message") %},

<UserShape> {
    foaf:name xsd:string
        %test:{ print(o) %}
PREFIX ex: <http://ex.example/#>
PREFIX foaf: <>

<Issue1> ex:reportedBy <User2> .
<User2> foaf:name "Bob" .

In the ShEx Demo we see a failure:

<Issue1> matches <IssueShape>:
PASS { ex:reportedBy @<UserShape> %<>{ fail("some message") %} matched by <Issue1> ex:reportedBy <User2> . PASS { Errors: ☹ eval of {"some message"} rejected [[ <> <> %<>{ print(o) %} matched by <User2> <> "Bob". ]] Matches: foaf:name xsd:string %<>{ print(o) %} matched by <User2> foaf:name "Bob" . } }No remaining triples.

Examining the output (look for or link in validation messages) we see:

  "prints": [


Test has a defined behavior when attached to a triple constraint. Other behaviors of Test are unspecified. There are two function in the Test extension:

Each takes an argument, which is one of these four particles:


Test directives can be parsed with the regular expression /^ *(fail|print) *\( *(?:(\"(?:[^\\"]|\\")*\")|([spo])) *\) *$/. The first capture group will be either "fail" or "print". The second will capture quoted strings, including their quotation marks. The third will captures the particles "s", "p", "o". For any valid Test string, the first capture group and either the second or the third will be matched.


edited by: Eric Prud'hommeaux