Skip to content

Commit 2af3890

Browse files
authored
build(tests): require //go:build test tag if importing test packages outside of _test.go files (#3173)
1 parent 45a30f9 commit 2af3890

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+137
-7
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ run:
1515
# By default, it isn't set.
1616
modules-download-mode: readonly
1717

18+
# Include non-test files tagged as test-only.
19+
# Context: https://github.com/ava-labs/avalanchego/pull/3173
20+
build-tags:
21+
- test
22+
1823
output:
1924
# Make issues output unique by line.
2025
# Default: true

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"gopls": {
3+
"build.buildFlags": [
4+
// Context: https://github.com/ava-labs/avalanchego/pull/3173
5+
// Without this tag, the language server won't build the test-only
6+
// code in non-_test.go files.
7+
"--tags='test'",
8+
],
9+
},
10+
"go.testTags": "test",
11+
}

cache/test_cacher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package cache
57

68
import (

chains/atomic/test_shared_memory.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package atomic
57

68
import (

codec/test_codec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package codec
57

68
import (

database/benchmark_database.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package database
57

68
import (

database/test_database.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package database
57

68
import (

ids/test_aliases.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
//go:build test
5+
46
package ids
57

68
import "github.com/stretchr/testify/require"

scripts/build_fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ do
2828
echo "Fuzzing $func in $file"
2929
parentDir=$(dirname "$file")
3030
# If any of the fuzz tests fail, return exit code 1
31-
if ! go test "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${fuzzTime}"s; then
31+
if ! go test -tags test "$parentDir" -run="$func" -fuzz="$func" -fuzztime="${fuzzTime}"s; then
3232
failed=true
3333
fi
3434
done

scripts/build_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ fi
1818
TEST_TARGETS="$(eval "go list ./... ${EXCLUDED_TARGETS}")"
1919

2020
# shellcheck disable=SC2086
21-
go test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS}
21+
go test -tags test -shuffle=on -race -timeout="${TIMEOUT:-120s}" -coverprofile="coverage.out" -covermode="atomic" ${TEST_TARGETS}

0 commit comments

Comments
 (0)