@zazuko/shacl-test 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.github/workflows/release.yaml +42 -0
- package/CHANGELOG.md +11 -0
- package/README.md +45 -0
- package/load-graph.js +11 -0
- package/package.json +32 -0
- package/pretty-print.js +29 -0
- package/report-failure.sh +18 -0
- package/run.sh +119 -0
- package/shorten-report.js +8 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": false,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "master",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
release:
|
|
12
|
+
name: Release
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: write
|
|
17
|
+
pull-requests: write
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout Repo
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
with:
|
|
23
|
+
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
24
|
+
fetch-depth: 0
|
|
25
|
+
|
|
26
|
+
- name: Setup Node.js
|
|
27
|
+
uses: actions/setup-node@v4
|
|
28
|
+
with:
|
|
29
|
+
node-version: "lts/*"
|
|
30
|
+
|
|
31
|
+
- name: Install Dependencies
|
|
32
|
+
run: npm ci
|
|
33
|
+
|
|
34
|
+
- name: Create Release Pull Request or Publish to npm
|
|
35
|
+
id: changesets
|
|
36
|
+
uses: changesets/action@v1
|
|
37
|
+
with:
|
|
38
|
+
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
|
39
|
+
publish: yarn release
|
|
40
|
+
env:
|
|
41
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
42
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# SHACL-test
|
|
2
|
+
|
|
3
|
+
Runs SHACL shapes against a set of positive and negative test cases (data graphs).
|
|
4
|
+
|
|
5
|
+
Positive test cases are a simple fail/pass.
|
|
6
|
+
Negative test cases are expected to fail and the validation report is compared against the
|
|
7
|
+
expectation using [approvals](https://npm.im/approvals).
|
|
8
|
+
|
|
9
|
+
In case of failures, a [SHACL Playground](https://shacl-playground.zazuko.com)
|
|
10
|
+
link is provided for further investigation.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npx shacl-test \
|
|
16
|
+
--shapes=${SHAPES} \
|
|
17
|
+
--valid-cases="${VALID_CASES_GLOB}" \
|
|
18
|
+
--invalid-cases="${INVALID_CASES_GLOB}" \
|
|
19
|
+
--filter="${FILTER}" \
|
|
20
|
+
--approve \
|
|
21
|
+
--debug \
|
|
22
|
+
--prefixes=${PREFIXES} \
|
|
23
|
+
--command="${COMMAND}"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Only the `--shapes` option is required. The rest are optional.
|
|
27
|
+
|
|
28
|
+
`--shapes` can be a filesystem path or URL and include [`code:imports`](https://github.com/zazuko/rdf-transform-graph-imports).
|
|
29
|
+
|
|
30
|
+
`--valid-cases` and `--invalid-cases` are globs that match the test cases.
|
|
31
|
+
Make sure to put them in quotes to avoid shell expansion.
|
|
32
|
+
|
|
33
|
+
`--filter` is a regular expression to filter the test cases.
|
|
34
|
+
|
|
35
|
+
`--approve` will approve the validation reports for the negative test cases instead of failing.
|
|
36
|
+
|
|
37
|
+
`--debug` will print the validation report for each test case.
|
|
38
|
+
|
|
39
|
+
`--prefixes` is a comma-separated list of prefix declarations to be used in the SHACL shapes.
|
|
40
|
+
For example, `--prefixes=schema,qudt,cube=https://cube.link/`, will declare the prefixes
|
|
41
|
+
`schema`, `qudt` and `cube` with the respective URIs. In the case of `schema` and `qudt`, their
|
|
42
|
+
URIs are taken from the list provided by the [`@zazuko/prefixes`](https://github.com/zazuko/rdf-vocabularies/blob/master/packages/prefixes/prefixes.ts) package (and, by extension, the [Zazuko prefix server](https://prefix.zazuko.com)).
|
|
43
|
+
|
|
44
|
+
`--command` is a command to run for each test case. It will be passed the shapes path as argument and the test case on standard input. The default is `npx barnard59 shacl validate --shapes`, which translates to `npx barnard59 shacl validate --shapes ${shapes} < $testCase`. The script must return a non-zero exit code if the test case is invalid.
|
|
45
|
+
|
package/load-graph.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import env from '@zazuko/env-node'
|
|
4
|
+
import importGraphs from 'rdf-transform-graph-imports'
|
|
5
|
+
import open from 'barnard59-rdf/open.js'
|
|
6
|
+
|
|
7
|
+
(async () => {
|
|
8
|
+
const quadStream = await open.call({ env }, process.argv[2])
|
|
9
|
+
|
|
10
|
+
env.formats.serializers.import('text/turtle', quadStream.pipe(importGraphs(env))).pipe(process.stdout)
|
|
11
|
+
})()
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zazuko/shacl-test",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"shacl-test": "./run.sh"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"release": "changeset publish"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"SHACL",
|
|
13
|
+
"test",
|
|
14
|
+
"rdf",
|
|
15
|
+
"approvals"
|
|
16
|
+
],
|
|
17
|
+
"author": "Zazuko GmbH",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@rdfjs-elements/formats-pretty": "^0.6.7",
|
|
21
|
+
"@zazuko/env-node": "^2.1.3",
|
|
22
|
+
"@zazuko/s": "^1.0.1",
|
|
23
|
+
"@zazuko/shacl-playground": "^2.0.0",
|
|
24
|
+
"approvals": "^7.1.3",
|
|
25
|
+
"barnard59-rdf": "^3.4.0",
|
|
26
|
+
"barnard59-shacl": "^1.4.10",
|
|
27
|
+
"rdf-transform-graph-imports": "^0.2.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@changesets/cli": "^2"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/pretty-print.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import rdf from '@zazuko/env-node'
|
|
3
|
+
import formats from '@rdfjs-elements/formats-pretty'
|
|
4
|
+
import { argv } from 'node:process'
|
|
5
|
+
|
|
6
|
+
rdf.formats.import(formats)
|
|
7
|
+
|
|
8
|
+
// Default prefixes
|
|
9
|
+
let prefixes = ['sh', 'rdf', 'rdfs', 'xsd']
|
|
10
|
+
|
|
11
|
+
// Parse command-line arguments for prefixes
|
|
12
|
+
let currentPrefix = argv.indexOf('--prefixes')
|
|
13
|
+
let arg = argv[currentPrefix + 1]
|
|
14
|
+
while (arg && !arg.startsWith('--')) {
|
|
15
|
+
const [key, value] = arg.split('=')
|
|
16
|
+
if (value) {
|
|
17
|
+
prefixes.push([key.replace('--prefixes', '').trim(), value.trim()])
|
|
18
|
+
} else {
|
|
19
|
+
prefixes.push(key.replace('--prefixes', '').trim())
|
|
20
|
+
}
|
|
21
|
+
currentPrefix++
|
|
22
|
+
arg = argv[currentPrefix + 1]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
;(async function () {
|
|
26
|
+
const dataset = await rdf.dataset().import(rdf.formats.parsers.import('text/turtle', process.stdin))
|
|
27
|
+
|
|
28
|
+
process.stdout.write(await dataset.serialize({ format: 'text/turtle', prefixes }))
|
|
29
|
+
})()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
|
2
|
+
|
|
3
|
+
file=$1
|
|
4
|
+
relativePath=$(node -e "console.log(require('path').relative('$(pwd)', '$file'))")
|
|
5
|
+
|
|
6
|
+
message=$4
|
|
7
|
+
if [ -z "$message" ]; then
|
|
8
|
+
message="check report"
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
playground=$("$SCRIPT_PATH"/shorten-report.js "$2" "$3")
|
|
12
|
+
echo "❌ FAIL - $relativePath. $message: $playground"
|
|
13
|
+
|
|
14
|
+
# git diff non interactive
|
|
15
|
+
if [ -f "$1".approved.txt ]; then
|
|
16
|
+
printf '\n'
|
|
17
|
+
git diff --color --no-index "$1".approved.txt "$1".received.txt | cat
|
|
18
|
+
fi
|
package/run.sh
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
SCRIPT_PATH="$(dirname "$(realpath "$0")")"
|
|
4
|
+
WORKING_DIR="$(pwd)"
|
|
5
|
+
FAILED=0
|
|
6
|
+
|
|
7
|
+
filter=''
|
|
8
|
+
debug=false
|
|
9
|
+
prefixes=()
|
|
10
|
+
command="npx barnard59 shacl validate --shapes"
|
|
11
|
+
|
|
12
|
+
while [ $# -gt 0 ]; do
|
|
13
|
+
case "$1" in
|
|
14
|
+
--shapes=*)
|
|
15
|
+
shapesPath="${1#*=}"
|
|
16
|
+
;;
|
|
17
|
+
--approve)
|
|
18
|
+
approvalsFlags='-f'
|
|
19
|
+
;;
|
|
20
|
+
--debug)
|
|
21
|
+
debug=true
|
|
22
|
+
;;
|
|
23
|
+
--filter=*)
|
|
24
|
+
filter="${1#*=}"
|
|
25
|
+
;;
|
|
26
|
+
--valid-cases=*)
|
|
27
|
+
validCases="${1#*=}"
|
|
28
|
+
;;
|
|
29
|
+
--invalid-cases=*)
|
|
30
|
+
invalidCases="${1#*=}"
|
|
31
|
+
;;
|
|
32
|
+
--prefixes=*)
|
|
33
|
+
IFS=',' read -r -a tempPrefixes <<< "${1#*=}"
|
|
34
|
+
prefixes+=("${tempPrefixes[@]}")
|
|
35
|
+
;;
|
|
36
|
+
--command=*)
|
|
37
|
+
command="${1#*=}"
|
|
38
|
+
;;
|
|
39
|
+
*)
|
|
40
|
+
printf "*******************************************\n"
|
|
41
|
+
printf "* Error: Invalid argument: %s *\n" "$1"
|
|
42
|
+
printf "* Remember that the syntax is --arg=value *\n"
|
|
43
|
+
printf "*******************************************\n"
|
|
44
|
+
exit 1
|
|
45
|
+
esac
|
|
46
|
+
shift
|
|
47
|
+
done
|
|
48
|
+
|
|
49
|
+
# check if shapesPath is set
|
|
50
|
+
if [ -z "$shapesPath" ]; then
|
|
51
|
+
printf "*************************************\n"
|
|
52
|
+
printf "* Error: --shapes argument missing. *\n"
|
|
53
|
+
printf "*************************************\n"
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
command="$command $shapesPath"
|
|
58
|
+
if [ "$debug" = true ]; then
|
|
59
|
+
echo "🐞 Command: $command"
|
|
60
|
+
echo "🐞 Filter: $filter"
|
|
61
|
+
echo "🐞 Approval flags: $approvalsFlags"
|
|
62
|
+
echo ""
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
loadFullShape() {
|
|
66
|
+
"$SCRIPT_PATH"/load-graph.js "$1" | "$SCRIPT_PATH"/pretty-print.js --prefixes "${prefixes[@]}"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# iterate over valid cases, run validation and monitor exit code
|
|
70
|
+
for file in $validCases; do
|
|
71
|
+
name=$(basename "$file")
|
|
72
|
+
relativePath=$(node -e "console.log(require('path').relative('$WORKING_DIR', '$file'))")
|
|
73
|
+
|
|
74
|
+
# check if filter is set and skip if not matching
|
|
75
|
+
if [ -n "$filter" ] && ! echo "$file" | grep -q "$filter"; then
|
|
76
|
+
echo "ℹ️SKIP - $relativePath"
|
|
77
|
+
continue
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
sh -c "$command" > "$file.log" 2>&1
|
|
82
|
+
success=$?
|
|
83
|
+
} < "$file"
|
|
84
|
+
|
|
85
|
+
if [ $success -ne 0 ] ; then
|
|
86
|
+
"$SCRIPT_PATH"/report-failure.sh "$file" "$(loadFullShape "$shapesPath")" "$(cat "$file")"
|
|
87
|
+
FAILED=1
|
|
88
|
+
else
|
|
89
|
+
echo "✅ PASS - $relativePath"
|
|
90
|
+
fi
|
|
91
|
+
done
|
|
92
|
+
|
|
93
|
+
# iterate over invalid cases
|
|
94
|
+
for file in $invalidCases; do
|
|
95
|
+
name=$(basename "$file")
|
|
96
|
+
relativePath=$(node -e "console.log(require('path').relative('$WORKING_DIR', '$file'))")
|
|
97
|
+
|
|
98
|
+
# skip if file does not exist
|
|
99
|
+
if [ ! -f "$file" ]; then
|
|
100
|
+
continue
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
# check if pattern is set and skip if not matching
|
|
104
|
+
if [ -n "$filter" ] && ! echo "$file" | grep -q "$filter"; then
|
|
105
|
+
echo "ℹ️SKIP - $relativePath"
|
|
106
|
+
continue
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
report=$(sh -c "$command" < "$file" 2> "$file.log" | "$SCRIPT_PATH"/pretty-print.js --prefixes "${prefixes[@]}")
|
|
110
|
+
|
|
111
|
+
if ! echo "$report" | npx approvals "$name" --outdir "$(dirname "$file")" "$approvalsFlags" > /dev/null 2>&1 ; then
|
|
112
|
+
"$SCRIPT_PATH"/report-failure.sh "$file" "$(loadFullShape "$shapesPath")" "$(cat "$file")" "check results"
|
|
113
|
+
FAILED=1
|
|
114
|
+
else
|
|
115
|
+
echo "✅ PASS - $name"
|
|
116
|
+
fi
|
|
117
|
+
done
|
|
118
|
+
|
|
119
|
+
exit $FAILED
|