MCPcopy Create free account
hub / github.com/cli/cli / TestOutputReturnsGitError

Function TestOutputReturnsGitError

git/command_test.go:47–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestOutputReturnsGitError(t *testing.T) {
48 // Given a command that fails with Git's not-a-repository diagnostic
49 stderr := "fatal: not a git repository (or any of the parent directories): .git"
50 cmd := createCommand(t, 128, "", stderr)
51 command := Command{cmd}
52
53 // When its output is captured
54 out, err := command.Output()
55
56 // Then the exit status and diagnostic are preserved in a Git error
57 require.Error(t, err)
58 var gitErr *GitError
59 require.ErrorAs(t, err, &gitErr)
60 assert.Equal(t, 128, gitErr.ExitCode)
61 assert.Equal(t, stderr, gitErr.Stderr)
62 require.EqualError(t, gitErr, "failed to run git: "+stderr)
63 assert.Empty(t, out)
64}
65
66func TestWithRepoDirInsertsRepositoryBeforeGitArguments(t *testing.T) {
67 // Given a Git command with a final -C operand after the argument separator

Callers

nothing calls this directly

Calls 5

OutputMethod · 0.95
createCommandFunction · 0.85
EqualMethod · 0.80
EmptyMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected