-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d091c03
commit 491a77a
Showing
8 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
OUTDIR="tests/expected" | ||
[[ ! -d "$OUTDIR" ]] && mkdir -p "$OUTDIR" | ||
|
||
echo "Hello there" > $OUTDIR/hello1.txt | ||
echo "Hello" "there" > $OUTDIR/hello2.txt | ||
echo -n "Hello there" > $OUTDIR/hello1.n.txt | ||
echo -n "Hello" "there" > $OUTDIR/hello2.n.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use assert_cmd::Command; | ||
use predicates::prelude::*; | ||
use std::fs; | ||
use anyhow::Result; | ||
|
||
#[test] | ||
fn dies_no_args() -> Result<()> { | ||
let mut cmd = Command::cargo_bin("echor")?; | ||
cmd.assert() | ||
.failure() | ||
.stderr(predicate::str::contains("Usage")); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn hello1() -> Result<()> { | ||
let expected = fs::read_to_string("tests/expected/hello1.txt")?; | ||
let mut cmd = Command::cargo_bin("echor")?; | ||
cmd.arg("Hello there").assert().success().stdout(expected); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn hello2() -> Result<()> { | ||
let expected = fs::read_to_string("tests/expected/hello2.txt")?; | ||
let mut cmd = Command::cargo_bin("echor")?; | ||
cmd.args(vec!["Hello", "there"]) | ||
.assert() | ||
.success() | ||
.stdout(expected); | ||
Ok(()) | ||
} | ||
|
||
fn run(args: &[&str], expected_file: &str) -> Result<()> { | ||
let expected = fs::read_to_string(expected_file)?; | ||
Command::cargo_bin("echor")? | ||
.args(args) | ||
.assert() | ||
.success() | ||
.stdout(expected); | ||
Ok(()) | ||
} | ||
|
||
// #[test] | ||
// fn hello1() -> Result<()> { | ||
// run(&["Hello there"], "tests/expected/hello1.txt") | ||
// } | ||
|
||
// #[test] | ||
// fn hello2() -> Result<()> { | ||
// run(&["Hello", "there"], "tests/expected/hello2.txt") | ||
// } | ||
|
||
#[test] | ||
fn hello1_no_newline() -> Result<()> { | ||
run(&["Hello there", "-n"], "tests/expected/hello1.n.txt") // Two spaces! | ||
} | ||
|
||
#[test] | ||
fn hello2_no_newline() -> Result<()> { | ||
run(&["-n", "Hello", "there"], "tests/expected/hello2.n.txt") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello there |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello there |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello there |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello there |