summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGreg <gregory.mkv@gmail.com>2019-11-17 14:28:43 -0500
committerGreg <gregory.mkv@gmail.com>2019-11-17 14:28:43 -0500
commit699eab6c27fea57f871db901732589cebd5cc155 (patch)
tree15364720ef192cc1e69ba3315b4521a8a89a3d10 /tests
parentb9c04a4dd69e13d0385bfd8107b60f249d41c4d6 (diff)
Add cli testing
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs50
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(())
+}