# $Id: testSPARQL.sh,v 1.4 2013/10/26 20:16:52 eric Exp $ test script using the SWObjects sparql command line interface.
#!/bin/bash

# Each test directory should have (schema.shex validation.rq extra.rq) and:
#   data expected to pass the schema: Turtle file: pass-*.ttl
#   data expected to fail the schema: Turtle file: fail-*.ttl
#   passing data with extra triples: pair of (extra-*.ttl extra-*.srt)
# where the srt file is a textual representation of a SPARQL results set.

BASE=

for dir in Issue-opt-group and-opt;
do
    node shex-SPARQLvalidation.js test/$dir/schema.shex > test/$dir/validation-gen.rq 
    diff test/$dir/validation.rq test/$dir/validation-gen.rq 

# expect true
    for ttl in test/$dir/pass-*.ttl; do sparql -q $BASE -d $ttl $BASE test/$dir/validation.rq || echo FAIL: sparql $BASE -d $ttl test/$dir/validation.rq; done
    for ttl in test/$dir/extra-*.ttl; do sparql -q $BASE -d $ttl $BASE test/$dir/validation.rq || echo FAIL: sparql $BASE -d $ttl test/$dir/validation.rq; done

# expect false
    for ttl in test/$dir/fail-*.ttl; do sparql -q $BASE -d $ttl $BASE test/$dir/validation.rq && echo FAIL: sparql $BASE -d $ttl test/$dir/validation.rq; done

    node shex-SPARQLremainingTriples.js test/$dir/schema.shex > test/$dir/extra-gen.rq 
    diff test/$dir/extra.rq test/$dir/extra-gen.rq
    for ttl in test/$dir/extra-*.ttl; do
        srt=$(echo $ttl | perl -pe "s/ttl/srt/")
        sparql -q $BASE -d $ttl $BASE test/$dir/extra.rq --compare $srt || echo FAIL: sparql $BASE -d $ttl test/$dir/extra.rq --compare $srt; done

done

