diff options
Diffstat (limited to 'cmd/krino/commands_test.go')
| -rw-r--r-- | cmd/krino/commands_test.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cmd/krino/commands_test.go b/cmd/krino/commands_test.go index 2156da2..b8364e6 100644 --- a/cmd/krino/commands_test.go +++ b/cmd/krino/commands_test.go @@ -9,7 +9,13 @@ import ( "testing" ) -// home gives each test its own HOME with no XDG overrides. +// home gives each test its own HOME with no XDG overrides, and points the +// package's stdin seam at something guaranteed non-terminal (fix round +// 2026-09-12/item 4): every test that reaches cmdSort's terminal check or +// the interactive review must not depend on what the ambient test binary's +// stdin happens to be - if that were ever a real terminal, such a test +// would silently fall through to the interactive prompt and block on a +// keypress instead of failing. func home(t *testing.T) string { t.Helper() h := t.TempDir() @@ -17,9 +23,24 @@ func home(t *testing.T) string { for _, v := range []string{"XDG_CONFIG_HOME", "XDG_STATE_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME"} { t.Setenv(v, "") } + setNonTerminalStdin(t) return h } +// setNonTerminalStdin points the stdin seam (sort.go) at os.DevNull for the +// duration of the calling test, restoring it afterward. +func setNonTerminalStdin(t *testing.T) { + t.Helper() + f, err := os.Open(os.DevNull) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { f.Close() }) + old := stdin + stdin = f + t.Cleanup(func() { stdin = old }) +} + func TestInitNewCheck(t *testing.T) { h := home(t) if err := os.Mkdir(filepath.Join(h, "dl"), 0o755); err != nil { |
