Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Consolidate test helpers and reduce test LOC (#342)
Maximilian Roos71899684eddf
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex f3d53395b..c8b29185c 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -36,7 +36,6 @@ repos:- --config=.config/lychee.toml# Root dir for resolving absolute paths like /assets/...- --root-dir=docs/static- - -q- repo: localhooks:- id: cargo-lockdiff --git a/tests/common/list_snapshots.rs b/tests/common/list_snapshots.rsindex d182b3d13..7cc9c6d67 100644--- a/tests/common/list_snapshots.rs+++ b/tests/common/list_snapshots.rs@@ -32,87 +32,8 @@ pub fn command_readme(repo: &TestRepo, cwd: &Path) -> Command {cmd}-pub fn command_json(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.arg("--format=json");- cmd-}--pub fn command_branches(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.arg("--branches");- cmd-}-pub fn command_with_width(repo: &TestRepo, width: usize) -> Command {let mut cmd = command(repo, repo.root_path());cmd.env("COLUMNS", width.to_string());cmd}--pub fn command_progressive(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.arg("--progressive");- cmd-}--pub fn command_no_progressive(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.arg("--no-progressive");- cmd-}--pub fn command_progressive_json(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.args(["--progressive", "--format=json"]);- cmd-}--pub fn command_remotes(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.arg("--remotes");- cmd-}--pub fn command_branches_and_remotes(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.args(["--branches", "--remotes"]);- cmd-}--pub fn command_no_progressive_json(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.args(["--no-progressive", "--format=json"]);- cmd-}--pub fn command_progressive_branches(repo: &TestRepo) -> Command {- let mut cmd = command(repo, repo.root_path());- cmd.args(["--progressive", "--branches"]);- cmd-}--pub fn command_progressive_full(repo: &TestRepo) -> Command {- let mut cmd = command_progressive(repo);- cmd.arg("--full");- cmd-}--pub fn command_progressive_from_dir(repo: &TestRepo, cwd: &Path) -> Command {- let mut cmd = wt_command();- repo.configure_wt_cmd(&mut cmd);- cmd.args(["list", "--progressive"]).current_dir(cwd);- cmd-}--pub fn command_readme_full_from_dir(repo: &TestRepo, cwd: &Path) -> Command {- let mut cmd = command_readme(repo, cwd);- cmd.arg("--full");- cmd-}--pub fn command_readme_branches_full_from_dir(repo: &TestRepo, cwd: &Path) -> Command {- let mut cmd = command_readme(repo, cwd);- cmd.args(["--branches", "--full"]);- cmd-}diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rsindex 5d3ad5337..f30b98769 100644--- a/tests/integration_tests/bare_repository.rs+++ b/tests/integration_tests/bare_repository.rs@@ -574,19 +574,6 @@ impl NestedBareRepoTest {.env_remove("NO_COLOR").env_remove("CLICOLOR_FORCE");}-- /// Create a commit in a worktree- fn commit(&self, worktree: &Path, message: &str) {- fs::write(worktree.join("file.txt"), message).unwrap();- self.git_command(worktree)- .args(["add", "."])- .output()- .unwrap();- self.git_command(worktree)- .args(["commit", "-m", message])- .output()- .unwrap();- }}impl TestRepoBase for NestedBareRepoTest {@@ -651,7 +638,7 @@ fn test_nested_bare_repo_full_workflow() {let main_worktree = test.project_path().join("main");assert!(main_worktree.exists(), "Main worktree should exist");- test.commit(&main_worktree, "Initial");+ test.commit_in(&main_worktree, "Initial");// Create feature worktreelet (directive_path, _guard) = directive_file();@@ -710,7 +697,7 @@ fn test_nested_bare_repo_list_snapshot() {cmd.output().unwrap();let main_worktree = test.project_path().join("main");- test.commit(&main_worktree, "Initial");+ test.commit_in(&main_worktree, "Initial");// Create feature worktreelet (directive_path, _guard) = directive_file();diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex 4b53790fc..36d07bb83 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -25,35 +25,27 @@ fn snapshot_list_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {}fn snapshot_list_json(test_name: &str, repo: &TestRepo) {- run_snapshot(- list_snapshots::json_settings(repo),- test_name,- list_snapshots::command_json(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.arg("--format=json");+ run_snapshot(list_snapshots::json_settings(repo), test_name, cmd);}fn snapshot_list_with_branches(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_branches(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.arg("--branches");+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_with_remotes(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_remotes(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.arg("--remotes");+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_with_branches_and_remotes(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_branches_and_remotes(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.args(["--branches", "--remotes"]);+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_full(test_name: &str, repo: &TestRepo) {@@ -63,35 +55,27 @@ fn snapshot_list_full(test_name: &str, repo: &TestRepo) {}fn snapshot_list_progressive(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_progressive(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.arg("--progressive");+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_no_progressive(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_no_progressive(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.arg("--no-progressive");+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_progressive_branches(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_progressive_branches(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.args(["--progressive", "--branches"]);+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_list_progressive_full(test_name: &str, repo: &TestRepo) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_progressive_full(repo),- );+ let mut cmd = list_snapshots::command(repo, repo.root_path());+ cmd.args(["--progressive", "--full"]);+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}// README example snapshots - use narrower width for doc site code blocks@@ -104,19 +88,15 @@ fn snapshot_readme_list_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {}fn snapshot_readme_list_full_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_readme_full_from_dir(repo, cwd),- );+ let mut cmd = list_snapshots::command_readme(repo, cwd);+ cmd.arg("--full");+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn snapshot_readme_list_branches_full_from_dir(test_name: &str, repo: &TestRepo, cwd: &Path) {- run_snapshot(- setup_snapshot_settings(repo),- test_name,- list_snapshots::command_readme_branches_full_from_dir(repo, cwd),- );+ let mut cmd = list_snapshots::command_readme(repo, cwd);+ cmd.args(["--branches", "--full"]);+ run_snapshot(setup_snapshot_settings(repo), test_name, cmd);}fn run_snapshot(settings: Settings, test_name: &str, mut cmd: Command) {@@ -1746,10 +1726,12 @@ fn test_list_task_dag_ordering_stability(mut repo: TestRepo) {// Run from feature-current worktree// Expected order: main, feature-current, then by timestamp: feature-newest, feature-middle, feature-oldest+ let mut cmd = list_snapshots::command(&repo, ¤t_path);+ cmd.arg("--progressive");run_snapshot(setup_snapshot_settings(&repo),"task_dag_ordering_stability",- list_snapshots::command_progressive_from_dir(&repo, ¤t_path),+ cmd,);}@@ -1773,13 +1755,17 @@ fn test_list_progressive_vs_buffered_identical_data(mut repo: TestRepo) {std::fs::write(feature_a_path.join("changes.txt"), "test").unwrap();// Run both modes with JSON output to compare data (not formatting)- let progressive_output = list_snapshots::command_progressive_json(&repo)- .output()- .unwrap();+ let progressive_output = {+ let mut cmd = list_snapshots::command(&repo, repo.root_path());+ cmd.args(["--progressive", "--format=json"]);+ cmd.output().unwrap()+ };- let buffered_output = list_snapshots::command_no_progressive_json(&repo)- .output()- .unwrap();+ let buffered_output = {+ let mut cmd = list_snapshots::command(&repo, repo.root_path());+ cmd.args(["--no-progressive", "--format=json"]);+ cmd.output().unwrap()+ };// Both should succeedassert!(