[librsvg: 13/15] tests: Add tests for rsvg-convert output option



commit 9a350f25391dad5d07de6b165ff9e54e6ac226ee
Author: Sven Neumann <sven svenfoo org>
Date:   Tue Feb 11 21:52:28 2020 +0100

    tests: Add tests for rsvg-convert output option

 Cargo.lock                        | 24 +++++++++++++++++++
 tests/Cargo.toml                  |  1 +
 tests/src/cmdline/rsvg_convert.rs | 49 ++++++++++++++++++++++++++++++++-------
 3 files changed, 65 insertions(+), 9 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 82f8b877..ec2c13be 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -719,6 +719,7 @@ dependencies = [
  "lopdf 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "png 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "predicates 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1357,6 +1358,14 @@ name = "regex-syntax"
 version = "0.6.14"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 
+[[package]]
+name = "remove_dir_all"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "rsvg_internals"
 version = "0.0.1"
@@ -1549,6 +1558,19 @@ dependencies = [
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "tempfile"
+version = "3.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index";
+dependencies = [
+ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
+ "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "tendril"
 version = "0.4.1"
@@ -1850,6 +1872,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = 
"322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8"
 "checksum regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = 
"92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9"
 "checksum regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = 
"b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06"
+"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
 "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = 
"138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
 "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = 
"bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
 "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = 
"93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
@@ -1869,6 +1892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index";
 "checksum string_cache 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a"
 "checksum string_cache_codegen 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"f24c8e5e19d22a726626f1a5e16fe15b132dcf21d10177fa5a45ce7962996b97"
 "checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = 
"af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5"
+"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
 "checksum tendril 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"707feda9f2582d5d680d733e38755547a3e8fb471e7ba11452ecfd9ce93a5d3b"
 "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = 
"d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
 "checksum thin-slice 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = 
"8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
diff --git a/tests/Cargo.toml b/tests/Cargo.toml
index f8d780a1..a054b9bd 100644
--- a/tests/Cargo.toml
+++ b/tests/Cargo.toml
@@ -11,3 +11,4 @@ chrono = "0.3"
 lopdf = "0.23.0"
 png = "0.15.3"
 predicates = "1.0.2"
+tempfile = "3"
diff --git a/tests/src/cmdline/rsvg_convert.rs b/tests/src/cmdline/rsvg_convert.rs
index 74852d6c..67a19269 100644
--- a/tests/src/cmdline/rsvg_convert.rs
+++ b/tests/src/cmdline/rsvg_convert.rs
@@ -1,6 +1,7 @@
 extern crate assert_cmd;
 extern crate chrono;
 extern crate predicates;
+extern crate tempfile;
 
 use super::predicates::file;
 
@@ -10,19 +11,20 @@ use chrono::{TimeZone, UTC};
 use predicate::str::*;
 use predicates::prelude::*;
 use std::path::Path;
+use tempfile::Builder;
 
 // What should be tested here?
 // The goal is to test the code in rsvg-convert, not the entire library.
 //
-//  - all command-line options are accepted
-//  - size of the output (should be sufficient to do that for PNG) ✔
 //  - command-line options that affect size (width, height, zoom, resolution) ✔
+//  - pixel dimensions of the output (should be sufficient to do that for PNG) ✔
 //  - limit on output size (32767 pixels) ✔
 //  - output formats (PNG, PDF, PS, EPS, SVG), okay to ignore XML and recording ✔
 //  - multi-page output (for PDF) ✔
-//  - handling of SOURCE_DATA_EPOCH environment variable for PDF output ✔
-//  - handling of background color option ✔
-//  - support for optional CSS stylesheet ✔
+//  - output file option ✔
+//  - SOURCE_DATA_EPOCH environment variable for PDF output ✔
+//  - background color option ✔
+//  - optional CSS stylesheet ✔
 //  - error handling for missing SVG dimensions ✔
 //  - error handling for export lookup ID ✔
 //  - error handling for invalid input ✔
@@ -144,13 +146,42 @@ fn output_format_svg_short_option() {
 }
 
 #[test]
-fn output_format_unknown_yields_error() {
+fn output_file_option() {
+    let output = {
+        let tempfile = Builder::new().suffix(".png").tempfile().unwrap();
+        tempfile.path().to_path_buf()
+    };
+    assert!(predicates::path::is_file().not().eval(&output));
+
     let input = Path::new("fixtures/dimensions/521-with-viewbox.svg");
     RsvgConvert::new_with_input(input)
-        .arg("--format=foo")
+        .arg(format!("--output={}", output.display()))
         .assert()
-        .failure()
-        .stderr("Unknown output format.\n");
+        .success()
+        .stdout(is_empty());
+
+    assert!(predicates::path::is_file().eval(&output));
+    std::fs::remove_file(&output).unwrap();
+}
+
+#[test]
+fn output_file_short_option() {
+    let output = {
+        let tempfile = Builder::new().suffix(".png").tempfile().unwrap();
+        tempfile.path().to_path_buf()
+    };
+    assert!(predicates::path::is_file().not().eval(&output));
+
+    let input = Path::new("fixtures/dimensions/521-with-viewbox.svg");
+    RsvgConvert::new_with_input(input)
+        .arg("-o")
+        .arg(format!("{}", output.display()))
+        .assert()
+        .success()
+        .stdout(is_empty());
+
+    assert!(predicates::path::is_file().eval(&output));
+    std::fs::remove_file(&output).unwrap();
 }
 
 #[test]


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