From 560bd03fb99b64f4a8bc5e0e96b365a9d1f0d3c9 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Fri, 19 Apr 2024 17:01:14 -0400 Subject: [PATCH] Support validation using new deno validator while manually skipping EMPTY_FILE errors. Also adjusted output to make it more concise and easier to identify what errors belong to etc --- run_tests.sh | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 8d88ee5a5..7d0f889dd 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,17 +2,18 @@ rc=0; -if bids-validator --version | grep -q 'alpha$'; then - VALIDATOR_SUPPORTS_CONFIG=no -else +which bids-validator +if bids-validator --help | grep -q -e '--config'; then VALIDATOR_SUPPORTS_CONFIG=yes +else + VALIDATOR_SUPPORTS_CONFIG= fi for i in $(ls -d */ | grep -v node_modules); do - echo "Validating dataset" $i + echo -n "Validating dataset $i: " if [ -f ${i%%/}/.SKIP_VALIDATION ]; then - echo "Skipping validation for ${i%%/}" + echo "skipping validation" continue fi @@ -21,18 +22,37 @@ for i in $(ls -d */ | grep -v node_modules); do CMD="bids-validator ${i%%/} $VALIDATOR_ARGS" # Use default configuration unless overridden - if [ "$VALIDATOR_SUPPORTS_CONFIG" = "yes" ] && [ ! -f ${i%%/}/.bids-validator-config.json ]; then - CMD="$CMD -c $PWD/bidsconfig.json" + if [ -n "$VALIDATOR_SUPPORTS_CONFIG" ]; then + if [ ! -f ${i%%/}/.bids-validator-config.json ]; then + CMD="$CMD -c $PWD/bidsconfig.json" + fi + else + # with new one we do not have config so let's get --json and exclude some using jq + CMD="$CMD --json" fi # Ignore NIfTI headers except for synthetic dataset if [ $i != "synthetic/" ]; then CMD="$CMD --ignoreNiftiHeaders" else - echo "Validating NIfTI headers for dataset" $i + echo "validating NIfTI headers. " fi - echo $CMD - $CMD || rc=$? + echo "Running " $CMD + + if [ -n "$VALIDATOR_SUPPORTS_CONFIG" ]; then + $CMD || rc=$? + else + # rc is not returned correctly anyways and for the best since we need to ignore + # ref: https://github.com/bids-standard/bids-validator/issues/1909 + # NOTE: limit to 1 file per error to not flood screen! + errors=$($CMD 2>/dev/null \ + | jq '(.issues | map(select(.severity == "error" and .key != "EMPTY_FILE"))) | map(.files_1 = (.files | if length > 0 then .[0:1] else empty end) | del(.files)) | if length > 0 then . else empty end' \ + ) + if [ -n "$errors" ]; then + echo -e "$errors" | sed -e 's,^, ,g' + rc=1 + fi + fi done exit $rc;