Describe `minicore` test auxiliary and directive (#2097)
This commit is contained in:
parent
b088cb6d97
commit
a54fe7590c
|
|
@ -24,7 +24,8 @@
|
||||||
- [Best practices](./tests/best-practices.md)
|
- [Best practices](./tests/best-practices.md)
|
||||||
- [Compiletest](./tests/compiletest.md)
|
- [Compiletest](./tests/compiletest.md)
|
||||||
- [UI tests](./tests/ui.md)
|
- [UI tests](./tests/ui.md)
|
||||||
- [Test headers](./tests/directives.md)
|
- [Test directives](./tests/directives.md)
|
||||||
|
- [Minicore](./tests/minicore.md)
|
||||||
- [Ecosystem testing](./tests/ecosystem.md)
|
- [Ecosystem testing](./tests/ecosystem.md)
|
||||||
- [Crater](./tests/crater.md)
|
- [Crater](./tests/crater.md)
|
||||||
- [Fuchsia](./tests/fuchsia.md)
|
- [Fuchsia](./tests/fuchsia.md)
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,9 @@ more information.
|
||||||
|
|
||||||
See also the [assembly tests](#assembly-tests) for a similar set of tests.
|
See also the [assembly tests](#assembly-tests) for a similar set of tests.
|
||||||
|
|
||||||
|
If you need to work with `#![no_std]` cross-compiling tests, consult the
|
||||||
|
[`minicore` test auxiliary](./minicore.md) chapter.
|
||||||
|
|
||||||
[`tests/codegen`]: https://github.com/rust-lang/rust/tree/master/tests/codegen
|
[`tests/codegen`]: https://github.com/rust-lang/rust/tree/master/tests/codegen
|
||||||
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
|
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
|
||||||
|
|
||||||
|
|
@ -303,6 +306,9 @@ information.
|
||||||
|
|
||||||
See also the [codegen tests](#codegen-tests) for a similar set of tests.
|
See also the [codegen tests](#codegen-tests) for a similar set of tests.
|
||||||
|
|
||||||
|
If you need to work with `#![no_std]` cross-compiling tests, consult the
|
||||||
|
[`minicore` test auxiliary](./minicore.md) chapter.
|
||||||
|
|
||||||
[`tests/assembly`]: https://github.com/rust-lang/rust/tree/master/tests/assembly
|
[`tests/assembly`]: https://github.com/rust-lang/rust/tree/master/tests/assembly
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,14 +66,14 @@ See [Controlling pass/fail
|
||||||
expectations](ui.md#controlling-passfail-expectations).
|
expectations](ui.md#controlling-passfail-expectations).
|
||||||
|
|
||||||
| Directive | Explanation | Supported test suites | Possible values |
|
| Directive | Explanation | Supported test suites | Possible values |
|
||||||
|-----------------------------|---------------------------------------------|--------------------------------------------------|-----------------|
|
|-----------------------------|---------------------------------------------|-------------------------------------------|-----------------|
|
||||||
| `check-pass` | Building (no codegen) should pass | `ui`, `crashes`, `incremental`[^inc1] | N/A |
|
| `check-pass` | Building (no codegen) should pass | `ui`, `crashes`, `incremental` | N/A |
|
||||||
| `check-fail` | Building (no codegen) should fail | `ui`, `crashes` | N/A |
|
| `check-fail` | Building (no codegen) should fail | `ui`, `crashes` | N/A |
|
||||||
| `build-pass` | Building should pass | `ui`, `crashes`, `codegen`, `incremental`[^inc1] | N/A |
|
| `build-pass` | Building should pass | `ui`, `crashes`, `codegen`, `incremental` | N/A |
|
||||||
| `build-fail` | Building should fail | `ui`, `crashes` | N/A |
|
| `build-fail` | Building should fail | `ui`, `crashes` | N/A |
|
||||||
| `run-pass` | Running the test binary should pass | `ui`, `crashes`, `incremental`[^inc1] | N/A |
|
| `run-pass` | Running the test binary should pass | `ui`, `crashes`, `incremental` | N/A |
|
||||||
| `run-fail` | Running the test binary should fail | `ui`, `crashes` | N/A |
|
| `run-fail` | Running the test binary should fail | `ui`, `crashes` | N/A |
|
||||||
| `ignore-pass` | Ignore `--pass` flag | `ui`, `crashes`, `codegen`, `incremental`[^inc1] | N/A |
|
| `ignore-pass` | Ignore `--pass` flag | `ui`, `crashes`, `codegen`, `incremental` | N/A |
|
||||||
| `dont-check-failure-status` | Don't check exact failure status (i.e. `1`) | `ui`, `incremental` | N/A |
|
| `dont-check-failure-status` | Don't check exact failure status (i.e. `1`) | `ui`, `incremental` | N/A |
|
||||||
| `failure-status` | Check | `ui`, `crashes` | Any `u16` |
|
| `failure-status` | Check | `ui`, `crashes` | Any `u16` |
|
||||||
| `should-ice` | Check failure status is `101` | `coverage`, `incremental` | N/A |
|
| `should-ice` | Check failure status is `101` | `coverage`, `incremental` | N/A |
|
||||||
|
|
@ -86,15 +86,15 @@ comparison](ui.md#output-comparison) and [Rustfix tests](ui.md#rustfix-tests)
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
| Directive | Explanation | Supported test suites | Possible values |
|
| Directive | Explanation | Supported test suites | Possible values |
|
||||||
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------------------------------------------|
|
|-----------------------------------|--------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|-----------------------------------------------------------------------------------------|
|
||||||
| `check-run-results` | Check run test binary `run-{pass,fail}` output snapshot | `ui`, `crashes`, `incremental`[^inc1] if `run-pass` | N/A |
|
| `check-run-results` | Check run test binary `run-{pass,fail}` output snapshot | `ui`, `crashes`, `incremental` if `run-pass` | N/A |
|
||||||
| `error-pattern` | Check that output contains a regex pattern | `ui`, `crashes`, `incremental`[^inc1] if `run-pass` | Regex |
|
| `error-pattern` | Check that output contains a regex pattern | `ui`, `crashes`, `incremental` if `run-pass` | Regex |
|
||||||
| `check-stdout` | Check `stdout` against `error-pattern`s from running test binary[^check_stdout] | `ui`, `crashes`, `incremental`[^inc1] | N/A |
|
| `check-stdout` | Check `stdout` against `error-pattern`s from running test binary[^check_stdout] | `ui`, `crashes`, `incremental` | N/A |
|
||||||
| `compare-output-lines-by-subset` | Check output contains the contents of the snapshot by lines opposed to checking for strict equality | `ui`, `coverage` | N/A |
|
| `compare-output-lines-by-subset` | Check output contains the contents of the snapshot by lines opposed to checking for strict equality | `ui`, `coverage` | N/A |
|
||||||
| `normalize-stderr-32bit` | Normalize actual stderr (for 32-bit platforms) with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental`[^inc1] | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
| `normalize-stderr-32bit` | Normalize actual stderr (for 32-bit platforms) with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
||||||
| `normalize-stderr-64bit` | Normalize actual stderr (for 64-bit platforms) with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental`[^inc1] | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
| `normalize-stderr-64bit` | Normalize actual stderr (for 64-bit platforms) with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
||||||
| `normalize-stderr-test` | Normalize actual stderr with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental`[^inc1] | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
| `normalize-stderr-test` | Normalize actual stderr with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
||||||
| `normalize-stdout-test` | Normalize actual stdout with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental`[^inc1] | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
| `normalize-stdout-test` | Normalize actual stdout with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
|
||||||
| `dont-check-compiler-stderr` | Don't check actual compiler stderr vs stderr snapshot | `ui` | N/A |
|
| `dont-check-compiler-stderr` | Don't check actual compiler stderr vs stderr snapshot | `ui` | N/A |
|
||||||
| `dont-check-compiler-stdout` | Don't check actual compiler stdout vs stdout snapshot | `ui` | N/A |
|
| `dont-check-compiler-stdout` | Don't check actual compiler stdout vs stdout snapshot | `ui` | N/A |
|
||||||
| `run-rustfix` | Apply all suggestions via `rustfix`, snapshot fixed output, and check fixed output builds | `ui` | N/A |
|
| `run-rustfix` | Apply all suggestions via `rustfix`, snapshot fixed output, and check fixed output builds | `ui` | N/A |
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
# `minicore` test auxiliary: using `core` stubs
|
||||||
|
|
||||||
|
<!-- date-check Oct 2024 -->
|
||||||
|
|
||||||
|
[`tests/auxiliary/minicore.rs`][`minicore`] is a test auxiliary for
|
||||||
|
ui/codegen/assembly test suites. It provides `core` stubs for tests that need to
|
||||||
|
build for cross-compiled targets but do not need/want to run.
|
||||||
|
|
||||||
|
A test can use [`minicore`] by specifying the `//@ add-core-stubs` directive.
|
||||||
|
Then, mark the test with `#![feature(no_core)]` + `#![no_std]` + `#![no_core]`.
|
||||||
|
Due to Edition 2015 extern prelude rules, you will probably need to declare
|
||||||
|
`minicore` as an extern crate.
|
||||||
|
|
||||||
|
Due to the `no_std` + `no_core` nature of these tests, `//@ add-core-stubs`
|
||||||
|
implies and requires that the test will be built with `-C panic=abort`.
|
||||||
|
Unwinding panics are not supported.
|
||||||
|
|
||||||
|
If you find a `core` item to be missing from the [`minicore`] stub, consider
|
||||||
|
adding it to the test auxiliary if it's likely to be used or is already needed
|
||||||
|
by more than one test.
|
||||||
|
|
||||||
|
<div class="warning">
|
||||||
|
Please note that [`minicore`] is only intended for `core` items, and explicitly
|
||||||
|
**not** `std` or `alloc` items because `core` items are applicable to a wider
|
||||||
|
range of tests.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Example codegen test that uses `minicore`
|
||||||
|
|
||||||
|
```rust,no_run
|
||||||
|
//@ add-core-stubs
|
||||||
|
//@ revisions: meow bark
|
||||||
|
//@[meow] compile-flags: --target=x86_64-unknown-linux-gnu
|
||||||
|
//@[meow] needs-llvm-components: x86
|
||||||
|
//@[bark] compile-flags: --target=wasm32-unknown-unknown
|
||||||
|
//@[bark] needs-llvm-components: webassembly
|
||||||
|
|
||||||
|
#![crate_type = "lib"]
|
||||||
|
#![feature(no_core)]
|
||||||
|
#![no_std]
|
||||||
|
#![no_core]
|
||||||
|
|
||||||
|
extern crate minicore;
|
||||||
|
use minicore::*;
|
||||||
|
|
||||||
|
struct Meow;
|
||||||
|
impl Copy for Meow {} // `Copy` here is provided by `minicore`
|
||||||
|
|
||||||
|
// CHECK-LABEL: meow
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
fn meow() {}
|
||||||
|
```
|
||||||
|
|
||||||
|
[minicore]: https://github.com/rust-lang/rust/tree/master/tests/auxiliary/minicore.rs
|
||||||
|
|
@ -13,6 +13,9 @@ used for many other purposes. For example, tests can also be configured to [run
|
||||||
the resulting program](#controlling-passfail-expectations) to verify its
|
the resulting program](#controlling-passfail-expectations) to verify its
|
||||||
behavior.
|
behavior.
|
||||||
|
|
||||||
|
If you need to work with `#![no_std]` cross-compiling tests, consult the
|
||||||
|
[`minicore` test auxiliary](./minicore.md) chapter.
|
||||||
|
|
||||||
[`tests/ui`]: https://github.com/rust-lang/rust/blob/master/tests/ui
|
[`tests/ui`]: https://github.com/rust-lang/rust/blob/master/tests/ui
|
||||||
|
|
||||||
## General structure of a test
|
## General structure of a test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue