(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func 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 | |
| 81 | func TestPassesWithNoHooks(t *testing.T) { |
| 82 | tempDir := initGitForPreCommit(t) |
nothing calls this directly
no test coverage detected