diff --git a/azure-pipelines.yml b/azure-pipelines.yml index fbbe22e..f4dd508 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,3 +58,14 @@ stages: ENV_IS_SET: true setup: - script: touch src/setup.rs + # test no features + - template: azure/stages.yml + parameters: + minrust: false + codecov_token: $(CODECOV_TOKEN_SECRET) + prefix: "nofeat_" + envs: + ENV_IS_SET: true + ALLOW_NO_FEATURES: true + setup: + - script: touch src/setup.rs diff --git a/azure/coverage.yml b/azure/coverage.yml index 8ca589f..701c2d7 100644 --- a/azure/coverage.yml +++ b/azure/coverage.yml @@ -4,7 +4,7 @@ parameters: setup: [] submodules: recursive nightly: false - features: '' # empty feature list is == default + features: [] jobs: - job: tarpaulin @@ -49,7 +49,13 @@ jobs: # Run any user-specific setup steps # Sadly we don't have a way of communicating the condition on has_secret - ${{ parameters.setup }} - - script: cargo tarpaulin --features "${{ parameters.features }}" --out Xml + # Determine what features to use + - bash: "if [[ -z $FEATURES ]]; then echo \"##vso[task.setvariable variable=features]\"; else echo \"##vso[task.setvariable variable=features]--features \\\"$FEATURES\\\"\"; fi" + name: features + displayName: Determine feature flags + env: + FEATURES: ${{ join(',', parameters.features) }} + - script: cargo tarpaulin $(features) --out Xml displayName: Run tarpaulin condition: and(succeeded(), eq('true', variables.has_secret)) env: diff --git a/azure/nightly-stages.yml b/azure/nightly-stages.yml index 681dcdf..35ca302 100644 --- a/azure/nightly-stages.yml +++ b/azure/nightly-stages.yml @@ -6,7 +6,7 @@ parameters: test_ignored: false single_threaded: false check_all_features: true - test_features: '' + test_features: [] stages: # the format here is so that we can have _two_ instances of this whole diff --git a/azure/stages.yml b/azure/stages.yml index ede925f..4205e1e 100644 --- a/azure/stages.yml +++ b/azure/stages.yml @@ -8,8 +8,8 @@ parameters: single_threaded: false nightly_coverage: false check_all_features: true - nightly_feature: '' - test_features: '' + nightly_features: [] + test_features: [] stages: # the format here is so that we can have _two_ instances of this whole @@ -56,7 +56,7 @@ stages: setup: ${{ parameters.setup }} test_ignored: ${{ parameters.test_ignored }} single_threaded: ${{ parameters.single_threaded }} - nightly_feature: ${{ parameters.nightly_feature }} + nightly_features: ${{ parameters.nightly_features }} features: ${{ parameters.test_features }} - stage: ${{ format('{0}style', parameters.prefix) }} ${{ if ne(parameters.prefix, '') }}: diff --git a/azure/test.yml b/azure/test.yml index d7664fb..7cd71f6 100644 --- a/azure/test.yml +++ b/azure/test.yml @@ -6,7 +6,7 @@ parameters: setup: [] test_ignored: false single_threaded: false - features: '' # empty feature list is == default + features: [] services: {} jobs: @@ -37,23 +37,28 @@ jobs: parameters: rust: ${{ parameters.rust }} setup: ${{ parameters.setup }} + - bash: "if [[ -z $FEATURES ]]; then echo \"##vso[task.setvariable variable=features]\"; else echo \"##vso[task.setvariable variable=features]--features \\\"$FEATURES\\\"\"; fi" + name: features + displayName: Determine feature flags + env: + FEATURES: ${{ join(',', parameters.features) }} - ${{ if ne('true', parameters.single_threaded) }}: - - script: cargo test --all --features "${{ parameters.features }}" + - script: cargo test --all $(features) displayName: Run tests env: ${{ insert }}: ${{ parameters.envs }} - ${{ if eq('true', parameters.single_threaded) }}: - - script: cargo test --all --features "${{ parameters.features }}" -- --test-threads=1 + - script: cargo test --all $(features) -- --test-threads=1 displayName: Run tests (single-threaded) env: ${{ insert }}: ${{ parameters.envs }} - ${{ if and(eq('true', parameters.test_ignored), ne('true', parameters.single_threaded)) }}: - - script: cargo test --all --features "${{ parameters.features }}" -- --ignored + - script: cargo test --all $(features) -- --ignored displayName: Run ignored tests env: ${{ insert }}: ${{ parameters.envs }} - ${{ if and(eq('true', parameters.test_ignored), eq('true', parameters.single_threaded)) }}: - - script: cargo test --all --features "${{ parameters.features }}" -- --ignored --test-threads=1 + - script: cargo test --all $(features) -- --ignored --test-threads=1 displayName: Run ignored tests (single-threaded) env: ${{ insert }}: ${{ parameters.envs }} diff --git a/azure/tests.yml b/azure/tests.yml index bbab2de..693e41c 100644 --- a/azure/tests.yml +++ b/azure/tests.yml @@ -3,8 +3,8 @@ parameters: setup: [] test_ignored: false single_threaded: false - nightly_feature: '' - features: '' + nightly_features: [] + features: [] jobs: - template: test.yml @@ -34,4 +34,6 @@ jobs: setup: ${{ parameters.setup }} test_ignored: ${{ parameters.test_ignored }} single_threaded: ${{ parameters.single_threaded }} - features: "${{ parameters.features }},${{ parameters.nightly_feature }}" + features: + - ${{ parameters.features }} + - ${{ parameters.nightly_feature }} diff --git a/docs/configuration.md b/docs/configuration.md index 389b848..d6ff5ae 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -72,13 +72,13 @@ Set this parameter to `true` to also run tests [marked with stages: - template: azure/stages.yml@templates parameters: - test_features: = '' - nightly_feature: = '' + test_features: <[string]> = [] + nightly_features: <[string]> = [] ``` If this parameter is set, it is passed along with `--features` to `cargo test`. This is useful if you have non-default features that you'd like -to test on CI. You can also set `nightly_feature` which will only be +to test on CI. You can also set `nightly_features` which will only be included when run on nightly, though do note that since nightly tests are always allowed to fail, you will only see yellow CI if these tests fail. If you have features like this, you _probably_ also want to @@ -90,7 +90,7 @@ features as `subcrate/feature` as described in [this issue](https://github.com/rust-lang/cargo/issues/5015). There is not currently a way to disabling default features for CI tests. -**`nightly_feature is not supported (or needed) on `nightly-stages.yml`.** +**`nightly_features is not supported (or needed) on `nightly-stages.yml`.** ### Single-threaded test execution diff --git a/docs/custom.md b/docs/custom.md index 234776c..3e90661 100644 --- a/docs/custom.md +++ b/docs/custom.md @@ -159,8 +159,8 @@ You can pass the parameter `envs: {...}` to pass [environment variables](configuration.md#environment-variables), and `setup: [...]` to run [additional setup steps](configuration.md#additional-setup-steps). You can also pass -`features` and/or `nightly_feature` to include additional cargo features -when running the tests. `nightly_feature` will only be included on runs +`features` and/or `nightly_features` to include additional cargo features +when running the tests. `nightly_features` will only be included on runs with the nightly compiler. See the [test docs](#test) for details. ### Test @@ -173,7 +173,7 @@ parameters: allow_fail: = false test_ignored: = false single_threaded: = false - features: = '' + features: <[string]> = [] envs: NAME: value services: @@ -194,7 +194,7 @@ nightly versions of the compiler. To run tests [marked with set `test_ignored: true`. To run tests with [`--test-threads=1`](https://doc.rust-lang.org/book/ch11-02-running-tests.html#running-tests-in-parallel-or-consecutively), set `single_threaded: true`. To run tests with particular features -enabled, pass `features: "feat1,feat2,subcrate/feat3"`. +enabled, pass `features: [feat1,feat2,subcrate/feat3]`. To spin up additional [service containers](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/service-containers?view=azure-devops&tabs=yaml), pass them in `services` (though note that these will generally only work diff --git a/src/lib.rs b/src/lib.rs index 94d2376..61388ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,9 @@ fn require_env() { #[cfg(all(test, not(feature = "ci")))] fn must_exist() { - panic!("ci feature was not enabled for test run"); + if !std::env::var("ALLOW_NO_FEATURES").is_ok() { + panic!("ci feature was not enabled for test run"); + } } #[cfg(all(test, feature = "ci"))]