From 41253e574e9064de556032b987e1b22d7283cc37 Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Thu, 7 Jan 2021 11:54:00 -0800 Subject: [PATCH] [go] tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. (#6388) * tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. Calling flags.Parse() within init() races with other packages which register flags in their init(), and in particular with the testing package itself. It is more reliable to call flags.Parse() from a TestMain implementation. See https://github.com/golang/go/issues/31859, https://github.com/golang/go/issues/33869. * .github: Enable build-go action in build.yaml workflow. --- .github/workflows/build.yml | 22 +++++++++++----------- tests/GoTest.sh | 6 +++--- tests/go_test.go | 15 +++++++++------ tests/monsterdata_go_wire.mon.sp | Bin 0 -> 224 bytes 4 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 tests/monsterdata_go_wire.mon.sp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65475d879..c4d75cdf4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -149,17 +149,17 @@ jobs: working-directory: tests run: bash PythonTest.sh - #build-go: - # name: Build Go - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v1 - # - name: flatc - # # FIXME: make test script not rely on flatc - # run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j4 - # - name: test - # working-directory: tests - # run: bash GoTest.sh + build-go: + name: Build Go + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: flatc + # FIXME: make test script not rely on flatc + run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j4 + - name: test + working-directory: tests + run: bash GoTest.sh #build-csharp: # name: Build CSharp diff --git a/tests/GoTest.sh b/tests/GoTest.sh index 60ef92778..8cbadcb56 100755 --- a/tests/GoTest.sh +++ b/tests/GoTest.sh @@ -47,11 +47,11 @@ cp -a ./go_test.go ./go_gen/src/flatbuffers_test/ # flag -test.bench and the wildcard regexp ".": # go -test -test.bench=. ... GOPATH=${go_path} go test flatbuffers_test \ - --test.coverpkg=github.com/google/flatbuffers/go \ + --coverpkg=github.com/google/flatbuffers/go \ --cpp_data=${test_dir}/monsterdata_test.mon \ --out_data=${test_dir}/monsterdata_go_wire.mon \ - --test.bench=. \ - --test.benchtime=3s \ + --bench=. \ + --benchtime=3s \ --fuzz=true \ --fuzz_fields=4 \ --fuzz_objects=10000 diff --git a/tests/go_test.go b/tests/go_test.go index 9e64cca0d..5d408f6de 100644 --- a/tests/go_test.go +++ b/tests/go_test.go @@ -50,12 +50,6 @@ func init() { flag.IntVar(&fuzzFields, "fuzz_fields", 4, "fields per fuzzer object") flag.IntVar(&fuzzObjects, "fuzz_objects", 10000, "number of fuzzer objects (higher is slower and more thorough") - flag.Parse() - - if cppData == "" { - fmt.Fprintf(os.Stderr, "cpp_data argument is required\n") - os.Exit(1) - } } // Store specific byte patterns in these variables for the fuzzer. These @@ -65,6 +59,15 @@ var ( overflowingInt64Val = flatbuffers.GetInt64([]byte{0x84, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}) ) +func TestMain(m *testing.M) { + flag.Parse() + if cppData == "" { + fmt.Fprintf(os.Stderr, "cpp_data argument is required\n") + os.Exit(1) + } + os.Exit(m.Run()) +} + // TestAll runs all checks, failing if any errors occur. func TestAll(t *testing.T) { // Verify that the Go FlatBuffers runtime library generates the diff --git a/tests/monsterdata_go_wire.mon.sp b/tests/monsterdata_go_wire.mon.sp new file mode 100644 index 0000000000000000000000000000000000000000..cf3019c031401adaa1713f56de91ca122532f54e GIT binary patch literal 224 zcmcb^z`&pZ#3~FPK+M3P#2^DCMSxhCfro*Efd$Bd0BNwi3y|Xj#0d~VMi|`z<_7@D z274gk07O6x0~`)a46F=nP%aaY2AN?4#2~gD&;?vTJ3;nA01J@Kz#ss`tRMkKCT5U3 lK-jG)H3cLD5-&+DE-^x48v@y!K