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

@@ -137,7 +137,8 @@ jobs:
go-version: ${{matrix.go}} go-version: ${{matrix.go}}
- name: run llgo test - name: run llgo test
run: bash .github/workflows/llgo_test.sh run: |
llgo test ./...
hello: hello:
continue-on-error: true continue-on-error: true

View File

@@ -1,17 +0,0 @@
#!/bin/bash
set -e
output=$(llgo test ./... 2>&1)
echo "$output"
pass_count=$(echo "$output" | grep -c "^PASS$")
echo "llgo test pass count: $pass_count"
if [ "$pass_count" -gt 1 ]; then
echo "llgo test ./... passed"
exit 0
else
echo "llgo test ./... failed: PASS count is not greater than 1"
exit 1
fi

View File

@@ -3,7 +3,7 @@ package bar_test
import ( import (
"testing" "testing"
"github.com/goplus/llgo/test/bar" "github.com/goplus/llgo/cl/_testgo/runextest/bar"
) )
func TestBar(t *testing.T) { func TestBar(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package barinner_test
import ( import (
"testing" "testing"
"github.com/goplus/llgo/test/bar/barinner" "github.com/goplus/llgo/cl/_testgo/runextest/bar/barinner"
) )
func TestBarInner(t *testing.T) { func TestBarInner(t *testing.T) {

View File

@@ -3,7 +3,7 @@ package foo_test
import ( import (
"testing" "testing"
"github.com/goplus/llgo/test/foo" "github.com/goplus/llgo/cl/_testgo/runextest/foo"
) )
func TestFoo(t *testing.T) { func TestFoo(t *testing.T) {

View File

@@ -0,0 +1,16 @@
package main
import (
"github.com/goplus/llgo/cl/_testgo/runextest/bar"
"github.com/goplus/llgo/cl/_testgo/runextest/foo"
)
func Zoo() int {
return 3
}
func main() {
println("foo.Foo()", foo.Foo())
println("bar.Bar()", bar.Bar())
println("Zoo()", Zoo())
}

View File

@@ -0,0 +1,11 @@
package main
import (
"testing"
)
func TestZoo(t *testing.T) {
if Zoo() != 3 {
t.Fatal("Zoo() != 3")
}
}

View File

@@ -0,0 +1 @@
;

View File

@@ -4,7 +4,9 @@
package build package build
import ( import (
"bytes"
"fmt" "fmt"
"io"
"os" "os"
"testing" "testing"
@@ -58,10 +60,36 @@ func TestRun(t *testing.T) {
} }
func TestTest(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}) 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) { func TestCmpTest(t *testing.T) {
mockRun([]string{"../../cl/_testgo/runtest"}, &Config{Mode: ModeCmpTest}) mockRun([]string{"../../cl/_testgo/runtest"}, &Config{Mode: ModeCmpTest})
} }