Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor shell E2E tests to use rstest for fish and zsh
Maximilian Roos39625534e4ea
diff --git a/Cargo.lock b/Cargo.lockindex 4297433db..949378d64 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -497,6 +497,101 @@ version = "1.0.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"+[[package]]+name = "futures"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-executor",+ "futures-io",+ "futures-sink",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-channel"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"+dependencies = [+ "futures-core",+ "futures-sink",+]++[[package]]+name = "futures-core"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"++[[package]]+name = "futures-executor"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"+dependencies = [+ "futures-core",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-io"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"++[[package]]+name = "futures-macro"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "futures-sink"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"++[[package]]+name = "futures-task"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"++[[package]]+name = "futures-timer"+version = "3.0.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24"++[[package]]+name = "futures-util"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-macro",+ "futures-sink",+ "futures-task",+ "memchr",+ "pin-project-lite",+ "pin-utils",+ "slab",+]+[[package]]name = "generic-array"version = "0.14.9"@@ -530,6 +625,12 @@ dependencies = ["wasip2",]+[[package]]+name = "glob"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"+[[package]]name = "hashbrown"version = "0.14.5"@@ -768,6 +869,18 @@ dependencies = ["sha2",]+[[package]]+name = "pin-project-lite"+version = "0.2.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"++[[package]]+name = "pin-utils"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"+[[package]]name = "powerfmt"version = "0.2.0"@@ -801,6 +914,15 @@ dependencies = ["termtree",]+[[package]]+name = "proc-macro-crate"+version = "3.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983"+dependencies = [+ "toml_edit 0.23.7",+]+[[package]]name = "proc-macro2"version = "1.0.101"@@ -865,6 +987,12 @@ version = "0.8.8"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"+[[package]]+name = "relative-path"+version = "1.9.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"+[[package]]name = "ron"version = "0.8.1"@@ -877,6 +1005,36 @@ dependencies = ["serde_derive",]+[[package]]+name = "rstest"+version = "0.23.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0a2c585be59b6b5dd66a9d2084aa1d8bd52fbdb806eafdeffb52791147862035"+dependencies = [+ "futures",+ "futures-timer",+ "rstest_macros",+ "rustc_version",+]++[[package]]+name = "rstest_macros"+version = "0.23.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "825ea780781b15345a146be27eaefb05085e337e869bff01b4306a4fd4a9ad5a"+dependencies = [+ "cfg-if",+ "glob",+ "proc-macro-crate",+ "proc-macro2",+ "quote",+ "regex",+ "relative-path",+ "rustc_version",+ "syn",+ "unicode-ident",+]+[[package]]name = "rust-ini"version = "0.20.0"@@ -893,6 +1051,15 @@ version = "2.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"+[[package]]+name = "rustc_version"+version = "0.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"+dependencies = [+ "semver",+]+[[package]]name = "rustix"version = "1.1.2"@@ -918,6 +1085,12 @@ version = "1.0.20"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"+[[package]]+name = "semver"+version = "1.0.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"+[[package]]name = "serde"version = "1.0.228"@@ -987,6 +1160,12 @@ version = "2.7.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa"+[[package]]+name = "slab"+version = "0.4.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"+[[package]]name = "strsim"version = "0.11.1"@@ -1093,8 +1272,8 @@ checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"dependencies = ["serde","serde_spanned",- "toml_datetime",- "toml_edit",+ "toml_datetime 0.6.11",+ "toml_edit 0.22.27",][[package]]@@ -1106,6 +1285,15 @@ dependencies = ["serde",]+[[package]]+name = "toml_datetime"+version = "0.7.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533"+dependencies = [+ "serde_core",+]+[[package]]name = "toml_edit"version = "0.22.27"@@ -1115,11 +1303,32 @@ dependencies = ["indexmap","serde","serde_spanned",- "toml_datetime",+ "toml_datetime 0.6.11","toml_write","winnow",]+[[package]]+name = "toml_edit"+version = "0.23.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d"+dependencies = [+ "indexmap",+ "toml_datetime 0.7.3",+ "toml_parser",+ "winnow",+]++[[package]]+name = "toml_parser"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e"+dependencies = [+ "winnow",+]+[[package]]name = "toml_write"version = "0.1.2"@@ -1478,6 +1687,7 @@ dependencies = ["directories","insta","insta-cmd",+ "rstest","serde","tempfile","toml",diff --git a/Cargo.toml b/Cargo.tomlindex 13128fa9d..1dfc7d195 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -28,3 +28,4 @@ insta-cmd = "0.6"assert_cmd = "2.0"tempfile = "3.14"toml = "0.8"+rstest = "0.23"diff --git a/tests/integration_tests/e2e_shell.rs b/tests/integration_tests/e2e_shell.rsindex 4d4278caf..c5c6b8515 100644--- a/tests/integration_tests/e2e_shell.rs+++ b/tests/integration_tests/e2e_shell.rs@@ -1,5 +1,6 @@use crate::common::TestRepo;use insta_cmd::get_cargo_bin;+use rstest::rstest;use std::process::Command;/// Helper to check if a shell is available on the system@@ -65,34 +66,46 @@ fn generate_init_code(repo: &TestRepo, shell: &str) -> String {String::from_utf8(output.stdout).expect("Invalid UTF-8 in init code")}-#[test]-fn test_bash_e2e_switch_changes_directory() {- if !is_shell_available("bash") {- eprintln!("Skipping test: bash not available");+/// Generate shell-specific PATH export syntax+fn path_export_syntax(shell: &str, bin_path: &str) -> String {+ match shell {+ "fish" => format!(r#"set -x PATH {} $PATH"#, bin_path),+ _ => format!(r#"export PATH="{}:$PATH""#, bin_path),+ }+}++#[rstest]+#[case("bash")]+#[case("fish")]+#[case("zsh")]+fn test_e2e_switch_changes_directory(#[case] shell: &str) {+ if !is_shell_available(shell) {+ eprintln!("Skipping test: {} not available", shell);return;}let repo = TestRepo::new();repo.commit("Initial commit");- let init_code = generate_init_code(&repo, "bash");+ let init_code = generate_init_code(&repo, shell);+ let bin_path = get_cargo_bin("wt")+ .parent()+ .unwrap()+ .to_string_lossy()+ .to_string();- // Create a script that:- // 1. Sources the init code- // 2. Runs wt switch to create and switch to a new branch- // 3. Prints the current directorylet script = format!(r#"- export PATH="{}:$PATH"+ {}{}wt switch --create my-featurepwd"#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),+ path_export_syntax(shell, &bin_path),init_code);- let output = execute_shell_script(&repo, "bash", &script);+ let output = execute_shell_script(&repo, shell, &script);// Verify that pwd shows we're in a worktree directory containing "my-feature"assert!(@@ -102,10 +115,13 @@ fn test_bash_e2e_switch_changes_directory() {);}-#[test]-fn test_bash_e2e_finish_returns_to_main() {- if !is_shell_available("bash") {- eprintln!("Skipping test: bash not available");+#[rstest]+#[case("bash")]+#[case("fish")]+#[case("zsh")]+fn test_e2e_finish_returns_to_main(#[case] shell: &str) {+ if !is_shell_available(shell) {+ eprintln!("Skipping test: {} not available", shell);return;}@@ -113,27 +129,27 @@ fn test_bash_e2e_finish_returns_to_main() {repo.commit("Initial commit");repo.setup_remote("main");- let init_code = generate_init_code(&repo, "bash");+ let init_code = generate_init_code(&repo, shell);let repo_path = repo.root_path().to_string_lossy().to_string();+ let bin_path = get_cargo_bin("wt")+ .parent()+ .unwrap()+ .to_string_lossy()+ .to_string();- // Create a script that:- // 1. Sources the init code- // 2. Switches to a feature branch- // 3. Finishes the feature (returns to main)- // 4. Prints the current directorylet script = format!(r#"- export PATH="{}:$PATH"+ {}{}wt switch --create my-featurewt finishpwd"#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),+ path_export_syntax(shell, &bin_path),init_code);- let output = execute_shell_script(&repo, "bash", &script);+ let output = execute_shell_script(&repo, shell, &script);// Verify that pwd shows we're back in the main repo directoryassert!(@@ -182,147 +198,6 @@ fn test_bash_e2e_switch_preserves_output() {);}-#[test]-fn test_fish_e2e_switch_changes_directory() {- if !is_shell_available("fish") {- eprintln!("Skipping test: fish not available");- return;- }-- let repo = TestRepo::new();- repo.commit("Initial commit");-- let init_code = generate_init_code(&repo, "fish");-- // Fish uses different syntax for sourcing code- let script = format!(- r#"- set -x PATH {} $PATH- {}- wt switch --create my-feature- pwd- "#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),- init_code- );-- let output = execute_shell_script(&repo, "fish", &script);-- // Verify that pwd shows we're in a worktree directory containing "my-feature"- assert!(- output.contains("my-feature"),- "Expected pwd to show my-feature worktree, got: {}",- output- );-}--#[test]-fn test_fish_e2e_finish_returns_to_main() {- if !is_shell_available("fish") {- eprintln!("Skipping test: fish not available");- return;- }-- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");-- let init_code = generate_init_code(&repo, "fish");- let repo_path = repo.root_path().to_string_lossy().to_string();-- let script = format!(- r#"- set -x PATH {} $PATH- {}- wt switch --create my-feature- wt finish- pwd- "#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),- init_code- );-- let output = execute_shell_script(&repo, "fish", &script);-- // Verify that pwd shows we're back in the main repo directory- assert!(- output.trim().ends_with(&repo_path),- "Expected pwd to show main repo at {}, got: {}",- repo_path,- output- );-}--#[test]-fn test_zsh_e2e_switch_changes_directory() {- if !is_shell_available("zsh") {- eprintln!("Skipping test: zsh not available");- return;- }-- let repo = TestRepo::new();- repo.commit("Initial commit");-- let init_code = generate_init_code(&repo, "zsh");-- let script = format!(- r#"- export PATH="{}:$PATH"- {}- wt switch --create my-feature- pwd- "#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),- init_code- );-- let output = execute_shell_script(&repo, "zsh", &script);-- // Verify that pwd shows we're in a worktree directory containing "my-feature"- assert!(- output.contains("my-feature"),- "Expected pwd to show my-feature worktree, got: {}",- output- );-}--#[test]-fn test_zsh_e2e_finish_returns_to_main() {- if !is_shell_available("zsh") {- eprintln!("Skipping test: zsh not available");- return;- }-- let mut repo = TestRepo::new();- repo.commit("Initial commit");- repo.setup_remote("main");-- let init_code = generate_init_code(&repo, "zsh");- let repo_path = repo.root_path().to_string_lossy().to_string();-- let script = format!(- r#"- export PATH="{}:$PATH"- {}- wt switch --create my-feature- wt finish- pwd- "#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),- init_code- );-- let output = execute_shell_script(&repo, "zsh", &script);-- // Verify that pwd shows we're back in the main repo directory- assert!(- output.trim().ends_with(&repo_path),- "Expected pwd to show main repo at {}, got: {}",- repo_path,- output- );-}-#[test]fn test_bash_e2e_custom_prefix() {if !is_shell_available("bash") {@@ -402,10 +277,12 @@ fn test_bash_e2e_error_handling() {);}-#[test]-fn test_bash_e2e_prompt_hook() {- if !is_shell_available("bash") {- eprintln!("Skipping test: bash not available");+#[rstest]+#[case("bash")]+#[case("fish")]+fn test_e2e_prompt_hook(#[case] shell: &str) {+ if !is_shell_available(shell) {+ eprintln!("Skipping test: {} not available", shell);return;}@@ -416,78 +293,32 @@ fn test_bash_e2e_prompt_hook() {let mut cmd = Command::new(get_cargo_bin("wt"));repo.clean_cli_env(&mut cmd);let output = cmd- .args(["init", "bash", "--hook", "prompt"])+ .args(["init", shell, "--hook", "prompt"]).current_dir(repo.root_path()).output().expect("Failed to generate init code");let init_code = String::from_utf8(output.stdout).expect("Invalid UTF-8");+ let bin_path = get_cargo_bin("wt")+ .parent()+ .unwrap()+ .to_string_lossy()+ .to_string();// Verify prompt hook function exists and can be calledlet script = format!(r#"- export PATH="{}:$PATH"{}- type _wt_prompt_hook 2>&1- _wt_prompt_hook 2>&1- echo "HOOK_EXECUTED"- "#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),- init_code- );-- let output = execute_shell_script(&repo, "bash", &script);-- // Verify hook function exists- assert!(- output.contains("_wt_prompt_hook is a function") || output.contains("function"),- "Expected prompt hook function to be defined, got: {}",- output- );-- // Verify hook executed successfully- assert!(- output.contains("HOOK_EXECUTED"),- "Expected prompt hook to execute without error, got: {}",- output- );-}--#[test]-fn test_fish_e2e_prompt_hook() {- if !is_shell_available("fish") {- eprintln!("Skipping test: fish not available");- return;- }-- let repo = TestRepo::new();- repo.commit("Initial commit");-- // Generate init code with prompt hook- let mut cmd = Command::new(get_cargo_bin("wt"));- repo.clean_cli_env(&mut cmd);- let output = cmd- .args(["init", "fish", "--hook", "prompt"])- .current_dir(repo.root_path())- .output()- .expect("Failed to generate init code");-- let init_code = String::from_utf8(output.stdout).expect("Invalid UTF-8");-- // Verify prompt hook function exists and can be called- let script = format!(- r#"- set -x PATH {} $PATH{}type _wt_prompt_hook 2>&1_wt_prompt_hook 2>&1echo "HOOK_EXECUTED""#,- get_cargo_bin("wt").parent().unwrap().to_string_lossy(),+ path_export_syntax(shell, &bin_path),init_code);- let output = execute_shell_script(&repo, "fish", &script);+ let output = execute_shell_script(&repo, shell, &script);// Verify hook function existsassert!(