MCPcopy Create free account
hub / github.com/dashed/git-chain / test_gh_cli_not_installed

Function test_gh_cli_not_installed

tests/pr.rs:354–412  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

352
353#[test]
354fn test_gh_cli_not_installed() {
355 let test_name = "test_gh_not_installed";
356 let repo = setup_git_repo(test_name);
357 let path_to_repo = generate_path_to_repo(test_name);
358
359 // Create initial commit on main branch
360 create_new_file(&path_to_repo, "README.md", "Initial commit");
361 first_commit_all(&repo, "Initial commit");
362
363 // Rename master to main
364 {
365 let mut master_branch = repo.find_branch("master", git2::BranchType::Local).unwrap();
366 master_branch.rename("main", false).unwrap();
367 }
368
369 // Create a branch and initialize chain
370 create_branch(&repo, "feature-1");
371 checkout_branch(&repo, "feature-1");
372 create_new_file(&path_to_repo, "feature.txt", "Feature");
373 commit_all(&repo, "Add feature");
374 run_test_bin_expect_ok(&path_to_repo, ["init", "test-chain", "main"]);
375
376 // Create a directory without gh in PATH
377 let empty_dir = path_to_repo.join("empty_bin");
378 fs::create_dir_all(&empty_dir).unwrap();
379
380 // Set PATH to only include the empty directory
381 let original_path = env::var("PATH").unwrap_or_default();
382 let absolute_empty_dir = empty_dir.canonicalize().unwrap();
383 env::set_var("PATH", absolute_empty_dir.display().to_string());
384
385 // Run pr command - should fail
386 let output = run_test_bin(&path_to_repo, ["pr"]);
387
388 // Restore original PATH
389 env::set_var("PATH", original_path);
390
391 let stderr = String::from_utf8_lossy(&output.stderr);
392
393 // Debug output
394 println!("=== TEST DIAGNOSTICS ===");
395 println!("STDERR: {}", stderr);
396 println!("EXIT STATUS: {}", output.status);
397 println!("======");
398
399 // Assertions - the command should fail when gh is not installed
400 assert!(
401 !output.status.success(),
402 "Command should fail when gh is not installed"
403 );
404 assert!(
405 stderr.contains("GitHub CLI (gh) is not installed")
406 || stderr.contains("not found in the PATH"),
407 "Should show error about gh not being installed, got: {}",
408 stderr
409 );
410
411 teardown_git_repo(test_name);

Callers

nothing calls this directly

Calls 11

setup_git_repoFunction · 0.85
generate_path_to_repoFunction · 0.85
create_new_fileFunction · 0.85
first_commit_allFunction · 0.85
create_branchFunction · 0.85
checkout_branchFunction · 0.85
commit_allFunction · 0.85
run_test_bin_expect_okFunction · 0.85
run_test_binFunction · 0.85
teardown_git_repoFunction · 0.85
renameMethod · 0.80

Tested by

no test coverage detected