Skip to content

Commit

Permalink
Merge pull request #527 from woshilapin/ci-xmllint
Browse files Browse the repository at this point in the history
[tech] Add test linter on XML for NeTEx France
  • Loading branch information
ArnaudOggy authored Feb 3, 2020
2 parents f1fbf96 + 7db19fa commit 2c63a99
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/NeTEx"]
path = tests/NeTEx
url = https://github.com/NeTEx-CEN/NeTEx.git
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ addons:
key_url: "https://kisiodigital.jfrog.io/kisiodigital/api/gpg/key/public"
packages:
- proj=6.3.0
- libxml2-utils
matrix:
include:
- rust: stable
Expand All @@ -24,7 +25,7 @@ matrix:
allow_failures:
- rust: nightly
script:
- cargo test --workspace --verbose --features proj
- cargo test --workspace --verbose --all-features
deploy:
provider: cargo
on:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [

[features]
stop_location = []
xmllint = ["proj"]

[dependencies]
chrono = "0.4"
Expand Down Expand Up @@ -81,7 +82,7 @@ required-features = ["proj"]
[[bench]]
name = "read_transxchange"
path = "benches/read_transxchange.rs"
required-features = ["transxchange"]
required-features = ["proj"]

[[test]]
name = "netexidf2ntfs"
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ If you want to use [PROJ](https://proj.org/) in your code, you can if you
activate the `proj` feature (`cargo build --features=proj`). Then don't forget
to protect your code with `#[cfg(feature="proj")]`.

### Feature `xmllint`
`transit_model` is capable of exporting NeTEx France format. In the tests, we're
automatically verifying that the produced files are matching the NeTEx
specification. For that, we're using the tool `xmllint` which can be install
on Debian with the package `libxml2-utils`. Therefore, these tests are run only
if you activate them. We also depend on NeTEx specification that are imported as
a git submodule.

```bash
git submodule update --init --recursive
apt install libxml2-utils
cargo test --features xmllint
```

## Benchmarking
A few benchmarks are available if you want to compare performance of a new
feature or of an optimization. Benchmarking functionality is only available in
Expand Down
1 change: 1 addition & 0 deletions tests/NeTEx
Submodule NeTEx added at 348033
23 changes: 23 additions & 0 deletions tests/write_netex_france.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>

#[cfg(feature = "xmllint")]
use std::{ffi::OsStr, fs, process::Command};
use transit_model::{self, netex_france, test_utils::*};

#[test]
Expand All @@ -30,3 +32,24 @@ fn test_write_netex_france() {
compare_output_dir_with_expected_content(&output_dir, None, "tests/fixtures/netex_france");
});
}

#[test]
#[cfg(feature = "xmllint")]
fn validate_xml_schemas() {
let paths = fs::read_dir("tests/fixtures/netex_france/")
.unwrap()
.map(|result| result.unwrap())
.map(|dir_entry| dir_entry.path())
.filter(|path| path.extension() == Some(&OsStr::new("xml")));
for path in paths {
let status = Command::new("xmllint")
.arg("--noout")
.arg("--nonet")
.arg("--huge")
.args(&["--schema", "tests/NeTEx/xsd/NeTEx_publication.xsd"])
.arg(path)
.status()
.unwrap();
assert!(status.success());
}
}

0 comments on commit 2c63a99

Please sign in to comment.