Skip to content

Commit 2f2ce28

Browse files
committed
Describe minicore test auxiliary and directive
1 parent 0f568c4 commit 2f2ce28

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [Compiletest](./tests/compiletest.md)
2626
- [UI tests](./tests/ui.md)
2727
- [Test directives](./tests/directives.md)
28+
- [Minicore](./tests/minicore.md)
2829
- [Ecosystem testing](./tests/ecosystem.md)
2930
- [Crater](./tests/crater.md)
3031
- [Fuchsia](./tests/fuchsia.md)

src/tests/compiletest.md

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ more information.
283283

284284
See also the [assembly tests](#assembly-tests) for a similar set of tests.
285285

286+
If you need to work with `#![no_std]` cross-compiling tests, consult the
287+
[`minicore` test auxiliary](./minicore.md) chapter.
288+
286289
[`tests/codegen`]: https://github.com/rust-lang/rust/tree/master/tests/codegen
287290
[FileCheck]: https://llvm.org/docs/CommandGuide/FileCheck.html
288291

@@ -303,6 +306,9 @@ information.
303306

304307
See also the [codegen tests](#codegen-tests) for a similar set of tests.
305308

309+
If you need to work with `#![no_std]` cross-compiling tests, consult the
310+
[`minicore` test auxiliary](./minicore.md) chapter.
311+
306312
[`tests/assembly`]: https://github.com/rust-lang/rust/tree/master/tests/assembly
307313

308314

src/tests/minicore.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# `minicore` test auxiliary
2+
3+
[`tests/auxiliary/minicore.rs`][`minicore`] is a test auxiliary for
4+
ui/codegen/assembly test suites. It provides `core` stubs for tests that need to
5+
build for cross-compiled targets but do not need/want to run.
6+
7+
A test can use [`minicore`] by specifying the `//@ use-minicore` directive. Then,
8+
mark the test with `#![feature(no_core)]` + `#![no_std]` + `#![no_core]`. Due to
9+
Edition 2015 extern prelude rules, you will probably need to declare `minicore`
10+
as an extern crate.
11+
12+
If you find a `core` item to be missing from the [`minicore`] stub, consider
13+
adding it to the test auxiliary. However, please note that [`minicore`] is only
14+
intended for `core` items, and explicitly not `std` or `alloc` items because
15+
`core` items are applicable to a wider range of tests.
16+
17+
## Example codegen test that uses `minicore`
18+
19+
```rust,no_run
20+
//@ use-minicore
21+
//@ revisions: meow
22+
//@[meow] compile-flags: --target=x86_64-unknown-linux-gnu
23+
//@[meow] needs-llvm-components: x86
24+
25+
#![crate_type = "lib"]
26+
#![feature(no_core)]
27+
#![no_std]
28+
#![no_core]
29+
30+
extern crate minicore;
31+
use minicore::*;
32+
33+
struct Meow;
34+
impl Copy for Meow {} // `Copy` here is provided by `minicore`
35+
36+
// CHECK-LABEL: meow
37+
#[no_mangle]
38+
fn meow() {}
39+
```
40+
41+
[minicore]: https://github.com/rust-lang/rust/tree/master/tests/auxiliary/minicore.rs

src/tests/ui.md

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ used for many other purposes. For example, tests can also be configured to [run
1313
the resulting program](#controlling-passfail-expectations) to verify its
1414
behavior.
1515

16+
If you need to work with `#![no_std]` cross-compiling tests, consult the
17+
[`minicore` test auxiliary](./minicore.md) chapter.
18+
1619
[`tests/ui`]: https://github.com/rust-lang/rust/blob/master/tests/ui
1720

1821
## General structure of a test

0 commit comments

Comments
 (0)