From 04f290dbeeee8a6fcbc70fed253a968336bcb2ab Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Sep 2025 13:19:01 +0300 Subject: more tests --- cmd/hexai-lsp/main_test.go | 23 +++++++++++++++++++++++ cmd/hexai/main_test.go | 23 +++++++++++++++++++++++ cmd/internal/hexai-action/main.go | 16 ++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 cmd/hexai-lsp/main_test.go create mode 100644 cmd/hexai/main_test.go create mode 100644 cmd/internal/hexai-action/main.go (limited to 'cmd') diff --git a/cmd/hexai-lsp/main_test.go b/cmd/hexai-lsp/main_test.go new file mode 100644 index 0000000..987bfb4 --- /dev/null +++ b/cmd/hexai-lsp/main_test.go @@ -0,0 +1,23 @@ +package main + +import ( + "bytes" + "log" + "os" + "testing" +) + +func TestMain_Version(t *testing.T) { + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = []string{"hexai-lsp", "-version"} + var buf bytes.Buffer + old := log.Writer() + log.SetOutput(&buf) + defer log.SetOutput(old) + main() + if buf.Len() == 0 { + t.Fatalf("expected version log") + } +} + diff --git a/cmd/hexai/main_test.go b/cmd/hexai/main_test.go new file mode 100644 index 0000000..beb684b --- /dev/null +++ b/cmd/hexai/main_test.go @@ -0,0 +1,23 @@ +package main + +import ( + "io" + "os" + "testing" +) + +func TestMain_Version(t *testing.T) { + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + os.Args = []string{"hexai", "-version"} + r, w, _ := os.Pipe() + old := os.Stdout + os.Stdout = w + defer func() { os.Stdout = old }() + main() + w.Close() + b, _ := io.ReadAll(r) + if len(b) == 0 { + t.Fatalf("expected version output") + } +} diff --git a/cmd/internal/hexai-action/main.go b/cmd/internal/hexai-action/main.go new file mode 100644 index 0000000..50e6774 --- /dev/null +++ b/cmd/internal/hexai-action/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "context" + "fmt" + "os" + + "codeberg.org/snonux/hexai/internal/hexaiaction" +) + +func main() { + if err := hexaiaction.Run(context.Background(), os.Stdin, os.Stdout, os.Stderr); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} -- cgit v1.2.3