this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/cuetest: drive long tests via an env var

Using a build tag like "go test -tags=long" works,
but has two noticeable disadvantages:

1. Flipping a build tag in a dependency package means rebuilding it
along all downstream packages. Rebuilding a big portion of the
packages in the CUE module feels unnecessary to just flip a boolean.

2. Using build tags to skip tests is generally discouraged, as it is
possible to break their compilation and not notice given that the
Go files aren't built at all. We shouldn't set the precedent.

The long tests are now run via a non-empty env var:

CUE_LONG=true go test ./...

Finally, update the CI setup to use the new mechanism.

Change-Id: I589e7c5163d9d763df3584aa16f7eef3d5e32c81
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536306
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>

+25 -101
+1 -2
.github/workflows/test.yml
··· 66 66 key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} 67 67 restore-keys: ${{ runner.os }}-${{ matrix.go-version }}-go- 68 68 - if: ${{ github.ref == 'refs/heads/master' }} 69 - name: Set go build tags 70 - run: go env -w GOFLAGS=-tags=long 69 + run: echo CUE_LONG=true >> $GITHUB_ENV 71 70 - if: matrix.go-version == '1.16.x' && matrix.os == 'ubuntu-18.04' 72 71 name: Generate 73 72 run: go generate ./...
+4 -10
cmd/cue/cmd/testdata/script/cmd_github.txt
··· 192 192 key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} 193 193 restore-keys: ${{ runner.os }}-${{ matrix.go-version }}-go- 194 194 - if: ${{ github.ref == 'refs/heads/master' }} 195 - name: Set go build tags 196 - run: go env -w GOFLAGS=-tags=long 195 + run: echo CUE_LONG=true >> $GITHUB_ENV 197 196 - if: matrix.go-version == '1.16.x' && matrix.os == 'ubuntu-18.04' 198 197 name: Generate 199 198 run: go generate ./... ··· 1123 1122 needs: "start" 1124 1123 strategy: _#testStrategy 1125 1124 "runs-on": "${{ matrix.os }}" 1126 - steps: [_#writeNetrcFile, _#installGo, _#checkoutCode, _#cacheGoModules, _#setGoBuildTags & { 1127 - _#tags: "long" 1128 - if: "${{ \(_#isMaster) }}" 1125 + steps: [_#writeNetrcFile, _#installGo, _#checkoutCode, _#cacheGoModules, _#step & { 1126 + if: "${{ \(_#isMaster) }}" 1127 + run: "echo CUE_LONG=true >> $GITHUB_ENV" 1129 1128 }, _#goGenerate, _#goTest, _#goTestRace & { 1130 1129 if: "${{ matrix.go-version == '\(_#latestStableGo)' && matrix.os == '\(_#linuxMachine)' }}" 1131 1130 }, _#goReleaseCheck, _#checkGitClean, _#pullThroughProxy, _#failCLBuild] ··· 1341 1340 "go-version": [_#codeGenGo, "1.17.x", _#latestStableGo] 1342 1341 os: [_#linuxMachine, _#macosMachine, _#windowsMachine] 1343 1342 } 1344 - } 1345 - _#setGoBuildTags: _#step & { 1346 - _#tags: string 1347 - name: "Set go build tags" 1348 - run: "go env -w GOFLAGS=-tags=\(_#tags)" 1349 1343 } 1350 1344 _#installGo: _#step & { 1351 1345 name: "Install Go"
+7 -30
cue/testdata/eval/github.txtar
··· 55 55 needs: "start" 56 56 strategy: _#testStrategy 57 57 "runs-on": "${{ matrix.os }}" 58 - steps: [_#writeNetrcFile, _#installGo, _#checkoutCode, _#cacheGoModules, _#setGoBuildTags & { 59 - _#tags: "long" 60 - if: "${{ \(_#isMaster) }}" 58 + steps: [_#writeNetrcFile, _#installGo, _#checkoutCode, _#cacheGoModules, _#step & { 59 + if: "${{ \(_#isMaster) }}" 60 + run: "echo CUE_LONG=true >> $GITHUB_ENV" 61 61 }, _#goGenerate, _#goTest, _#goTestRace & { 62 62 if: "${{ matrix.go-version == '\(_#latestStableGo)' && matrix.os == '\(_#linuxMachine)' }}" 63 63 }, _#goReleaseCheck, _#checkGitClean, _#pullThroughProxy, _#failCLBuild] ··· 273 273 "go-version": [_#codeGenGo, "1.17.x", _#latestStableGo] 274 274 os: [_#linuxMachine, _#macosMachine, _#windowsMachine] 275 275 } 276 - } 277 - _#setGoBuildTags: _#step & { 278 - _#tags: string 279 - name: "Set go build tags" 280 - run: "go env -w GOFLAGS=-tags=\(_#tags)" 281 276 } 282 277 _#installGo: _#step & { 283 278 name: "Install Go" ··· 1121 1116 } 1122 1117 } 1123 1118 4: (#struct){ 1124 - _#tags(:ci): (string){ "long" } 1125 - name: (string){ "Set go build tags" } 1126 - run: (string){ "go env -w GOFLAGS=-tags=long" } 1127 1119 if: (string){ "${{ github.ref == 'refs/heads/master' }}" } 1120 + run: (string){ "echo CUE_LONG=true >> $GITHUB_ENV" } 1128 1121 } 1129 1122 5: (#struct){ 1130 1123 name: (string){ "Generate" } ··· 1639 1632 } 1640 1633 } 1641 1634 4: (#struct){ 1642 - _#tags(:ci): (string){ "long" } 1643 - name: (string){ "Set go build tags" } 1644 - run: (string){ "go env -w GOFLAGS=-tags=long" } 1645 1635 if: (string){ "${{ github.ref == 'refs/heads/master' }}" } 1636 + run: (string){ "echo CUE_LONG=true >> $GITHUB_ENV" } 1646 1637 } 1647 1638 5: (#struct){ 1648 1639 name: (string){ "Generate" } ··· 2130 2121 } 2131 2122 } 2132 2123 } 2133 - _#setGoBuildTags(:ci): (#struct){ 2134 - _#tags(:ci): (string){ string } 2135 - name: (string){ "Set go build tags" } 2136 - run: (_|_){ 2137 - // [incomplete] _#setGoBuildTags.run: invalid interpolation: non-concrete value string (type string): 2138 - // ./workflows.cue:270:10 2139 - // ./workflows.cue:268:10 2140 - } 2141 - } 2142 2124 _#installGo(:ci): (#struct){ 2143 2125 name: (string){ "Install Go" } 2144 2126 uses: (string){ "actions/setup-go@v3" } ··· 2251 2233 〈4;_#installGo〉, 2252 2234 〈4;_#checkoutCode〉, 2253 2235 〈4;_#cacheGoModules〉, 2254 - (〈4;_#setGoBuildTags〉 & { 2255 - _#tags: "long" 2236 + (〈4;_#step〉 & { 2256 2237 if: "${{ \(〈4;_#isMaster〉) }}" 2238 + run: "echo CUE_LONG=true >> $GITHUB_ENV" 2257 2239 }), 2258 2240 〈4;_#goGenerate〉, 2259 2241 〈4;_#goTest〉, ··· 2515 2497 ] 2516 2498 } 2517 2499 } 2518 - _#setGoBuildTags: (〈0;_#step〉 & { 2519 - _#tags: string 2520 - name: "Set go build tags" 2521 - run: "go env -w GOFLAGS=-tags=\(〈0;_#tags〉)" 2522 - }) 2523 2500 _#installGo: (〈0;_#step〉 & { 2524 2501 name: "Install Go" 2525 2502 uses: "actions/setup-go@v3"
+3 -11
internal/ci/workflows.cue
··· 74 74 _#installGo, 75 75 _#checkoutCode, 76 76 _#cacheGoModules, 77 - _#setGoBuildTags & { 78 - _#tags: "long" 79 - if: "${{ \(_#isMaster) }}" 77 + _#step & { 78 + if: "${{ \(_#isMaster) }}" 79 + run: "echo CUE_LONG=true >> $GITHUB_ENV" 80 80 }, 81 81 _#goGenerate, 82 82 _#goTest, ··· 351 351 "go-version": [_#codeGenGo, "1.17.x", _#latestStableGo] 352 352 os: [_#linuxMachine, _#macosMachine, _#windowsMachine] 353 353 } 354 - } 355 - 356 - _#setGoBuildTags: _#step & { 357 - _#tags: string 358 - name: "Set go build tags" 359 - run: """ 360 - go env -w GOFLAGS=-tags=\(_#tags) 361 - """ 362 354 } 363 355 364 356 _#installGo: _#step & {
+10 -4
internal/cuetest/cuetest.go
··· 24 24 ) 25 25 26 26 const ( 27 - // envUpdate is used in the definition of UpdateGoldenFiles 27 + envLong = "CUE_LONG" 28 + 28 29 envUpdate = "CUE_UPDATE" 29 30 30 31 // envNonIssues can be set to a regular expression which indicates what ··· 51 52 } 52 53 ) 53 54 55 + // Long determines whether long tests should be run. 56 + // It is controlled by setting CUE_LONG to a non-empty string like "true". 57 + // Note that it is not the equivalent of not supplying -short. 58 + var Long = os.Getenv(envLong) != "" 59 + 54 60 // UpdateGoldenFiles determines whether testscript scripts should update txtar 55 - // archives in the event of cmp failures. It corresponds to 56 - // testscript.Params.UpdateGoldenFiles. See the docs for 57 - // testscript.Params.UpdateGoldenFiles for more details. 61 + // archives in the event of cmp failures. 62 + // It is controlled by setting CUE_UPDATE to a non-empty string like "true". 63 + // It corresponds to testscript.Params.UpdateGoldenFiles; see its docs for details. 58 64 var UpdateGoldenFiles = os.Getenv(envUpdate) != "" 59 65 60 66 // FormatTxtar ensures that .cue files in txtar test archives are well
-22
internal/cuetest/long.go
··· 1 - // Copyright 2021 The CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build long 16 - // +build long 17 - 18 - package cuetest 19 - 20 - // LongTest is a build tag used to indicate that long tests should be run 21 - // Note this is not the equivalent of not supplying -short. 22 - const Long = true
-22
internal/cuetest/nolong.go
··· 1 - // Copyright 2021 The CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 14 - 15 - //go:build !long 16 - // +build !long 17 - 18 - package cuetest 19 - 20 - // LongTest is a build tag used to indicate that long tests should be run. 21 - // Note this is not the equivalent of not supplying -short. 22 - const Long = false