Skip to content

Commit

Permalink
Add infrastructure for defining -ldflags for go test run
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
per1234 committed Jul 19, 2023
1 parent dc828e0 commit e10da07
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ vars:
go list ./... | tr '\n' ' ' ||
echo '"ERROR: Unable to discover Go packages"'
)
# `-ldflags` flag to use for `go build` command
LDFLAGS:
# `-ldflags` flag to use for `go test` command
TEST_LDFLAGS:

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

0 comments on commit e10da07

Please sign in to comment.