diff --git a/.github/workflows/llgo.yml b/.github/workflows/llgo.yml index 1c5cbb9b..f3f4ed7b 100644 --- a/.github/workflows/llgo.yml +++ b/.github/workflows/llgo.yml @@ -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 diff --git a/.github/workflows/llgo_test.sh b/.github/workflows/llgo_test.sh deleted file mode 100644 index 6137fd37..00000000 --- a/.github/workflows/llgo_test.sh +++ /dev/null @@ -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 diff --git a/test/bar/bar.go b/cl/_testgo/runextest/bar/bar.go similarity index 100% rename from test/bar/bar.go rename to cl/_testgo/runextest/bar/bar.go diff --git a/test/bar/bar_test.go b/cl/_testgo/runextest/bar/bar_test.go similarity index 70% rename from test/bar/bar_test.go rename to cl/_testgo/runextest/bar/bar_test.go index b3e25c2f..8d4c0438 100644 --- a/test/bar/bar_test.go +++ b/cl/_testgo/runextest/bar/bar_test.go @@ -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) { diff --git a/test/bar/barinner/barinner.go b/cl/_testgo/runextest/bar/barinner/barinner.go similarity index 100% rename from test/bar/barinner/barinner.go rename to cl/_testgo/runextest/bar/barinner/barinner.go diff --git a/test/bar/barinner/barinner_test.go b/cl/_testgo/runextest/bar/barinner/barinner_test.go similarity index 70% rename from test/bar/barinner/barinner_test.go rename to cl/_testgo/runextest/bar/barinner/barinner_test.go index d2d79d03..12c543cd 100644 --- a/test/bar/barinner/barinner_test.go +++ b/cl/_testgo/runextest/bar/barinner/barinner_test.go @@ -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) { diff --git a/test/foo/foo.go b/cl/_testgo/runextest/foo/foo.go similarity index 100% rename from test/foo/foo.go rename to cl/_testgo/runextest/foo/foo.go diff --git a/test/foo/foo_test.go b/cl/_testgo/runextest/foo/foo_test.go similarity index 70% rename from test/foo/foo_test.go rename to cl/_testgo/runextest/foo/foo_test.go index aa11438a..5c2125e7 100644 --- a/test/foo/foo_test.go +++ b/cl/_testgo/runextest/foo/foo_test.go @@ -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) { diff --git a/cl/_testgo/runextest/main.go b/cl/_testgo/runextest/main.go new file mode 100644 index 00000000..b3fd473c --- /dev/null +++ b/cl/_testgo/runextest/main.go @@ -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()) +} diff --git a/cl/_testgo/runextest/main_test.go b/cl/_testgo/runextest/main_test.go new file mode 100644 index 00000000..385de527 --- /dev/null +++ b/cl/_testgo/runextest/main_test.go @@ -0,0 +1,11 @@ +package main + +import ( + "testing" +) + +func TestZoo(t *testing.T) { + if Zoo() != 3 { + t.Fatal("Zoo() != 3") + } +} diff --git a/cl/_testgo/runextest/out.ll b/cl/_testgo/runextest/out.ll new file mode 100644 index 00000000..1c8a0e79 --- /dev/null +++ b/cl/_testgo/runextest/out.ll @@ -0,0 +1 @@ +; \ No newline at end of file diff --git a/internal/build/build_test.go b/internal/build/build_test.go index a7d3cf38..f2f8730f 100644 --- a/internal/build/build_test.go +++ b/internal/build/build_test.go @@ -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}) }