Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/e2e_test_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x
go-version: 1.18.x
- name: Checkout code
uses: actions/checkout@v2
- name: Go build
Expand All @@ -43,7 +43,7 @@ jobs:
needs: job_1
strategy:
matrix:
go-version: [1.11.x, 1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x]
go-version: [1.16.x, 1.17.x, 1.18.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -56,7 +56,7 @@ jobs:
uses: actions/download-artifact@v2
with:
path: /home/runner/tools
- name: Install bats-core
- name: Install bats-core
run: |
git clone https://github.com/bats-core/bats-core.git
cd bats-core
Expand All @@ -70,4 +70,4 @@ jobs:
chmod +x /home/runner/tools/gocc/gocc
export PATH=/home/runner/tools/gocc:$PATH
cd tests
./run-ci-actions.sh
./run-ci-actions.sh
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.29
version: v1.45

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand All @@ -20,4 +20,4 @@ jobs:
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
only-new-issues: true
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x
go-version: 1.18.x
- name: compile and release
run: |
./ci-build.sh
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x
go-version: 1.18.x
- name: compile and release
run: |
./ci-build.sh
Expand All @@ -45,11 +45,11 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x
go-version: 1.18.x
- name: compile and release
run: |
./ci-build.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: darwin
GOOS: darwin
3 changes: 2 additions & 1 deletion .github/workflows/style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
name: vet and gofmt
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x]
# We have generics code, so only 1.18+ can work
go-version: [1.18.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ut_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: go test
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x]
go-version: [1.16.x, 1.17.x, 1.18.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
49 changes: 49 additions & 0 deletions cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -89,6 +91,53 @@ func TestBuildBinaryName(t *testing.T) {
assert.Equal(t, cnt > 0, true, "GoCover variable should be in the binary")
}

func TestBuildBinaryWithGenerics(t *testing.T) {
startTime := time.Now()

workingDir := filepath.Join(baseDir, "../tests/samples/simple_project_with_generics")
gopath := ""

os.Setenv("GOPATH", gopath)
os.Setenv("GO111MODULE", "on")

// only run this test on go1.18+
{
cmd := exec.Command("go", "version")
cmd.Dir = workingDir
out, err := cmd.CombinedOutput()
assert.NoError(t, err, "go version invocation should succeed")

re := regexp.MustCompile(`^go version go(\d+)\.(\d+)`)
match := re.FindStringSubmatch(string(out))
assert.NotNil(t, match, "go version output should be well-formed")

majorVersion, _ := strconv.ParseInt(match[1], 10, 0)
minorVersion, _ := strconv.ParseInt(match[2], 10, 0)

if majorVersion < 1 || (majorVersion == 1 && minorVersion < 18) {
t.Skip("skipping on older Go toolchain")
}
}

buildFlags, buildOutput = "", ""
args := []string{"."}
runBuild(args, workingDir)

obj := filepath.Join(workingDir, "simple-project")
fInfo, err := os.Lstat(obj)
assert.Equal(t, err, nil, "the binary should be generated.")
assert.Equal(t, startTime.Before(fInfo.ModTime()), true, obj+"new binary should be generated, not the old one")

cmd := exec.Command("go", "tool", "objdump", "simple-project")
cmd.Dir = workingDir
out, _ := cmd.CombinedOutput()
cnt := strings.Count(string(out), "main.registerSelf")
assert.Equal(t, cnt > 0, true, "main.registerSelf function should be in the binary")

cnt = strings.Count(string(out), "GoCover")
assert.Equal(t, cnt > 0, true, "GoCover variable should be in the binary")
}

// test if goc can get variables in internal package
func TestBuildBinaryForInternalPackage(t *testing.T) {
startTime := time.Now()
Expand Down
24 changes: 21 additions & 3 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ setup() {

@test "test basic goc build command" {
cd samples/run_for_several_seconds

wait_profile_backend "build1" &
profile_pid=$!

Expand Down Expand Up @@ -90,7 +90,7 @@ setup() {

@test "test goc build on complex project" {
cd samples/complex_project

wait_profile_backend "build5" &
profile_pid=$!

Expand All @@ -116,7 +116,7 @@ setup() {

@test "test basic goc build command with singleton" {
cd samples/run_for_several_seconds

wait_profile_backend "build7" &
profile_pid=$!

Expand All @@ -126,3 +126,21 @@ setup() {

wait $profile_pid
}

@test "test goc build command on project using Go generics" {
if ! go_version_at_least 1 18; then
info skipped on old Go versions
return 0
fi

cd samples/simple_project_with_generics

wait_profile_backend "build8" &
profile_pid=$!

run gocc build --debug --debugcisyncfile ci-sync.bak;
info build8 output: $output
[ "$status" -eq 0 ]

wait $profile_pid
}
4 changes: 2 additions & 2 deletions tests/clear.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setup_file() {
sleep 1

WORKDIR=$PWD
cd samples/run_for_several_seconds
cd $WORKDIR/samples/$(demo_service_name)
gocc build --center=http://127.0.0.1:60001
./simple-project 3>&- &
SAMPLE_PID=$!
Expand Down Expand Up @@ -99,4 +99,4 @@ teardown_file() {


kill -9 $TEST_SERVICE
}
}
4 changes: 2 additions & 2 deletions tests/init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setup_file() {
sleep 1

WORKDIR=$PWD
cd samples/run_for_several_seconds
cd $WORKDIR/samples/$(demo_service_name)
gocc build --center=http://127.0.0.1:60001
./simple-project 3>&- &
SAMPLE_PID=$!
Expand All @@ -52,4 +52,4 @@ teardown_file() {
[ "$status" -eq 0 ]

wait $profile_pid
}
}
4 changes: 2 additions & 2 deletions tests/profile.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setup_file() {
sleep 1

WORKDIR=$PWD
cd samples/run_for_several_seconds
cd $WORKDIR/samples/$(demo_service_name)
goc build --center=http://127.0.0.1:60001

info "goc server started"
Expand Down Expand Up @@ -150,4 +150,4 @@ setup() {

wait $profile_pid
kill -9 $SAMPLE_PID
}
}
2 changes: 1 addition & 1 deletion tests/remove.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setup_file() {
sleep 1

WORKDIR=$PWD
cd samples/run_for_several_seconds
cd $WORKDIR/samples/$(demo_service_name)
gocc build --center=http://127.0.0.1:60001
./simple-project 3>&- &
SAMPLE_PID=$!
Expand Down
6 changes: 6 additions & 0 deletions tests/samples/run_for_several_seconds_with_generics/a/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package a

// Say Hello A
func Say() {
println("Hello A")
}
6 changes: 6 additions & 0 deletions tests/samples/run_for_several_seconds_with_generics/b/b.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package b

// Say Hello B
func Say() {
println("Hello B")
}
3 changes: 3 additions & 0 deletions tests/samples/run_for_several_seconds_with_generics/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/simple-project

go 1.18
24 changes: 24 additions & 0 deletions tests/samples/run_for_several_seconds_with_generics/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"time"

"example.com/simple-project/a"
"example.com/simple-project/b"
)

func main() {
fmt.Println("hello")
a.Say()
b.Say()
time.Sleep(time.Second * time.Duration(mulBy(3, uint(5))))
}

type c interface {
~int | ~uint
}

func mulBy[T c, U c](x T, y U) T {
return x * T(y)
}
3 changes: 3 additions & 0 deletions tests/samples/simple_project_with_generics/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/simple-project

go 1.18
27 changes: 27 additions & 0 deletions tests/samples/simple_project_with_generics/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build go1.18

package main

import (
"fmt"
"strconv"
)

func main() {
x := []int{1, 3, 5, 7, 9}
y := mapSlice(func(x int) string {
return strconv.Itoa(x * x)
}, x)

for i, elem := range x {
fmt.Printf("%d -> '%s'\n", elem, y[i])
}
}

func mapSlice[T any, U any](fn func(T) U, src []T) []U {
dst := make([]U, len(src))
for i, x := range src {
dst[i] = fn(x)
}
return dst
}
4 changes: 2 additions & 2 deletions tests/server.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ teardown_file() {

@test "register a covered service" {
WORKDIR=$PWD
cd $WORKDIR/samples/run_for_several_seconds
cd $WORKDIR/samples/$(demo_service_name)

run goc build --debug --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
Expand All @@ -64,4 +64,4 @@ teardown_file() {
run goc init --center=http://127.0.0.1:60001
[ "$status" -eq 0 ]
[ ! -f "$WORKDIR/persistence/servicesAll.txt" ]
}
}
Loading