Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/scripts/validate-should-fail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Negative examples: documents that MUST be rejected by the schema.
#
# Each case is declared as: should_fail <file> <expected error substring>.
# We assert BEHAVIOUR (the document is rejected, and its output contains the
# declared substring) - not a specific constraint name.
#
# All cases share ONE schema and are validated in a SINGLE xmllint call (one
# compile for many files) to stay fast. Fails closed: accepted, wrong reason, or
# xmllint not running all count as failures.
#
# CI uses the vendored 2025 Linux x86-64 xmllint ("Temporary xmllint master",
# https://github.com/TransmodelEcosystem/NeTEx/pull/915); set XMLLINT_BIN to a local
# xmllint to run this on any other OS or CPU architecture (macOS, Windows, ARM, ...).

set -u
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$( cd -- "${SCRIPT_DIR}/../.." &> /dev/null && pwd )
XMLLINT="${XMLLINT_BIN:-${SCRIPT_DIR}/xmllint}"
cd "${ROOT_DIR}"

SCHEMA="xsd/NeTEx_publication.xsd"

files=(); expected=()
should_fail() { files+=("$1"); expected+=("$2"); }

should_fail examples/should-fail/duplicate-GroupOfLinkSequences.xml "Duplicate key-sequence ['TEST:GroupOfLinkSequences:1', '1.0']"
should_fail examples/should-fail/duplicate-ValidBetween.xml "Duplicate key-sequence ['TEST:ValidBetween:1', '1.0']"
should_fail examples/should-fail/duplicate-ValidityPeriod.xml "Duplicate key-sequence ['TEST:ValidityPeriod:1', '1.0']"

out=$("${XMLLINT}" --noout --schema "${SCHEMA}" "${files[@]}" 2>&1)

fail=0
echo "Checking NeTEx 'should-fail' negative examples ..."
for i in "${!files[@]}"; do
f="${files[$i]}"; exp="${expected[$i]}"
if printf '%s\n' "${out}" | grep -Fqx "${f} validates"; then
echo "SHOULD HAVE FAILED ${f} — accepted (must be rejected)"; fail=1
elif printf '%s\n' "${out}" | grep -F "${f}:" | grep -Fq "${exp}"; then
echo "OK ${f}"
else
echo "ERROR ${f} — rejected, but not matching '${exp}'"; fail=1
fi
done

exit "${fail}"
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Validate NeTEx XML examples
run: ./.github/scripts/validate-examples.sh

- name: Validate negative examples (must-fail)
run: ./.github/scripts/validate-should-fail.sh

- name: Commit changes
uses: EndBug/add-and-commit@v9 # https://github.com/marketplace/actions/add-commit
with:
Expand Down
7 changes: 7 additions & 0 deletions examples/should-fail/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Negative examples (must-fail)

Each file carries one deliberate defect and must therefore be **rejected** by the
schema for a specific, expected reason. The cases — file, schema and expected
constraint — are declared in `.github/scripts/validate-should-fail.sh` (run in CI).

Run locally: `XMLLINT_BIN=$(which xmllint) ./.github/scripts/validate-should-fail.sh`
13 changes: 13 additions & 0 deletions examples/should-fail/duplicate-GroupOfLinkSequences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<PublicationTimestamp>2020-01-01T12:00:00Z</PublicationTimestamp>
<ParticipantRef>TEST</ParticipantRef>
<dataObjects>
<ResourceFrame version="1.0" id="TEST:ResourceFrame:1">
<groupsOfEntities>
<GroupOfLinkSequences version="1.0" id="TEST:GroupOfLinkSequences:1"/>
<GroupOfLinkSequences version="1.0" id="TEST:GroupOfLinkSequences:1"/>
</groupsOfEntities>
</ResourceFrame>
</dataObjects>
</PublicationDelivery>
17 changes: 17 additions & 0 deletions examples/should-fail/duplicate-ValidBetween.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<PublicationTimestamp>2020-01-01T12:00:00Z</PublicationTimestamp>
<ParticipantRef>TEST</ParticipantRef>
<dataObjects>
<ResourceFrame version="1.0" id="TEST:ResourceFrame:1">
<ValidBetween id="TEST:ValidBetween:1" version="1.0">
<FromDate>2020-01-01T00:00:00Z</FromDate>
</ValidBetween>
</ResourceFrame>
<ServiceFrame version="1.0" id="TEST:ServiceFrame:1">
<ValidBetween id="TEST:ValidBetween:1" version="1.0">
<FromDate>2020-01-01T00:00:00Z</FromDate>
</ValidBetween>
</ServiceFrame>
</dataObjects>
</PublicationDelivery>
23 changes: 23 additions & 0 deletions examples/should-fail/duplicate-ValidityPeriod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<PublicationDelivery xmlns="http://www.netex.org.uk/netex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<PublicationTimestamp>2020-01-01T12:00:00Z</PublicationTimestamp>
<ParticipantRef>TEST</ParticipantRef>
<dataObjects>
<ResourceFrame version="1.0" id="TEST:ResourceFrame:1">
<organisations>
<Authority version="1.0" id="TEST:Authority:1">
<Name>A</Name>
<ValidityPeriod id="TEST:ValidityPeriod:1" version="1.0">
<FromDate>2020-01-01T00:00:00Z</FromDate>
</ValidityPeriod>
</Authority>
<Operator version="1.0" id="TEST:Operator:1">
<Name>B</Name>
<ValidityPeriod id="TEST:ValidityPeriod:1" version="1.0">
<FromDate>2020-01-01T00:00:00Z</FromDate>
</ValidityPeriod>
</Operator>
</organisations>
</ResourceFrame>
</dataObjects>
</PublicationDelivery>
Loading