From 3f8679be9373ee7508d512dfdfc1dda0839c7f90 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Sat, 12 Sep 2026 20:14:47 +0200 Subject: krino: acting — trash, journal, apply, lock, review, undo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/krino/commands_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'cmd/krino/commands_test.go') 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 { -- cgit v1.3