diff options
author | Greg <gregory.mkv@gmail.com> | 2019-11-17 14:28:43 -0500 |
---|---|---|
committer | Greg <gregory.mkv@gmail.com> | 2019-11-17 14:28:43 -0500 |
commit | 699eab6c27fea57f871db901732589cebd5cc155 (patch) | |
tree | 15364720ef192cc1e69ba3315b4521a8a89a3d10 /tests | |
parent | b9c04a4dd69e13d0385bfd8107b60f249d41c4d6 (diff) |
Add cli testing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cli.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..39aab05 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,50 @@ +use anyhow::Result; +use assert_cmd::prelude::*; +use assert_fs::prelude::*; +use std::process::Command; + +fn sd() -> Command { + Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Error invoking sd") +} + +#[test] +fn in_place() -> Result<()> { + let file = assert_fs::NamedTempFile::new("test")?; + file.write_str("abc123def")?; + + let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; + cmd.args(&["abc\\d+", "", file.path().to_str().unwrap()]); + cmd.assert().success(); + file.assert("def"); + + Ok(()) +} + +#[test] +fn replace_into_stdout() -> Result<()> { + let file = assert_fs::NamedTempFile::new("test")?; + file.write_str("abc123def")?; + + #[rustfmt::skip] + sd() + .args(&["-p", "abc\\d+", "", file.path().to_str().unwrap()]) + .assert() + .success() + .stdout("def"); + + file.assert("abc123def"); + + Ok(()) +} + +#[test] +fn stdin() -> Result<()> { + sd().args(&["abc\\d+", ""]) + .with_stdin() + .buffer("abc123def") + .assert() + .success() + .stdout("def"); + + Ok(()) +} |