test(build):collect llgo test ./... output to test
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user