gitstack

grindlemire/go-tui code browser

1.9 KB Go 89 lines 2026-05-18 · 0af9408 raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"testing"
)

var testBin string

func TestMain(m *testing.M) {
	tmp, err := os.MkdirTemp("", "tui-integration-*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create temp dir: %v\n", err)
		os.Exit(1)
	}
	defer os.RemoveAll(tmp)

	testBin = filepath.Join(tmp, "tui")
	if runtime.GOOS == "windows" {
		testBin += ".exe"
	}
	cmd := exec.Command("go", "build", "-o", testBin, ".")
	if out, err := cmd.CombinedOutput(); err != nil {
		fmt.Fprintf(os.Stderr, "build failed: %v\n%s\n", err, out)
		os.Exit(1)
	}

	os.Exit(m.Run())
}

func TestCLI_Check(t *testing.T) {
	gsxFiles, _ := filepath.Glob("testdata/*.gsx")
	if len(gsxFiles) == 0 {
		t.Skip("no testdata/*.gsx files found")
	}

	for _, gsxFile := range gsxFiles {
		t.Run(filepath.Base(gsxFile), func(t *testing.T) {
			cmd := exec.Command(testBin, "check", gsxFile)
			out, err := cmd.CombinedOutput()
			if err != nil {
				t.Errorf("check %s failed: %v\n%s", gsxFile, err, out)
			}
		})
	}
}

func TestCLI_Fmt_Stdout(t *testing.T) {
	gsxFiles, _ := filepath.Glob("testdata/*.gsx")
	if len(gsxFiles) == 0 {
		t.Skip("no testdata/*.gsx files found")
	}

	for _, gsxFile := range gsxFiles {
		t.Run(filepath.Base(gsxFile), func(t *testing.T) {
			cmd := exec.Command(testBin, "fmt", "--stdout", gsxFile)
			out, err := cmd.CombinedOutput()
			if err != nil {
				t.Errorf("fmt --stdout %s failed: %v\n%s", gsxFile, err, out)
			}
			if len(out) == 0 {
				t.Errorf("fmt --stdout %s produced empty output", gsxFile)
			}
		})
	}
}

func TestCLI_Version(t *testing.T) {
	cmd := exec.Command(testBin, "version")
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Errorf("version failed: %v\n%s", err, out)
	}
}

func TestCLI_Help(t *testing.T) {
	cmd := exec.Command(testBin, "help")
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Errorf("help failed: %v\n%s", err, out)
	}
	if len(out) == 0 {
		t.Error("help output should not be empty")
	}
}