Skip to content
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
4 changes: 2 additions & 2 deletions cortex-m-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ panic-halt = "0.2.0"
cortex-m-semihosting = { path = "../cortex-m-semihosting" }

[target.'cfg(not(target_os = "none"))'.dev-dependencies]
compiletest_rs = "0.11"
trybuild = "1.0.125"

[[example]]
name = "device"
Expand All @@ -32,7 +32,7 @@ name = "warnings"
required-features = ["device"]

[[test]]
name = "compiletest"
name = "compile_fail"
required-features = ["device"]

[features]
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ main() {
if [ "$TARGET" = x86_64-unknown-linux-gnu ] && [ "$TRAVIS_RUST_VERSION" = stable ]; then
( cd macros && cargo check && cargo test )

cargo test --features "device,${needed_features}" --test compiletest
cargo test --features "device,${needed_features}" --test compile_fail
fi

local examples=(
Expand Down
16 changes: 14 additions & 2 deletions cortex-m-rt/tests/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# How to run

To run the compile tests, use the following command on the root of the project:
The compile-fail tests use [trybuild](https://docs.rs/trybuild). To run them, use the following
command on the root of the project:

```
cargo test --package cortex-m-rt --test compiletest --features device
cargo test --package cortex-m-rt --test compile_fail --features device
```

Each `tests/compile-fail/*.rs` file must fail to compile with exactly the diagnostics in the
`.stderr` file next to it. After adding a test or intentionally changing a diagnostic, regenerate
the `.stderr` files with:

```
TRYBUILD=overwrite cargo test --package cortex-m-rt --test compile_fail --features device
```

and review the result before committing. The expected output is tied to the current stable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we pin the version we test with? So "selected" or "pinned" rather than "current"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSRV is pinned, latest stable is not.

compiler, so new Rust releases may require regenerating it.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ fn foo() -> ! {

#[exception]
unsafe fn DefaultHandler(_irqn: i16, undef: u32) {}
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
--> tests/compile-fail/default-handler-bad-signature-1.rs:15:1
|
15 | unsafe fn DefaultHandler(_irqn: i16, undef: u32) {}
| ^^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ fn foo() -> ! {

#[exception]
unsafe fn DefaultHandler(_irqn: i16) -> u32 {
//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `DefaultHandler` must have signature `unsafe fn(i16) [-> !]`
--> tests/compile-fail/default-handler-bad-signature-2.rs:15:1
|
15 | unsafe fn DefaultHandler(_irqn: i16) -> u32 {
| ^^^^^^
22 changes: 0 additions & 22 deletions cortex-m-rt/tests/compile-fail/default-handler-hidden.rs

This file was deleted.

2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/default-handler-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ unsafe fn DefaultHandler(_irqn: i16) {}
pub mod reachable {
use cortex_m_rt::exception;

#[exception] //~ ERROR symbol `DefaultHandler` is already defined
#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
}
7 changes: 7 additions & 0 deletions cortex-m-rt/tests/compile-fail/default-handler-twice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: symbol `DefaultHandler` is already defined
--> tests/compile-fail/default-handler-twice.rs:20:5
|
20 | #[exception]
| ^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `exception` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 3 additions & 3 deletions cortex-m-rt/tests/compile-fail/duplicate-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ enum interrupt {
#[entry]
fn foo() -> ! {
static mut X: u32 = 0;
static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times
static mut X: i32 = 0;

loop {}
}

#[exception]
fn SVCall() {
static mut X: u32 = 0;
static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times
static mut X: i32 = 0;
}

#[interrupt]
fn UART0() {
static mut X: u32 = 0;
static mut X: i32 = 0; //~ ERROR the name `X` is defined multiple times
static mut X: i32 = 0;
}
17 changes: 17 additions & 0 deletions cortex-m-rt/tests/compile-fail/duplicate-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: the name `X` is defined multiple times
--> tests/compile-fail/duplicate-static.rs:17:16
|
17 | static mut X: i32 = 0;
| ^

error: the name `X` is defined multiple times
--> tests/compile-fail/duplicate-static.rs:25:16
|
25 | static mut X: i32 = 0;
| ^

error: the name `X` is defined multiple times
--> tests/compile-fail/duplicate-static.rs:31:16
|
31 | static mut X: i32 = 0;
| ^
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/entry-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate panic_halt;

use cortex_m_rt::entry;

#[entry(foo)] //~ ERROR This attribute accepts no arguments
#[entry(foo)]
fn foo() -> ! {
loop {}
}
7 changes: 7 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-args.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: This attribute accepts no arguments
--> tests/compile-fail/entry-args.rs:9:1
|
9 | #[entry(foo)]
| ^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `entry` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 0 additions & 1 deletion cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ use cortex_m_rt::entry;

#[entry]
fn foo() {}
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-bad-signature-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `#[entry]` function must have signature `[unsafe] fn() -> !`
--> tests/compile-fail/entry-bad-signature-1.rs:10:1
|
10 | fn foo() {}
| ^^
1 change: 0 additions & 1 deletion cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ use cortex_m_rt::entry;

#[entry]
fn foo(undef: i32) -> ! {}
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-bad-signature-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `#[entry]` function must have signature `[unsafe] fn() -> !`
--> tests/compile-fail/entry-bad-signature-2.rs:10:1
|
10 | fn foo(undef: i32) -> ! {}
| ^^
1 change: 0 additions & 1 deletion cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ use cortex_m_rt::entry;

#[entry]
extern "C" fn foo() -> ! {
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`
loop {}
}
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-bad-signature-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `#[entry]` function must have signature `[unsafe] fn() -> !`
--> tests/compile-fail/entry-bad-signature-3.rs:10:1
|
10 | extern "C" fn foo() -> ! {
| ^^^^^^
19 changes: 0 additions & 19 deletions cortex-m-rt/tests/compile-fail/entry-hidden.rs

This file was deleted.

2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/entry-soundness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ fn foo() -> ! {
#[exception]
fn SysTick() {
// If this was allowed it would lead to a data race as `SysTick` can preempt `foo`
foo(); //~ ERROR cannot find function `foo` in this scope
foo();
}
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-soundness.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0425]: cannot find function `foo` in this scope
--> tests/compile-fail/entry-soundness.rs:25:5
|
25 | foo();
| ^^^ not found in this scope
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/entry-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn foo() -> ! {
loop {}
}

#[entry] //~ ERROR symbol `main` is already defined
#[entry]
fn bar() -> ! {
loop {}
}
7 changes: 7 additions & 0 deletions cortex-m-rt/tests/compile-fail/entry-twice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: symbol `main` is already defined
--> tests/compile-fail/entry-twice.rs:14:1
|
14 | #[entry]
| ^^^^^^^^
|
= note: this error originates in the attribute macro `entry` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/exception-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fn foo() -> ! {
loop {}
}

#[exception(SysTick)] //~ ERROR This attribute accepts no arguments
#[exception(SysTick)]
fn SysTick() {}
7 changes: 7 additions & 0 deletions cortex-m-rt/tests/compile-fail/exception-args.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: This attribute accepts no arguments
--> tests/compile-fail/exception-args.rs:14:1
|
14 | #[exception(SysTick)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `exception` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ fn foo() -> ! {

#[exception]
fn SysTick(undef: u32) {}
//~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
--> tests/compile-fail/exception-bad-signature-1.rs:15:1
|
15 | fn SysTick(undef: u32) {}
| ^^
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ fn foo() -> ! {

#[exception]
fn SysTick() -> u32 {
//~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
--> tests/compile-fail/exception-bad-signature-2.rs:15:1
|
15 | fn SysTick() -> u32 {
| ^^
22 changes: 0 additions & 22 deletions cortex-m-rt/tests/compile-fail/exception-hidden.rs

This file was deleted.

3 changes: 0 additions & 3 deletions cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ fn foo() -> ! {

#[exception]
fn DefaultHandler(_irq: i16) {}
//~^ ERROR defining a `DefaultHandler` is unsafe and requires an `unsafe fn`

#[exception]
fn HardFault() {}
//~^ ERROR defining a `HardFault` handler is unsafe and requires an `unsafe fn`

#[exception]
fn NonMaskableInt() {}
//~^ ERROR defining a `NonMaskableInt` handler is unsafe and requires an `unsafe fn`
17 changes: 17 additions & 0 deletions cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: defining a `DefaultHandler` is unsafe and requires an `unsafe fn` (see the cortex-m-rt docs)
--> tests/compile-fail/exception-nmi-unsafe.rs:15:4
|
15 | fn DefaultHandler(_irq: i16) {}
| ^^^^^^^^^^^^^^

error: defining a `HardFault` handler is unsafe and requires an `unsafe fn` (see the cortex-m-rt docs)
--> tests/compile-fail/exception-nmi-unsafe.rs:18:4
|
18 | fn HardFault() {}
| ^^^^^^^^^

error: defining a `NonMaskableInt` handler is unsafe and requires an `unsafe fn` (see the cortex-m-rt docs)
--> tests/compile-fail/exception-nmi-unsafe.rs:21:4
|
21 | fn NonMaskableInt() {}
| ^^^^^^^^^^^^^^
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/exception-soundness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ fn SysTick() {
#[exception]
fn SVCall() {
// If this was allowed it would lead to a data race as `SVCall` could preempt `SysTick`
SysTick(); //~ ERROR cannot find function, tuple struct or tuple variant `SysTick` in this scope [E0425]
SysTick();
}
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/exception-soundness.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0425]: cannot find function, tuple struct or tuple variant `SysTick` in this scope
--> tests/compile-fail/exception-soundness.rs:28:5
|
28 | SysTick();
| ^^^^^^^ not found in this scope
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/exception-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ fn SysTick() {}
pub mod reachable {
use cortex_m_rt::exception;

#[exception] //~ ERROR symbol `SysTick` is already defined
#[exception]
fn SysTick() {}
}
7 changes: 7 additions & 0 deletions cortex-m-rt/tests/compile-fail/exception-twice.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: symbol `SysTick` is already defined
--> tests/compile-fail/exception-twice.rs:20:5
|
20 | #[exception]
| ^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `exception` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 0 additions & 1 deletion cortex-m-rt/tests/compile-fail/exception-v8only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ fn foo() -> ! {

#[exception]
fn SecureFault() {}
//~^ ERROR no variant, associated function, or constant named `SecureFault` found for enum `cortex_m_rt::Exception` in the current scope
5 changes: 5 additions & 0 deletions cortex-m-rt/tests/compile-fail/exception-v8only.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0599]: no variant, associated function, or constant named `SecureFault` found for enum `cortex_m_rt::Exception` in the current scope
--> tests/compile-fail/exception-v8only.rs:15:4
|
15 | fn SecureFault() {}
| ^^^^^^^^^^^ variant, associated function, or constant not found in `cortex_m_rt::Exception`
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ fn foo() -> ! {

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! {
//~^ ERROR `HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !`
loop {}
}
Loading
Loading