Skip to content

Commit c679381

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 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. Even though this project doesn't currently have any need for the capability, it does no harm and brings the task into alignment with the standardized "template".
1 parent 7ab3a17 commit c679381

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Taskfile.yml

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ vars:
3939
-X {{.CONFIGURATION_PACKAGE}}.Commit={{.COMMIT}}
4040
-X {{.CONFIGURATION_PACKAGE}}.Timestamp={{.TIMESTAMP}}
4141
'
42+
# `-ldflags` flag to use for `go test` command
43+
TEST_LDFLAGS:
4244

4345
tasks:
4446
build:
@@ -225,6 +227,7 @@ tasks:
225227
-run '{{default ".*" .GO_TEST_REGEX}}' \
226228
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
227229
-coverprofile=coverage_unit.txt \
230+
{{.TEST_LDFLAGS}} \
228231
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
229232
230233
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml

0 commit comments

Comments
 (0)