test(build):collect llgo test ./... output to test
This commit is contained in:
3
.github/workflows/llgo.yml
vendored
3
.github/workflows/llgo.yml
vendored
@@ -137,7 +137,8 @@ jobs:
|
||||
go-version: ${{matrix.go}}
|
||||
|
||||
- name: run llgo test
|
||||
run: bash .github/workflows/llgo_test.sh
|
||||
run: |
|
||||
llgo test ./...
|
||||
|
||||
hello:
|
||||
continue-on-error: true
|
||||
|
||||
17
.github/workflows/llgo_test.sh
vendored
17
.github/workflows/llgo_test.sh
vendored
@@ -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
|
||||
@@ -3,7 +3,7 @@ package bar_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llgo/test/bar"
|
||||
"github.com/goplus/llgo/cl/_testgo/runextest/bar"
|
||||
)
|
||||
|
||||
func TestBar(t *testing.T) {
|
||||
@@ -3,7 +3,7 @@ package barinner_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llgo/test/bar/barinner"
|
||||
"github.com/goplus/llgo/cl/_testgo/runextest/bar/barinner"
|
||||
)
|
||||
|
||||
func TestBarInner(t *testing.T) {
|
||||
@@ -3,7 +3,7 @@ package foo_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goplus/llgo/test/foo"
|
||||
"github.com/goplus/llgo/cl/_testgo/runextest/foo"
|
||||
)
|
||||
|
||||
func TestFoo(t *testing.T) {
|
||||
16
cl/_testgo/runextest/main.go
Normal file
16
cl/_testgo/runextest/main.go
Normal 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())
|
||||
}
|
||||
11
cl/_testgo/runextest/main_test.go
Normal file
11
cl/_testgo/runextest/main_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestZoo(t *testing.T) {
|
||||
if Zoo() != 3 {
|
||||
t.Fatal("Zoo() != 3")
|
||||
}
|
||||
}
|
||||
1
cl/_testgo/runextest/out.ll
Normal file
1
cl/_testgo/runextest/out.ll
Normal file
@@ -0,0 +1 @@
|
||||
;
|
||||
@@ -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