[librsvg: 1/15] tests: Add infrastructure to test the rust-convert command-line tool



commit dadd8eb1eecdef853f4ae065e42e60c4e404d559
Author: Sven Neumann <sven svenfoo org>
Date:   Mon Feb 3 14:09:38 2020 +0100

    tests: Add infrastructure to test the rust-convert command-line tool
    
    The goal is to write tests in Rust for the existing binary,
    written in C. Then port rust-convert to Rust and make sure that
    it passes the same tests before removing the C implementation.

 Cargo.lock                        | 108 ++++++++++++++++++++++++++++++++++++--
 Cargo.toml                        |   1 +
 tests/Cargo.toml                  |  10 ++++
 tests/Makefile.am                 |   7 +++
 tests/src/cmdline/mod.rs          |   1 +
 tests/src/cmdline/rsvg_convert.rs |  24 +++++++++
 tests/src/main.rs                 |   6 +++
 7 files changed, 152 insertions(+), 5 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 436e4878..a270a30d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,6 +27,18 @@ dependencies = [
  "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "assert_cmd"
+version = "0.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "escargot 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "predicates 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "atty"
 version = "0.2.14"
@@ -156,7 +168,7 @@ dependencies = [
  "rayon-core 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "tinytemplate 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -275,6 +287,16 @@ dependencies = [
  "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "difference"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+
+[[package]]
+name = "doc-comment"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+
 [[package]]
 name = "downcast-rs"
 version = "1.1.1"
@@ -355,6 +377,25 @@ name = "encoding_index_tests"
 version = "0.1.4"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
+[[package]]
+name = "escargot"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "float-cmp"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "float-cmp"
 version = "0.6.0"
@@ -614,6 +655,14 @@ dependencies = [
  "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "librsvg-tests"
+version = "0.1.0"
+dependencies = [
+ "assert_cmd 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "predicates 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "librsvg_c_api"
 version = "0.0.1"
@@ -676,7 +725,7 @@ dependencies = [
  "phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "string_cache 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "string_cache_codegen 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "tendril 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -738,6 +787,11 @@ name = "nodrop"
 version = "0.1.14"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
+[[package]]
+name = "normalize-line-endings"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+
 [[package]]
 name = "num-complex"
 version = "0.2.4"
@@ -958,6 +1012,32 @@ name = "precomputed-hash"
 version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
+[[package]]
+name = "predicates"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "float-cmp 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "predicates-core"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+
+[[package]]
+name = "predicates-tree"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "proc-macro-hack"
 version = "0.5.11"
@@ -1243,6 +1323,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 name = "serde"
 version = "1.0.104"
 source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
+]
 
 [[package]]
 name = "serde_derive"
@@ -1256,7 +1339,7 @@ dependencies = [
 
 [[package]]
 name = "serde_json"
-version = "1.0.45"
+version = "1.0.46"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
  "itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1368,9 +1451,14 @@ version = "1.0.3"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 dependencies = [
  "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "treeline"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+
 [[package]]
 name = "typenum"
 version = "1.11.2"
@@ -1468,6 +1556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum aho-corasick 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = 
"5f56c476256dc249def911d6f7580b5fc7e875895b5d7ee88f5d602208035744"
 "checksum alga 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"658f9468113d34781f6ca9d014d174c74b73de870f1e0e3ad32079bbab253b19"
 "checksum approx 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
+"checksum assert_cmd 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"6283bac8dd7226470d491bc4737816fea4ca1fba7a2847f2e9097fd6bfb4624c"
 "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
 "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = 
"1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
 "checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
@@ -1494,6 +1583,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = 
"9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c"
 "checksum data-url 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d33fe99ccedd6e84bc035f1931bb2e6be79739d6242bd895e7311c886c50dc9c"
 "checksum derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"2159be042979966de68315bce7034bb000c775f22e3e834e1c52ff78f041cae8"
+"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
+"checksum doc-comment 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"923dea538cea0aa3025e8685b20d6ee21ef99c4f77e954a30febbaac5ec73a97"
 "checksum downcast-rs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"52ba6eb47c2131e784a38b726eb54c1e1484904f013e576a25354d0124161af6"
 "checksum dtoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = 
"4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3"
 "checksum dtoa-short 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"59020b8513b76630c49d918c33db9f4c91638e7d3404a28084083b87e33f76f2"
@@ -1505,6 +1596,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = 
"3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
 "checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = 
"fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
 "checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
+"checksum escargot 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"74cf96bec282dcdb07099f7e31d9fed323bca9435a09aba7b6d99b7617bca96d"
+"checksum float-cmp 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"75224bec9bfe1a65e2d34132933f2de7fe79900c96a0174307554244ece8150e"
 "checksum float-cmp 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"da62c4f1b81918835a8c6a484a397775fff5953fe83529afd51b05f5c6a6617d"
 "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
 "checksum futf 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b"
@@ -1545,6 +1638,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum nalgebra 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"0abb021006c01b126a936a8dd1351e0720d83995f4fc942d0d426c654f990745"
 "checksum new_debug_unreachable 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
 "checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = 
"72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
+"checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8"
 "checksum num-complex 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
 "checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = 
"3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
 "checksum num-rational 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"da4dc79f9e6c81bef96148c8f6b8e72ad4541caa4a24373e900a36da07de03a3"
@@ -1570,6 +1664,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = 
"05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
 "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = 
"74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
 "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
+"checksum predicates 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"a9bfe52247e5cc9b2f943682a85a5549fb9662245caf094504e69a2f03fe64d4"
+"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
+"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
 "checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = 
"ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5"
 "checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e"
 "checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = 
"3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548"
@@ -1601,7 +1698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
 "checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = 
"414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
 "checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = 
"128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
-"checksum serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = 
"eab8f15f15d6c41a154c1b128a22f2dfabe350ef53c40953d84e36155c91192b"
+"checksum serde_json 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = 
"21b01d7f0288608a01dca632cf1df859df6fd6ffa885300fc275ce2ba6221953"
 "checksum servo_arc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432"
 "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
 "checksum siphasher 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"83da420ee8d1a89e640d0948c646c1c088758d3a3c538f943bfa97bdac17929d"
@@ -1616,6 +1713,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
 "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
 "checksum tinytemplate 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"57a3c6667d3e65eb1bc3aed6fd14011c6cbc3a0665218ab7f5daf040b9ec371a"
+"checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
 "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
 "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
 "checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = 
"5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4"
diff --git a/Cargo.toml b/Cargo.toml
index e344df6d..818fa620 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,6 +3,7 @@ members = [
     "librsvg",
     "librsvg_crate",
     "rsvg_internals",
+    "tests",
 ]
 
 [profile.release]
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
new file mode 100644
index 00000000..84707ecd
--- /dev/null
+++ b/tests/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "librsvg-tests"
+version = "0.1.0"
+authors = ["Sven Neumann <sven svenfoo org>"]
+workspace = ".."
+edition = "2018"
+
+[dev-dependencies]
+assert_cmd = "0.12"
+predicates = "1.0.2"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b526e6c..e5e6581e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,13 @@
 include $(top_srcdir)/glib-tap.mk
 
+test_sources =                         \
+       Cargo.toml              \
+       src/main.rs             \
+       src/cmdline/mod.rs      \
+       src/cmdline/rsvg_convert.rs
+
 EXTRA_DIST +=          \
+       $(test_sources) \
        README.md
 
 # Keep "errors" at the end; they are the slowest to run
diff --git a/tests/src/cmdline/mod.rs b/tests/src/cmdline/mod.rs
new file mode 100644
index 00000000..c694bf2e
--- /dev/null
+++ b/tests/src/cmdline/mod.rs
@@ -0,0 +1 @@
+mod rsvg_convert;
diff --git a/tests/src/cmdline/rsvg_convert.rs b/tests/src/cmdline/rsvg_convert.rs
new file mode 100644
index 00000000..83feeb28
--- /dev/null
+++ b/tests/src/cmdline/rsvg_convert.rs
@@ -0,0 +1,24 @@
+extern crate assert_cmd;
+extern crate predicates;
+
+use predicates::prelude::*;
+use std::path::Path;
+
+struct RsvgConvert {
+    cmd: assert_cmd::Command,
+}
+
+impl RsvgConvert {
+    fn new() -> Self {
+        let dir = Path::new(env!("CARGO_MANIFEST_DIR"));
+        let path = dir.parent().unwrap().join("rsvg-convert");
+        RsvgConvert { cmd: assert_cmd::Command::new(path) }
+    }
+}
+
+#[test]
+fn version() {
+    let expected = predicate::str::starts_with("rsvg-convert version ");
+    RsvgConvert::new().cmd.arg("-v").assert().success().stdout(expected.clone());
+    RsvgConvert::new().cmd.arg("--version").assert().success().stdout(expected);
+}
diff --git a/tests/src/main.rs b/tests/src/main.rs
new file mode 100644
index 00000000..48bee891
--- /dev/null
+++ b/tests/src/main.rs
@@ -0,0 +1,6 @@
+#[cfg(test)]
+mod cmdline;
+
+fn main() {
+    println!("Use 'cargo test' to run the tests");
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]