Skip to content

Feature/raw cargo opts #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions azure/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
check_all_features: true
nightly_feature: ''
test_features: ''
test_arguments: '--' # Defaults to a separator

stages:
# the format here is so that we can have _two_ instances of this whole
Expand Down Expand Up @@ -58,6 +59,7 @@ stages:
single_threaded: ${{ parameters.single_threaded }}
nightly_feature: ${{ parameters.nightly_feature }}
features: ${{ parameters.test_features }}
arguments: ${{ parameters.test_arguments }}
- stage: ${{ format('{0}style', parameters.prefix) }}
${{ if ne(parameters.prefix, '') }}:
displayName: ${{ format('Style linting ({0})', parameters.prefix) }}
Expand Down
37 changes: 19 additions & 18 deletions azure/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
test_ignored: false
single_threaded: false
features: '' # empty feature list is == default
arguments: '--' # Defaults to the separator between cargo opts and libtest opts

jobs:
- job: ${{ parameters.name }}
Expand All @@ -24,33 +25,33 @@ jobs:
vmImage: macOS-10.14
Windows:
vmImage: windows-2019
${{ if ne('true', parameters.cross) }}:
variables:
variables:
${{ if ne('true', parameters.cross) }}:
vmImage: ubuntu-16.04
cargo_opts: ''
libtest_opts: ''
pool:
vmImage: $(vmImage)
steps:
- template: _setup.yml
parameters:
rust: ${{ parameters.rust }}
setup: ${{ parameters.setup }}
- ${{ if ne('true', parameters.single_threaded) }}:
- script: cargo test --all --features "${{ parameters.features }}"
displayName: Run tests
env:
${{ insert }}: ${{ parameters.envs }}
# Cargo options go here
- bash: echo '##vso[task.setvariable variable=cargo_opts]$(cargo_opts) --all'
- ${{ if eq(true, parameters.features)}}:
- bash: echo '##vso[task.setvariable variable=cargo_opts]$(cargo_opts) --features "${{ parameters.features }}"'
# Libtest options go here
- ${{ if eq('true', parameters.single_threaded) }}:
- script: cargo test --all --features "${{ parameters.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
- bash: echo '##vso[task.setvariable variable=libtest_opts]$(libtest_opts) --test-threads=1'
# Run tests with the given options
- bash: cargo test $(cargo_opts) ${{ parameters.arguments }} $(libtest_opts)
displayName: Run tests
env:
${{ insert }}: ${{ parameters.envs }}
- ${{ if eq('true', parameters.test_ignored)}}:
- bash: cargo test $(cargo_opts) ${{ parameters.arguments }} $(libtest_opts) --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
displayName: Run ignored tests (single-threaded)
env:
${{ insert }}: ${{ parameters.envs }}

4 changes: 4 additions & 0 deletions azure/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ parameters:
single_threaded: false
nightly_feature: ''
features: ''
arguments: '--'

jobs:
- template: test.yml
Expand All @@ -16,6 +17,7 @@ jobs:
test_ignored: ${{ parameters.test_ignored }}
single_threaded: ${{ parameters.single_threaded }}
features: ${{ parameters.features }}
arguments: ${{ parameters.arguments }}
- template: test.yml
parameters:
name: cargo_test_beta
Expand All @@ -25,6 +27,7 @@ jobs:
test_ignored: ${{ parameters.test_ignored }}
single_threaded: ${{ parameters.single_threaded }}
features: ${{ parameters.features }}
arguments: ${{ parameters.arguments }}
- template: test.yml
parameters:
name: cargo_test_nightly
Expand All @@ -35,3 +38,4 @@ jobs:
test_ignored: ${{ parameters.test_ignored }}
single_threaded: ${{ parameters.single_threaded }}
features: "${{ parameters.features }},${{ parameters.nightly_feature }}"
arguments: ${{ parameters.arguments }}
20 changes: 20 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ fashion](https://doc.rust-lang.org/book/ch11-02-running-tests.html#running-tests
case for you, set this parameter to `true` and your tests will be run
with `--test-threads=1`.

### Custom Arguments

```yaml
stages:
- template: azure/stages.yml@templates
parameters:
test_arguments: <string> = '--'
```

If the pre-baked `cargo test` parameters are not extensible enough for your
use case, (for example, if you need to pass unstable `-Z` options) you can
pass `cargo test` custom arguments that are used *in addition* to any others
set by parameters. This parameter has a syntax:

`<cargo test args> -- <libtest args>`

Note that even if you include no libtest arguments, you must still include
a trailing `--` so that any libtest arguments passed by other
configuration options (such as `single_threaded`) will still work correctly.

### Disable checking all features

```yaml
Expand Down
4 changes: 3 additions & 1 deletion docs/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ 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
with the nightly compiler. See the [test docs](#test) for details.
with the nightly compiler. See the [test docs](#test) for details.

### Test

Expand All @@ -173,6 +173,7 @@ parameters:
test_ignored: <bool> = false
single_threaded: <bool> = false
features: <string> = ''
arguments: <string> = '--'
envs:
NAME: value
setup:
Expand All @@ -192,6 +193,7 @@ 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"`.
To include arbitrary `cargo test` arguments, pass `arguments: <test args -- libtest args>`, but note that you must always include the `--`, even if you add no libtest args.

### Style

Expand Down