summaryrefslogtreecommitdiff
path: root/internal/hexaiaction/cmdentry_runcommand_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-08 12:02:40 +0300
committerPaul Buetow <paul@buetow.org>2025-09-08 12:02:40 +0300
commit75cf6abd55bfb60324fc47cf91eac08dbb8b87b4 (patch)
tree6ef90d8014fe4d9a757d3f7e95bf736b70e4c685 /internal/hexaiaction/cmdentry_runcommand_test.go
parent0dcf347c3fbc6e4ffb7e46294f5dd92dbbcd98ef (diff)
docs: move tmux documentation to its own file
Diffstat (limited to 'internal/hexaiaction/cmdentry_runcommand_test.go')
-rw-r--r--internal/hexaiaction/cmdentry_runcommand_test.go87
1 files changed, 47 insertions, 40 deletions
diff --git a/internal/hexaiaction/cmdentry_runcommand_test.go b/internal/hexaiaction/cmdentry_runcommand_test.go
index 092e43b..b139bb3 100644
--- a/internal/hexaiaction/cmdentry_runcommand_test.go
+++ b/internal/hexaiaction/cmdentry_runcommand_test.go
@@ -1,53 +1,60 @@
package hexaiaction
import (
- "bytes"
- "context"
- "io"
- "os"
- "path/filepath"
- "testing"
+ "bytes"
+ "context"
+ "io"
+ "os"
+ "path/filepath"
+ "testing"
- "codeberg.org/snonux/hexai/internal/tmux"
+ "codeberg.org/snonux/hexai/internal/tmux"
)
func TestRunCommand_UIChild(t *testing.T) {
- dir := t.TempDir()
- in := filepath.Join(dir, "in.txt")
- out := filepath.Join(dir, "out.txt")
- _ = os.WriteFile(in, []byte("sel"), 0o600)
- old := runFn
- runFn = func(_ context.Context, _ io.Reader, w io.Writer, _ io.Writer) error { _, _ = io.WriteString(w, "OK"); return nil }
- t.Cleanup(func(){ runFn = old })
- opts := Options{Infile: in, Outfile: out, UIChild: true}
- if err := RunCommand(context.Background(), opts, bytes.NewBuffer(nil), io.Discard, io.Discard); err != nil {
- t.Fatalf("RunCommand UIChild: %v", err)
- }
- b, _ := os.ReadFile(out)
- if string(b) != "OK" { t.Fatalf("outfile: %q", string(b)) }
+ dir := t.TempDir()
+ in := filepath.Join(dir, "in.txt")
+ out := filepath.Join(dir, "out.txt")
+ _ = os.WriteFile(in, []byte("sel"), 0o600)
+ old := runFn
+ runFn = func(_ context.Context, _ io.Reader, w io.Writer, _ io.Writer) error {
+ _, _ = io.WriteString(w, "OK")
+ return nil
+ }
+ t.Cleanup(func() { runFn = old })
+ opts := Options{Infile: in, Outfile: out, UIChild: true}
+ if err := RunCommand(context.Background(), opts, bytes.NewBuffer(nil), io.Discard, io.Discard); err != nil {
+ t.Fatalf("RunCommand UIChild: %v", err)
+ }
+ b, _ := os.ReadFile(out)
+ if string(b) != "OK" {
+ t.Fatalf("outfile: %q", string(b))
+ }
}
func TestRunCommand_Tmux(t *testing.T) {
- oldTTY := isTTYFn
- oldExec := osExecutableFn
- oldSplit := splitRunFn
- isTTYFn = func(_ uintptr) bool { return false }
- osExecutableFn = func() (string, error) { return "/bin/hexai-tmux-action", nil }
- splitRunFn = func(_ tmux.SplitOpts, argv []string) error {
- for i := 0; i < len(argv)-1; i++ {
- if argv[i] == "-outfile" && i+1 < len(argv) {
- _ = os.WriteFile(argv[i+1], []byte("OUT"), 0o600)
- break
- }
- }
- return nil
- }
- defer func(){ isTTYFn = oldTTY; osExecutableFn = oldExec; splitRunFn = oldSplit }()
- var out bytes.Buffer
- if err := RunCommand(context.Background(), Options{}, bytes.NewBufferString("X"), &out, io.Discard); err != nil {
- t.Fatalf("RunCommand tmux: %v", err)
- }
- if out.String() != "OUT" { t.Fatalf("stdout: %q", out.String()) }
+ oldTTY := isTTYFn
+ oldExec := osExecutableFn
+ oldSplit := splitRunFn
+ isTTYFn = func(_ uintptr) bool { return false }
+ osExecutableFn = func() (string, error) { return "/bin/hexai-tmux-action", nil }
+ splitRunFn = func(_ tmux.SplitOpts, argv []string) error {
+ for i := 0; i < len(argv)-1; i++ {
+ if argv[i] == "-outfile" && i+1 < len(argv) {
+ _ = os.WriteFile(argv[i+1], []byte("OUT"), 0o600)
+ break
+ }
+ }
+ return nil
+ }
+ defer func() { isTTYFn = oldTTY; osExecutableFn = oldExec; splitRunFn = oldSplit }()
+ var out bytes.Buffer
+ if err := RunCommand(context.Background(), Options{}, bytes.NewBufferString("X"), &out, io.Discard); err != nil {
+ t.Fatalf("RunCommand tmux: %v", err)
+ }
+ if out.String() != "OUT" {
+ t.Fatalf("stdout: %q", out.String())
+ }
}
// Inline TTY path is exercised implicitly via other helpers; testing it directly