Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Refactor test helpers to remove redundant wrapper functions

Maximilian Roosb256f876dfb6
diff --git a/tests/common/list_snapshots.rs b/tests/common/list_snapshots.rs
index 7bd272b58..29724c6fc 100644
--- a/tests/common/list_snapshots.rs
+++ b/tests/common/list_snapshots.rs
@@ -3,10 +3,6 @@ use insta::Settings;
use std::path::Path;
use std::process::Command;
-pub fn standard_settings(repo: &TestRepo) -> Settings {
- setup_snapshot_settings(repo)
-}
-
pub fn json_settings(repo: &TestRepo) -> Settings {
let mut settings = setup_snapshot_settings(repo);
// JSON-specific filters for timestamps and escaped ANSI codes
@@ -96,29 +92,19 @@ pub fn command_progressive_branches(repo: &TestRepo) -> Command {
cmd
}
-pub fn command_task_dag(repo: &TestRepo) -> Command {
- // Task DAG is now the default for progressive mode
- command_progressive(repo)
-}
-
-pub fn command_task_dag_full(repo: &TestRepo) -> Command {
- let mut cmd = command_task_dag(repo);
+pub fn command_progressive_full(repo: &TestRepo) -> Command {
+ let mut cmd = command_progressive(repo);
cmd.arg("--full");
cmd
}
-pub fn command_task_dag_from_dir(repo: &TestRepo, cwd: &Path) -> Command {
+pub fn command_progressive_from_dir(repo: &TestRepo, cwd: &Path) -> Command {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.args(["list", "--progressive"]).current_dir(cwd);
cmd
}
-// README example commands - use narrower width for doc site code blocks
-pub fn command_readme_from_dir(repo: &TestRepo, cwd: &Path) -> Command {
- command_readme(repo, cwd)
-}
-
pub fn command_readme_full_from_dir(repo: &TestRepo, cwd: &Path) -> Command {
let mut cmd = command_readme(repo, cwd);
cmd.arg("--full");
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index d18fef678..faebfb01e 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -8,7 +8,7 @@ use std::process::Command;
fn snapshot_list(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command(repo, repo.root_path()),
);
@@ -16,7 +16,7 @@ fn snapshot_list(test_name: &str, repo: &TestRepo) {
fn snapshot_list_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command(repo, cwd),
);
@@ -32,7 +32,7 @@ fn snapshot_list_json(test_name: &str, repo: &TestRepo) {
fn snapshot_list_with_branches(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_branches(repo),
);
@@ -40,7 +40,7 @@ fn snapshot_list_with_branches(test_name: &str, repo: &TestRepo) {
fn snapshot_list_with_remotes(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_remotes(repo),
);
@@ -48,7 +48,7 @@ fn snapshot_list_with_remotes(test_name: &str, repo: &TestRepo) {
fn snapshot_list_with_branches_and_remotes(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_branches_and_remotes(repo),
);
@@ -56,7 +56,7 @@ fn snapshot_list_with_branches_and_remotes(test_name: &str, repo: &TestRepo) {
fn snapshot_list_progressive(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_progressive(repo),
);
@@ -64,7 +64,7 @@ fn snapshot_list_progressive(test_name: &str, repo: &TestRepo) {
fn snapshot_list_no_progressive(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_no_progressive(repo),
);
@@ -72,40 +72,32 @@ fn snapshot_list_no_progressive(test_name: &str, repo: &TestRepo) {
fn snapshot_list_progressive_branches(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_progressive_branches(repo),
);
}
-fn snapshot_list_task_dag(test_name: &str, repo: &TestRepo) {
+fn snapshot_list_progressive_full(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
- list_snapshots::command_task_dag(repo),
- );
-}
-
-fn snapshot_list_task_dag_full(test_name: &str, repo: &TestRepo) {
- run_snapshot(
- list_snapshots::standard_settings(repo),
- test_name,
- list_snapshots::command_task_dag_full(repo),
+ list_snapshots::command_progressive_full(repo),
);
}
// README example snapshots - use narrower width for doc site code blocks
fn snapshot_readme_list_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
- list_snapshots::command_readme_from_dir(repo, cwd),
+ list_snapshots::command_readme(repo, cwd),
);
}
fn snapshot_readme_list_full_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_readme_full_from_dir(repo, cwd),
);
@@ -113,7 +105,7 @@ fn snapshot_readme_list_full_from_dir(test_name: &str, repo: &TestRepo, cwd: &Pa
fn snapshot_readme_list_branches_full_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_readme_branches_full_from_dir(repo, cwd),
);
@@ -1930,7 +1922,7 @@ fn test_list_progressive_with_branches() {
fn test_list_task_dag_single_worktree() {
let repo = TestRepo::new();
- snapshot_list_task_dag("task_dag_single_worktree", &repo);
+ snapshot_list_progressive("task_dag_single_worktree", &repo);
}
#[test]
@@ -1941,7 +1933,7 @@ fn test_list_task_dag_multiple_worktrees() {
repo.add_worktree("feature-b");
repo.add_worktree("feature-c");
- snapshot_list_task_dag("task_dag_multiple_worktrees", &repo);
+ snapshot_list_progressive("task_dag_multiple_worktrees", &repo);
}
#[test]
@@ -1968,7 +1960,7 @@ fn test_list_task_dag_full_with_diffs() {
.output()
.unwrap();
- snapshot_list_task_dag_full("task_dag_full_with_diffs", &repo);
+ snapshot_list_progressive_full("task_dag_full_with_diffs", &repo);
}
#[test]
@@ -2005,7 +1997,7 @@ fn test_list_task_dag_with_upstream() {
.output()
.unwrap();
- snapshot_list_task_dag_full("task_dag_with_upstream", &repo);
+ snapshot_list_progressive_full("task_dag_with_upstream", &repo);
}
#[test]
@@ -2017,7 +2009,7 @@ fn test_list_task_dag_many_worktrees() {
repo.add_worktree(&format!("feature-{}", i));
}
- snapshot_list_task_dag("task_dag_many_worktrees", &repo);
+ snapshot_list_progressive("task_dag_many_worktrees", &repo);
}
#[test]
@@ -2028,7 +2020,7 @@ fn test_list_task_dag_with_locked_worktree() {
repo.add_worktree("locked");
repo.lock_worktree("locked", Some("Testing task DAG with locked worktree"));
- snapshot_list_task_dag("task_dag_with_locked", &repo);
+ snapshot_list_progressive("task_dag_with_locked", &repo);
}
#[test]
@@ -2036,7 +2028,7 @@ fn test_list_task_dag_detached_head() {
let repo = TestRepo::new();
repo.detach_head();
- snapshot_list_task_dag("task_dag_detached_head", &repo);
+ snapshot_list_progressive("task_dag_detached_head", &repo);
}
#[test]
@@ -2049,9 +2041,9 @@ fn test_list_task_dag_ordering_stability() {
// Run from feature-current worktree
// Expected order: main, feature-current, then by timestamp: feature-newest, feature-middle, feature-oldest
run_snapshot(
- list_snapshots::standard_settings(&repo),
+ setup_snapshot_settings(&repo),
"task_dag_ordering_stability",
- list_snapshots::command_task_dag_from_dir(&repo, &current_path),
+ list_snapshots::command_progressive_from_dir(&repo, &current_path),
);
}
@@ -2122,7 +2114,7 @@ fn test_list_with_c_flag() {
repo.add_worktree("feature-b");
// Run wt -C <repo_path> list from a completely different directory
- let mut settings = list_snapshots::standard_settings(&repo);
+ let mut settings = setup_snapshot_settings(&repo);
// Redact the -C path argument in metadata (try different selector formats)
settings.add_redaction(".args[1]", "[REPO_PATH]");
settings.bind(|| {
@@ -2516,7 +2508,7 @@ fn test_list_maximum_status_with_git_operation() {
// Result should show: ?!+ (working_tree) + = (conflicts) + ↻ (rebase) + ↕ (diverged) + ⊠ (locked) + 🤖 (user marker)
// Use --full to enable conflict detection
- let settings = list_snapshots::standard_settings(&repo);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = list_snapshots::command(&repo, repo.root_path());
cmd.arg("--full");
@@ -2682,7 +2674,7 @@ fn test_list_maximum_status_symbols() {
.unwrap();
// Result should show 11 chars: ?!+»✘=⊠↕⇅🤖
- let settings = list_snapshots::standard_settings(&repo);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = list_snapshots::command(&repo, repo.root_path());
cmd.arg("--full");
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index 81e35e647..207be2696 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -28,14 +28,9 @@ fn snapshot_remove_with_global_flags(
});
}
-/// Common setup for remove tests - creates repo with initial commit and remote
-fn setup_remove_repo() -> TestRepo {
- TestRepo::new()
-}
-
#[test]
fn test_remove_already_on_default() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Already on main branch
snapshot_remove("remove_already_on_default", &repo, &[], None);
@@ -43,7 +38,7 @@ fn test_remove_already_on_default() {
#[test]
fn test_remove_switch_to_default() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create and switch to a feature branch in the main repo
let mut cmd = Command::new("git");
@@ -58,7 +53,7 @@ fn test_remove_switch_to_default() {
#[test]
fn test_remove_from_worktree() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-wt");
@@ -68,7 +63,7 @@ fn test_remove_from_worktree() {
#[test]
fn test_remove_internal_mode() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-internal");
@@ -83,7 +78,7 @@ fn test_remove_internal_mode() {
#[test]
fn test_remove_dirty_working_tree() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create a dirty file
std::fs::write(repo.root_path().join("dirty.txt"), "uncommitted changes").unwrap();
@@ -93,7 +88,7 @@ fn test_remove_dirty_working_tree() {
#[test]
fn test_remove_by_name_from_main() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create a worktree
let _worktree_path = repo.add_worktree("feature-a");
@@ -104,7 +99,7 @@ fn test_remove_by_name_from_main() {
#[test]
fn test_remove_by_name_from_other_worktree() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create two worktrees
let worktree_a = repo.add_worktree("feature-a");
@@ -121,7 +116,7 @@ fn test_remove_by_name_from_other_worktree() {
#[test]
fn test_remove_current_by_name() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-current");
@@ -136,7 +131,7 @@ fn test_remove_current_by_name() {
#[test]
fn test_remove_nonexistent_worktree() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Try to remove a worktree that doesn't exist
snapshot_remove("remove_nonexistent_worktree", &repo, &["nonexistent"], None);
@@ -144,7 +139,7 @@ fn test_remove_nonexistent_worktree() {
#[test]
fn test_remove_remote_only_branch() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
repo.setup_remote("main"); // This test specifically needs a remote
// Create a remote-only branch by pushing a branch then deleting it locally
@@ -183,7 +178,7 @@ fn test_remove_remote_only_branch() {
#[test]
fn test_remove_by_name_dirty_target() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-dirty");
@@ -201,7 +196,7 @@ fn test_remove_by_name_dirty_target() {
#[test]
fn test_remove_multiple_worktrees() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create three worktrees
let _worktree_a = repo.add_worktree("feature-a");
@@ -219,7 +214,7 @@ fn test_remove_multiple_worktrees() {
#[test]
fn test_remove_multiple_including_current() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create three worktrees
let worktree_a = repo.add_worktree("feature-a");
@@ -237,7 +232,7 @@ fn test_remove_multiple_including_current() {
#[test]
fn test_remove_branch_not_fully_merged() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create a worktree with an unmerged commit
let worktree_path = repo.add_worktree("feature-unmerged");
@@ -265,7 +260,7 @@ fn test_remove_branch_not_fully_merged() {
#[test]
fn test_remove_foreground() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create a worktree
let _worktree_path = repo.add_worktree("feature-fg");
@@ -281,7 +276,7 @@ fn test_remove_foreground() {
#[test]
fn test_remove_no_delete_branch() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create a worktree
let _worktree_path = repo.add_worktree("feature-keep");
@@ -297,7 +292,7 @@ fn test_remove_no_delete_branch() {
#[test]
fn test_remove_branch_only_merged() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create a branch from main without a worktree (already merged)
repo.git_command(&["branch", "feature-merged"])
@@ -315,7 +310,7 @@ fn test_remove_branch_only_merged() {
#[test]
fn test_remove_branch_only_unmerged() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create a branch with a unique commit (not in main)
repo.git_command(&["branch", "feature-unmerged"])
@@ -345,7 +340,7 @@ fn test_remove_branch_only_unmerged() {
#[test]
fn test_remove_branch_only_force_delete() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create a branch with a unique commit (not in main)
repo.git_command(&["branch", "feature-force"])
@@ -378,7 +373,7 @@ fn test_remove_branch_only_force_delete() {
/// using path-based removal (no branch deletion).
#[test]
fn test_remove_from_detached_head_in_worktree() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-detached");
@@ -400,7 +395,7 @@ fn test_remove_from_detached_head_in_worktree() {
/// without branch deletion. The `@` symbol refers to the current worktree.
#[test]
fn test_remove_at_from_detached_head_in_worktree() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
let worktree_path = repo.add_worktree("feature-detached-at");
@@ -425,7 +420,7 @@ fn test_remove_at_from_detached_head_in_worktree() {
/// - Branch should be deleted because content is integrated
#[test]
fn test_remove_branch_matching_tree_content() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create a feature branch from main
repo.git_command(&["branch", "feature-squashed"])
@@ -500,7 +495,7 @@ fn test_remove_branch_matching_tree_content() {
#[test]
#[cfg_attr(windows, ignore)]
fn test_remove_main_worktree_vs_linked_worktree() {
- let mut repo = setup_remove_repo();
+ let mut repo = TestRepo::new();
// Create a linked worktree
let linked_wt_path = repo.add_worktree("feature");
@@ -679,7 +674,7 @@ fn test_remove_default_branch_no_tautology() {
/// produces the same tree as main, meaning merging feature would add nothing.
#[test]
fn test_remove_squash_merged_then_main_advanced() {
- let repo = setup_remove_repo();
+ let repo = TestRepo::new();
// Create feature branch
repo.git_command(&["checkout", "-b", "feature-squash"])
diff --git a/tests/integration_tests/spacing_edge_cases.rs b/tests/integration_tests/spacing_edge_cases.rs
index 20b0ca680..578162317 100644
--- a/tests/integration_tests/spacing_edge_cases.rs
+++ b/tests/integration_tests/spacing_edge_cases.rs
@@ -1,11 +1,11 @@
-use crate::common::{TestRepo, list_snapshots};
+use crate::common::{TestRepo, list_snapshots, setup_snapshot_settings};
use insta::Settings;
use insta_cmd::assert_cmd_snapshot;
use std::process::Command;
fn snapshot_list(test_name: &str, repo: &TestRepo) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command(repo, repo.root_path()),
);
@@ -13,7 +13,7 @@ fn snapshot_list(test_name: &str, repo: &TestRepo) {
fn snapshot_list_with_width(test_name: &str, repo: &TestRepo, width: usize) {
run_snapshot(
- list_snapshots::standard_settings(repo),
+ setup_snapshot_settings(repo),
test_name,
list_snapshots::command_with_width(repo, width),
);
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index d24e4d87d..12047b784 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -58,10 +58,6 @@ fn run_statusline(repo: &TestRepo, args: &[&str], stdin_json: Option<&str>) -> S
// --- Test Fixtures ---
-fn setup_basic_repo() -> TestRepo {
- TestRepo::new()
-}
-
fn setup_repo_with_changes() -> TestRepo {
let repo = TestRepo::new();
@@ -105,7 +101,7 @@ fn setup_repo_with_commits_ahead() -> TestRepo {
#[test]
fn test_statusline_basic() {
- let repo = setup_basic_repo();
+ let repo = TestRepo::new();
let output = run_statusline(&repo, &[], None);
assert_snapshot!(output, @"main ^");
}
@@ -177,7 +173,7 @@ fn test_statusline_claude_code_full_context() {
#[test]
#[cfg_attr(windows, ignore)]
fn test_statusline_claude_code_minimal() {
- let repo = setup_basic_repo();
+ let repo = TestRepo::new();
let json = format!(
r#"{{"workspace": {{"current_dir": "{}"}}}}"#,
@@ -194,7 +190,7 @@ fn test_statusline_claude_code_minimal() {
#[test]
#[cfg_attr(windows, ignore)]
fn test_statusline_claude_code_with_model() {
- let repo = setup_basic_repo();
+ let repo = TestRepo::new();
let json = format!(
r#"{{