Skip to content

Commit

Permalink
feat: more output when tests finish (#6)
Browse files Browse the repository at this point in the history
* feat: more output when tests finish

* Create cyan-rabbits-double.md
  • Loading branch information
tpluscode authored Nov 6, 2024
1 parent 7a61928 commit f09b688
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-rabbits-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zazuko/shacl-test": patch
---

Provide test run summary and exit with nonzero code when no tests are found
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ npx shacl-test \
--command="${COMMAND}"
```

Only the `--shapes` option is required. The rest are optional.
The `--shapes` option is required.
Also, you must provide at least `--valid-cases` or `--invalid-cases`, lest no tests are run.
The rest are optional.

`--shapes` can be a filesystem path or URL and include [`code:imports`](https://github.com/zazuko/rdf-transform-graph-imports).

Expand Down
19 changes: 19 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ loadFullShape() {
"$SCRIPT_PATH"/load-graph.js "$1" | "$SCRIPT_PATH"/pretty-print.js --prefixes "${prefixes[@]}"
}

testsRun=0

# iterate over valid cases, run validation and monitor exit code
for file in $validCases; do
testsRun=$((testsRun + 1))

name=$(basename "$file")
relativePath=$(node -e "console.log(require('path').relative('$WORKING_DIR', '$file'))")

Expand All @@ -92,6 +96,8 @@ done

# iterate over invalid cases
for file in $invalidCases; do
testsRun=$((testsRun + 1))

name=$(basename "$file")
relativePath=$(node -e "console.log(require('path').relative('$WORKING_DIR', '$file'))")

Expand All @@ -116,4 +122,17 @@ for file in $invalidCases; do
fi
done

if [ $testsRun -eq 0 ]; then
echo "ℹ️ No test cases found"
echo "ℹ️ Check if the --valid-cases and --invalid-cases globs match any files"
exit 255
fi

echo "🏁 Tests cases run: $testsRun"
if [ $FAILED -eq 0 ]; then
echo "🎉 All tests passed"
else
echo "❌ Failed $FAILED tests"
fi

exit $FAILED

0 comments on commit f09b688

Please sign in to comment.