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

Function not_a_git_repo

tests/misc.rs:38–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36
37#[test]
38fn not_a_git_repo() {
39 // Create a directory in the system temp location to avoid finding parent git repos
40 let temp_dir = std::env::temp_dir();
41 let path_to_non_git_dir = temp_dir.join("git_chain_test_not_a_repo");
42
43 // Create a directory that is NOT a git repository
44 fs::remove_dir_all(&path_to_non_git_dir).ok();
45 fs::create_dir_all(&path_to_non_git_dir).unwrap();
46
47 // Run git chain in the non-git directory
48 let args: Vec<String> = vec![];
49 let output = run_test_bin_expect_err(&path_to_non_git_dir, args);
50
51 let stdout = String::from_utf8_lossy(&output.stdout);
52 let stderr = String::from_utf8_lossy(&output.stderr);
53
54 // Diagnostic printing
55 println!("=== TEST DIAGNOSTICS ===");
56 println!("Test directory: {:?}", path_to_non_git_dir);
57 println!("STDOUT: {}", stdout);
58 println!("STDERR: {}", stderr);
59 println!("EXIT STATUS: {}", output.status);
60 println!("Is directory a git repo: false (intentional test condition)");
61 println!("======");
62
63 // Uncomment to stop test execution and inspect state with captured output
64 // assert!(false, "DEBUG STOP: not_a_git_repo test section");
65 // assert!(false, "stdout: {}", stdout);
66 // assert!(false, "stderr: {}", stderr);
67 // assert!(false, "status code: {}", output.status.code().unwrap_or(0));
68
69 // Specific assertions based on expected behavior
70 assert!(
71 !output.status.success(),
72 "Command should fail when run in non-git directory"
73 );
74 assert!(
75 stderr.contains("Not a git repository"),
76 "Error message should mention 'Not a git repository', got: {}",
77 stderr
78 );
79 assert!(
80 stderr.contains("This command must be run inside a git repository"),
81 "Error message should provide helpful hint, got: {}",
82 stderr
83 );
84
85 // Clean up
86 fs::remove_dir_all(&path_to_non_git_dir).ok();
87}

Callers

nothing calls this directly

Calls 1

run_test_bin_expect_errFunction · 0.85

Tested by

no test coverage detected