test(build):collect llgo test ./... output to test

This commit is contained in:
luoliwoshang
2025-06-25 14:46:44 +08:00
parent 3df783de13
commit 6e8f3d1d19
12 changed files with 62 additions and 22 deletions

View File

@@ -4,7 +4,9 @@
package build
import (
"bytes"
"fmt"
"io"
"os"
"testing"
@@ -58,10 +60,36 @@ func TestRun(t *testing.T) {
}
func TestTest(t *testing.T) {
// fixme:with builtin package test in a llgo test ./... will cause duplicate symbol error
// FIXME(zzy): with builtin package test in a llgo test ./... will cause duplicate symbol error
mockRun([]string{"../../cl/_testgo/runtest"}, &Config{Mode: ModeTest})
}
func TestExtest(t *testing.T) {
originalStdout := os.Stdout
defer func() { os.Stdout = originalStdout }()
r, w, err := os.Pipe()
if err != nil {
t.Fatalf("os.Pipe failed: %v", err)
}
os.Stdout = w
outputChan := make(chan string)
go func() {
var data bytes.Buffer
io.Copy(&data, r)
outputChan <- data.String()
}()
mockRun([]string{"../../cl/_testgo/runextest/..."}, &Config{Mode: ModeTest})
w.Close()
got := <-outputChan
expected := "PASS\nPASS\nPASS\nPASS\n"
if got != expected {
t.Errorf("Expected output %q, but got %q", expected, got)
}
}
func TestCmpTest(t *testing.T) {
mockRun([]string{"../../cl/_testgo/runtest"}, &Config{Mode: ModeCmpTest})
}