From 3e360f5a3e52852e349361d83280a3d21f051e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Mon, 18 Dec 2023 23:36:58 +0000 Subject: test(Makefile): add validate-docx-golden-test2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a validation rule based on OOXML-Validator which uses the Open-XML-SDK shipped and maintained as part of dotnet. This catches a few more issues compared to the .xsd. Unfortunately currently this executable always exits with 0 even when validation failed. That can be fixed later by invoking it from a script. Signed-off-by: Edwin Török --- Makefile | 9 +++++++++ tools/validate-docx2.sh | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tools/validate-docx2.sh diff --git a/Makefile b/Makefile index 254448cc8..5d1be9ef8 100644 --- a/Makefile +++ b/Makefile @@ -242,6 +242,15 @@ validate-docx-golden-tests: ## validate docx golden tests against schema sh ./tools/validate-docx.sh test/docx/golden/*.docx .PHONY: validate-docx-golden-tests +validate-docx-golden-tests2: ## validate docx golden tests using OOXMLValidator + which dotnet || ("dotnet is required" && exit 1) + which json_reformat || ("json_reformat is required" && exit 1) + test -d ./OOXML-Validator || \ + (git clone https://github.com/mikeebowen/OOXML-Validator.git \ + && cd OOXML-Validator && dotnet build --configuration=Release) + dotnet run --configuration=Release --no-build --no-restore --project OOXML-Validator/OOXMLValidatorCLI -- test/docx/golden -r | json_reformat +.PHONY: validate-docx-golden-tests2 + validate-epub: ## generate an epub and validate it with epubcheck which epubcheck || exit 1 tmp=$$(mktemp -d) && \ diff --git a/tools/validate-docx2.sh b/tools/validate-docx2.sh new file mode 100644 index 000000000..7b43c62a0 --- /dev/null +++ b/tools/validate-docx2.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# based on validate-docx.sh, and adapted for OOXMLValidatorCLI +# Modified by edwintorok from https://github.com/devoidfury/docx-validator +# to look at more files than just document.xml. +# Further modified by jgm for portability. + +tmpdir=$(mktemp -d) +error_files="" +errors=0 +VALIDATOR=OOXML-Validator/bin/Release/*/OOXMLValidatorCLI + +for file in "$@"; do + file_errors=0 + echo "*** Checking $file" + dotnet $(VALIDATOR) "${file}" 2>&1 || file_errors=1 + if [ $file_errors -gt 0 ]; then + errors=$((file_errors + errors)) + error_files="$error_files\n$file" + fi +done +if [ $errors -gt 0 ]; then + echo "These files failed validation:$error_files" +fi +exit $errors -- cgit v1.2.3