Skip to content

Commit

Permalink
Refactored functional test using assert_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
pomettini committed May 30, 2019
1 parent e83fb93 commit a5a885e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ after_success: |
cargo tarpaulin --ciserver travis-ci --coveralls $TRAVIS_JOB_ID
# Uncomment the following two lines create and upload a report for codecov.io
cargo tarpaulin --out Xml
bash <(curl -s https://codecov.io/bash)
# cargo tarpaulin --out Xml
# bash <(curl -s https://codecov.io/bash)
fi
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ authors = ["Giorgio Pomettini <giorgio.pomettini@gmail.com>"]

[dependencies]
regex = ">=1"
clap = ">=2"
clap = ">=2"
assert_cmd = ">=0.11.1"
59 changes: 15 additions & 44 deletions src/bin/stevia.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg_attr(feature = "clippy", allow(clippy_pedantic))]

extern crate assert_cmd;
extern crate clap;
extern crate stevia;

Expand Down Expand Up @@ -42,64 +41,41 @@ fn main() {
}

mod tests {
use std::env;
use assert_cmd::prelude::*;
use std::fs;
use std::process::Command;

#[test]
fn test_load_no_argument() {
clean();

let output = Command::new("./target/debug/stevia").output().unwrap();

assert!(output.stderr.len() > 0);

let mut cmd = Command::cargo_bin("stevia").unwrap();
cmd.assert().failure();
clean();
}

#[test]
fn test_load_file() {
clean();

let output = Command::new("./target/debug/stevia")
.arg("examples/example.ink")
.output()
.unwrap();

assert!(output.stderr.len() == 0);

let mut cmd = Command::cargo_bin("stevia").unwrap();
cmd.arg("examples/example.ink");
cmd.assert().success();
clean();
}

#[test]
fn test_load_non_existent_file() {
clean();

let output = Command::new("./target/debug/stevia")
.arg("examples/examples.ink")
.output()
.unwrap();

assert!(output.stderr.len() > 0);

let mut cmd = Command::cargo_bin("stevia").unwrap();
cmd.arg("examples/nonexistent.ink");
cmd.assert().failure();
clean();
}

#[test]
fn test_functional_process_file_green() {
clean();

Command::new("./target/debug/stevia")
.arg("examples/example.ink")
.output()
.unwrap();

let mut cmd = Command::cargo_bin("stevia").unwrap();
cmd.arg("examples/example.ink").assert().success();
// Check contents of output file
let expected = "P;Hello there|P;I'm a VN written in the Ink format|P;Do you like it?|Q;Yes, I like it!;00120;No, I do not like it;00136|P;Thank you!|E;|P;Oh, I see|E;";

let contents = fs::read_to_string("example.stevia").expect("Cannot find .stevia file");

assert_eq!(contents, expected);

assert_eq!(expected, contents);
clean();
}

Expand All @@ -111,10 +87,5 @@ mod tests {
.arg("*.stevia")
.arg("-delete")
.output()
.unwrap();

// println!("status: {}", output.status);
// println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
// println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
}
.unwrap(); }
}
4 changes: 3 additions & 1 deletion stevia.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"path": "."
}
],
"settings": {}
"settings": {
"cSpell.enabled": false
}
}

0 comments on commit a5a885e

Please sign in to comment.