TestBareHeyShowsHelpWithoutTTY verifies that bare `hey` falls back to help when either stdin or stdout is not a terminal (e.g. `hey | head`, cron, CI pipelines). In test context neither fd is a TTY, covering both gates.
(t *testing.T)
| 13 | // when either stdin or stdout is not a terminal (e.g. `hey | head`, cron, |
| 14 | // CI pipelines). In test context neither fd is a TTY, covering both gates. |
| 15 | func TestBareHeyShowsHelpWithoutTTY(t *testing.T) { |
| 16 | root := newRootCmd() |
| 17 | var buf bytes.Buffer |
| 18 | root.SetOut(&buf) |
| 19 | root.SetArgs([]string{}) |
| 20 | |
| 21 | if err := root.Execute(); err != nil { |
| 22 | t.Fatalf("bare hey: %v", err) |
| 23 | } |
| 24 | |
| 25 | out := buf.String() |
| 26 | if !strings.Contains(out, "USAGE") { |
| 27 | t.Errorf("expected help output with USAGE, got:\n%s", out) |
| 28 | } |
| 29 | if !strings.Contains(out, "hey <command>") { |
| 30 | t.Errorf("expected help to mention 'hey <command>', got:\n%s", out) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestWriteOKIncludesStats(t *testing.T) { |
| 35 | oldWriter, oldStats, oldSDKStats := writer, statsFlag, sdkStats |
nothing calls this directly
no test coverage detected