Skip to content

Commit

Permalink
Add integration tests for the auto/never color options
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev authored and dbrgn committed Aug 30, 2020
1 parent 1b8062e commit dc6af5a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
28 changes: 28 additions & 0 deletions tests/inkscape-default-no-color.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

An SVG (Scalable Vector Graphics) editing program.
Use -z to not open the GUI and only process files in the console.

Open an SVG file in the Inkscape GUI:

inkscape filename.svg

Export an SVG file into a bitmap with the default format (PNG) and the default resolution (90 DPI):

inkscape filename.svg -e filename.png

Export an SVG file into a bitmap of 600x400 pixels (aspect ratio distortion may occur):

inkscape filename.svg -e filename.png -w 600 -h 400

Export a single object, given its ID, into a bitmap:

inkscape filename.svg -i id -e object.png

Export an SVG document to PDF, converting all texts to paths:

inkscape filename.svg | inkscape | inkscape --export-pdf=inkscape.pdf | inkscape | inkscape --export-text-to-path

Duplicate the object with id="path123", rotate the duplicate 90 degrees, save the file, and quit Inkscape:

inkscape filename.svg --select=path123 --verb=EditDuplicate --verb=ObjectRotate90 --verb=FileSave --verb=FileQuit

47 changes: 42 additions & 5 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ fn test_markdown_rendering() {
.stdout(similar(expected));
}

fn _test_correct_rendering(input_file: &str, filename: &str) {
fn _test_correct_rendering(
input_file: &str,
filename: &str,
expected: &'static str,
color_option: &str,
) {
let testenv = TestEnv::new();

// Create input file
Expand All @@ -250,10 +255,9 @@ fn _test_correct_rendering(input_file: &str, filename: &str) {
let mut file = File::create(&file_path).unwrap();
file.write_all(input_file.as_bytes()).unwrap();

let expected = include_str!("inkscape-default.expected");
testenv
.command()
.args(&["--color", "always", "-f", &file_path.to_str().unwrap()])
.args(&["--color", color_option, "-f", &file_path.to_str().unwrap()])
.assert()
.success()
.stdout(similar(expected));
Expand All @@ -262,13 +266,46 @@ fn _test_correct_rendering(input_file: &str, filename: &str) {
/// An end-to-end integration test for direct file rendering (v1 syntax).
#[test]
fn test_correct_rendering_v1() {
_test_correct_rendering(include_str!("inkscape-v1.md"), "inkscape-v1.md");
_test_correct_rendering(
include_str!("inkscape-v1.md"),
"inkscape-v1.md",
include_str!("inkscape-default.expected"),
"always",
);
}

/// An end-to-end integration test for direct file rendering (v2 syntax).
#[test]
fn test_correct_rendering_v2() {
_test_correct_rendering(include_str!("inkscape-v2.md"), "inkscape-v2.md");
_test_correct_rendering(
include_str!("inkscape-v2.md"),
"inkscape-v2.md",
include_str!("inkscape-default.expected"),
"always",
);
}

#[test]
/// An end-to-end integration test for direct file rendering with the `--color auto` option. This
/// will not use styling since output is not stdout.
fn test_rendering_color_auto() {
_test_correct_rendering(
include_str!("inkscape-v2.md"),
"inkscape-v2.md",
include_str!("inkscape-default-no-color.expected"),
"auto",
);
}

#[test]
/// An end-to-end integration test for direct file rendering with the `--color never` option.
fn test_rendering_color_never() {
_test_correct_rendering(
include_str!("inkscape-v2.md"),
"inkscape-v2.md",
include_str!("inkscape-default-no-color.expected"),
"never",
);
}

/// An end-to-end integration test for rendering with constom syntax config.
Expand Down

0 comments on commit dc6af5a

Please sign in to comment.