summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock151
-rw-r--r--Cargo.toml1
-rw-r--r--readme.org3
-rw-r--r--tests/cli.rs68
4 files changed, 178 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0a5c417..76e0078 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -95,6 +95,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
+name = "errno"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
+dependencies = [
+ "errno-dragonfly",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "errno-dragonfly"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
+dependencies = [
+ "cc",
+ "libc",
+]
+
+[[package]]
name = "fastrand"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -147,6 +168,16 @@ dependencies = [
]
[[package]]
+name = "io-lifetimes"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3"
+dependencies = [
+ "libc",
+ "windows-sys 0.45.0",
+]
+
+[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -211,6 +242,12 @@ dependencies = [
]
[[package]]
+name = "linux-raw-sys"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
+
+[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -385,15 +422,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
-name = "remove_dir_all"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
-dependencies = [
- "winapi",
-]
-
-[[package]]
name = "rexpect"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -407,6 +435,20 @@ dependencies = [
]
[[package]]
+name = "rustix"
+version = "0.36.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644"
+dependencies = [
+ "bitflags",
+ "errno",
+ "io-lifetimes",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys 0.45.0",
+]
+
+[[package]]
name = "serde"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -421,6 +463,7 @@ dependencies = [
"git2",
"nom",
"rexpect",
+ "tempfile",
"thiserror",
]
@@ -437,16 +480,15 @@ dependencies = [
[[package]]
name = "tempfile"
-version = "3.3.0"
+version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
+checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95"
dependencies = [
"cfg-if",
"fastrand",
- "libc",
"redox_syscall",
- "remove_dir_all",
- "winapi",
+ "rustix",
+ "windows-sys 0.42.0",
]
[[package]]
@@ -558,3 +600,84 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows-sys"
+version = "0.42.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.45.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.42.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
diff --git a/Cargo.toml b/Cargo.toml
index 98d243e..1f70f9a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,3 +14,4 @@ thiserror = "1.0.38"
[dev-dependencies]
anyhow = "1.0.69"
assert_cmd = "2.0.8"
+tempfile = "3.4.0"
diff --git a/readme.org b/readme.org
index 1a36ac8..9288d44 100644
--- a/readme.org
+++ b/readme.org
@@ -17,8 +17,7 @@ Pijul.
- [X] exit command
- [X] git init of private repo
- [X] responds to unknown commands
-- [ ] Isolation of workdir between tests
- - use TempDir and rexpect::session::spawn_command instead of spawn
+- [X] Isolation of workdir between tests
- [ ] git fetch
- git receive-pack <argument>
- [ ] git push
diff --git a/tests/cli.rs b/tests/cli.rs
index 8b8aa82..01e8f2b 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -1,12 +1,22 @@
use anyhow::Result;
use assert_cmd::{cargo::cargo_bin, Command};
-use rexpect::{session::PtySession, spawn};
+use rexpect::session::{spawn_command, PtySession};
+use tempfile::TempDir;
+
+struct TestContext {
+ p: PtySession,
+ workdir: TempDir,
+}
+
+fn spawn_interactive_process() -> Result<TestContext> {
+ let workdir = tempfile::tempdir()?;
-fn spawn_interactive_process() -> Result<PtySession> {
let path = cargo_bin(env!("CARGO_PKG_NAME"));
- let mut process = spawn(&path.display().to_string(), Some(3000))?;
- expect_prompt(&mut process)?;
- Ok(process)
+ let mut command = std::process::Command::new(&path);
+ command.current_dir(&workdir);
+ let mut p = spawn_command(command, Some(3000))?;
+ expect_prompt(&mut p)?;
+ Ok(TestContext { p, workdir })
}
fn expect_prompt(p: &mut PtySession) -> Result<()> {
@@ -22,59 +32,59 @@ fn shows_a_prompt() -> Result<()> {
#[test]
fn does_nothing_after_receiving_whitespace_input() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_line("")?;
- expect_prompt(&mut p)?;
- p.send_line(" ")?;
- expect_prompt(&mut p)?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_line("")?;
+ expect_prompt(&mut c.p)?;
+ c.p.send_line(" ")?;
+ expect_prompt(&mut c.p)?;
Ok(())
}
#[test]
fn quits_when_eof_is_sent() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_control('d')?;
- p.exp_eof()?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_control('d')?;
+ c.p.exp_eof()?;
Ok(())
}
#[test]
fn quits_when_exit_command_is_sent() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_line("exit")?;
- p.exp_eof()?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_line("exit")?;
+ c.p.exp_eof()?;
Ok(())
}
#[test]
fn reports_error_with_unsupported_shell_commands() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_line("ls")?;
- p.exp_string("Unknown input \"ls\"")?;
- expect_prompt(&mut p)?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_line("ls")?;
+ c.p.exp_string("Unknown input \"ls\"")?;
+ expect_prompt(&mut c.p)?;
Ok(())
}
#[test]
fn reports_error_with_nonsense_input() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_line(" asd fg ")?;
- p.exp_string("Unknown input \"asd fg\"")?;
- expect_prompt(&mut p)?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_line(" asd fg ")?;
+ c.p.exp_string("Unknown input \"asd fg\"")?;
+ expect_prompt(&mut c.p)?;
Ok(())
}
#[test]
fn can_init_a_new_git_repo() -> Result<()> {
- let mut p = spawn_interactive_process()?;
- p.send_line("git-init my-new-repo")?;
- p.exp_string("Successfully created my-new-repo.git")?;
- expect_prompt(&mut p)?;
+ let mut c = spawn_interactive_process()?;
+ c.p.send_line("git-init my-new-repo")?;
+ c.p.exp_string("Successfully created my-new-repo.git")?;
+ expect_prompt(&mut c.p)?;
Command::new("git")
.arg("rev-list")
.arg("--all")
- .current_dir("git/my-new-repo.git")
+ .current_dir(c.workdir.as_ref().join("git").join("my-new-repo.git"))
.assert()
.success()
.stdout("");