Commit 21eef7a1 authored by richardARPANET's avatar richardARPANET

Generate test data in the tests themselves

parent b3609984
......@@ -81,6 +81,7 @@ version = "0.1.1"
dependencies = [
"assert_cli 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"galvanic-test 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -113,6 +114,11 @@ dependencies = [
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "galvanic-test"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itoa"
version = "0.4.3"
......@@ -236,6 +242,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum environment 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4b14e20978669064c33b4c1e0fb4083412e40fe56cbea2eae80fd7591503ee"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
"checksum galvanic-test 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e6ec93b2f388dcd1102437036da399ae305e9c6cdd4e213260f5ddb6005907a"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1"
......
......@@ -15,6 +15,5 @@ include = [
[dependencies]
csv = "1"
[dev-dependencies]
assert_cli = "0.6.3"
galvanic-test = "0.2.0"
......@@ -36,24 +36,51 @@ fn main() -> Result<(), Box<Error>> {
}
#[cfg(test)]
mod tests {
#[macro_use]
extern crate galvanic_test;
test_suite! {
use super::*;
use assert_cli;
#[test]
fn test_outputs_csv() {
fn create_test_csv(label: &str) -> Result<String, io::Error> {
let csv_path = String::from(format!("/tmp/{}.csv", label));
let mut wtr = csv::WriterBuilder::new().from_path(&csv_path)?;
wtr.write_record(&["header", "header2"])?;
wtr.write_record(
&[format!("csv{}_value{}_a", label, label),
format!("csv{}_anothervalue{}_a", label, label)]
)?;
wtr.write_record(
&[format!("csv{}_value{}_b", label, label),
format!("csv{}_anothervalue{}_b", label, label)]
)?;
wtr.flush()?;
return Ok(csv_path)
}
test test_outputs_csv() {
let csv_path1;
let csv_path2;
match create_test_csv("1") {
Ok(val) => csv_path1 = val,
Err(e) => panic!(e),
}
match create_test_csv("2") {
Ok(val) => csv_path2 = val,
Err(e) => panic!(e),
}
let expected_output = "\
header,header2\n\
a,123\n\
hello,456\n\
bob,\n\
2-a,2-123\n\
2-hello,2-456\n\
2-bob,";
let cmd = &[
"cargo", "run", "src/test_data/1.csv", "src/test_data/2.csv"
];
csv1_value1_a,csv1_anothervalue1_a\n\
csv1_value1_b,csv1_anothervalue1_b\n\
csv2_value2_a,csv2_anothervalue2_a\n\
csv2_value2_b,csv2_anothervalue2_b\n";
let cmd = &["cargo", "run", &csv_path1, &csv_path2];
assert_cli::Assert::command(cmd)
.stdout().is(expected_output)
.unwrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment