MCPcopy Create free account
hub / github.com/dirk/quickhook / TestFailingHookWithPty

Function TestFailingHookWithPty

hooks/pre_commit_test.go:39–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37}
38
39func TestFailingHookWithPty(t *testing.T) {
40 ptyTests := []struct {
41 name string
42 arg []string
43 out string
44 }{
45 {
46 "no args",
47 []string{},
48 "\x1b[31mfails\x1b[0m: first line\r\n\x1b[31mfails\x1b[0m: second line\r\n",
49 },
50 {
51 "no-color arg",
52 []string{"--no-color"},
53 "fails: first line\r\nfails: second line\r\n",
54 },
55 }
56 for _, tt := range ptyTests {
57 t.Run(tt.name, func(t *testing.T) {
58 tempDir := initGitForPreCommit(t)
59 tempDir.MkdirAll(".quickhook", "pre-commit")
60 tempDir.WriteFile(
61 []string{".quickhook", "pre-commit", "fails"},
62 "#!/bin/bash \n printf \"first line\\nsecond line\\n\" \n exit 1",
63 )
64
65 cmd := tempDir.NewCommand(
66 tempDir.Quickhook,
67 append([]string{"hook", "pre-commit"}, tt.arg...)...,
68 )
69 f, err := pty.Start(cmd)
70 require.NoError(t, err)
71 defer func() { _ = f.Close() }()
72
73 var b bytes.Buffer
74 io.Copy(&b, f)
75
76 assert.Equal(t, tt.out, b.String())
77 })
78 }
79}
80
81func TestPassesWithNoHooks(t *testing.T) {
82 tempDir := initGitForPreCommit(t)

Callers

nothing calls this directly

Calls 5

initGitForPreCommitFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
NewCommandMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected