Skip to content

Commit 916dc48

Browse files
committed
Implemented code coverage in integration tests
1 parent eb857c4 commit 916dc48

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Diff for: .github/workflows/test-go-task.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ jobs:
110110
run: |
111111
export GO_TEST_PACKAGE="github.com/arduino/arduino-cli/internal/integrationtest/${{ matrix.tests }}"
112112
task go:integration-test
113+
mv coverage_integration.txt coverage_integration_${{ matrix.operating-system }}_${{ matrix.tests }}.txt
114+
115+
- name: Upload coverage data to workflow artifact
116+
uses: actions/upload-artifact@v3
117+
with:
118+
if-no-files-found: error
119+
name: ${{ env.COVERAGE_ARTIFACT }}
120+
path: |
121+
./coverage_integration_*.txt
113122
114123
test:
115124
needs: run-determination
@@ -162,7 +171,9 @@ jobs:
162171
163172
coverage-upload:
164173
runs-on: ubuntu-latest
165-
needs: test
174+
needs:
175+
- test
176+
- test-integration
166177
steps:
167178
- name: Checkout repository
168179
uses: actions/checkout@v3
@@ -176,6 +187,7 @@ jobs:
176187
with:
177188
files: >
178189
./coverage_unit.txt,
179-
./coverage_legacy.txt
190+
./coverage_legacy.txt,
191+
./coverage_integration_*.txt
180192
flags: unit
181193
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-cli' }}

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/wiki
88
.idea
99
coverage_*.txt
10+
coverage_data
1011
__pycache__
1112
venv
1213
.pytest_cache

Diff for: Taskfile.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tasks:
4848
desc: Build the Go code
4949
dir: '{{default "./" .GO_MODULE_PATH}}'
5050
cmds:
51-
- go build -v {{.LDFLAGS}}
51+
- go build -v {{default "" .EXTRA_FLAGS}} {{.LDFLAGS}}
5252

5353
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/deploy-cobra-mkdocs-versioned-poetry/Taskfile.yml
5454
go:cli-docs:
@@ -110,10 +110,14 @@ tasks:
110110
desc: Run the Go-based integration tests
111111
deps:
112112
- task: go:build
113+
vars:
114+
EXTRA_FLAGS: "-covermode=atomic"
113115
dir: '{{default "./" .GO_MODULE_PATH}}'
114116
cmds:
115117
- |
116-
go test \
118+
rm -fr coverage_data
119+
mkdir coverage_data
120+
INTEGRATION_GOCOVERDIR={{ .ROOT_DIR }}/coverage_data go test \
117121
-v \
118122
-short \
119123
{{ .GO_TEST_PACKAGE }} \
@@ -122,6 +126,7 @@ tasks:
122126
-coverprofile=coverage_unit.txt \
123127
{{default .DEFAULT_INTEGRATIONTEST_GO_PACKAGES .GO_PACKAGES}} \
124128
{{.TEST_LDFLAGS}}
129+
go tool covdata textfmt -i=coverage_data -o coverage_integration.txt
125130
126131
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
127132
go:vet:

Diff for: internal/integrationtest/arduino-cli.go

+5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ func (cli *ArduinoCLI) convertEnvForExecutils(env map[string]string) []string {
185185
for k, v := range env {
186186
envVars = append(envVars, fmt.Sprintf("%s=%s", k, v))
187187
}
188+
189+
// Proxy code-coverage related env vars
190+
if gocoverdir := os.Getenv("INTEGRATION_GOCOVERDIR"); gocoverdir != "" {
191+
envVars = append(envVars, "GOCOVERDIR="+gocoverdir)
192+
}
188193
return envVars
189194
}
190195

0 commit comments

Comments
 (0)