Skip to content

Commit

Permalink
Merge branch 'fix-empty-features'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Oct 18, 2019
2 parents ba25779 + eaeaa36 commit 5c6e574
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 23 deletions.
11 changes: 11 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions azure/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
setup: []
submodules: recursive
nightly: false
features: '' # empty feature list is == default
features: []

jobs:
- job: tarpaulin
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion azure/nightly-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions azure/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, '') }}:
Expand Down
15 changes: 10 additions & 5 deletions azure/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
setup: []
test_ignored: false
single_threaded: false
features: '' # empty feature list is == default
features: []
services: {}

jobs:
Expand Down Expand Up @@ -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 }}
8 changes: 5 additions & 3 deletions azure/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ parameters:
setup: []
test_ignored: false
single_threaded: false
nightly_feature: ''
features: ''
nightly_features: []
features: []

jobs:
- template: test.yml
Expand Down Expand Up @@ -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 }}
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ Set this parameter to `true` to also run tests [marked with
stages:
- template: azure/stages.yml@templates
parameters:
test_features: <string> = ''
nightly_feature: <string> = ''
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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions docs/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -173,7 +173,7 @@ parameters:
allow_fail: <bool> = false
test_ignored: <bool> = false
single_threaded: <bool> = false
features: <string> = ''
features: <[string]> = []
envs:
NAME: value
services:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down

0 comments on commit 5c6e574

Please sign in to comment.