Skip to content

Commit e10da07

Browse files
committed
Add infrastructure for defining -ldflags for go test run
The `go:build` task has an `LDFLAGS` taskfile template variable, which is currently used by some projects to inject the versioning information while building via an `-ldflags` flag. `go test` has undocumented support for an `-ldflags` flag as well. Projects might find it useful to be able to set the value of string variables in the code while running the tests. To provide support by the template task for this use case, a `TEST_LDFLAGS` taskfile template variable is added to the `go test` command in the `go:test` task, as well as empty definition of the variable. This can be left empty if the project doesn't have any need for the capability.
1 parent dc828e0 commit e10da07

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Taskfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ vars:
1111
go list ./... | tr '\n' ' ' ||
1212
echo '"ERROR: Unable to discover Go packages"'
1313
)
14+
# `-ldflags` flag to use for `go build` command
1415
LDFLAGS:
16+
# `-ldflags` flag to use for `go test` command
17+
TEST_LDFLAGS:
1518

1619
tasks:
1720
build:
@@ -78,6 +81,7 @@ tasks:
7881
-run '{{default ".*" .GO_TEST_REGEX}}' \
7982
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
8083
-coverprofile=coverage_unit.txt \
84+
{{.TEST_LDFLAGS}} \
8185
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
8286
8387
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml

0 commit comments

Comments
 (0)