Skip to content

Commit dcef09a

Browse files
authored
Merge pull request #94 from hannobraun/compiletest
Add compiletest infrastructure
2 parents e07b608 + 7a931a0 commit dcef09a

9 files changed

+189
-5
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ addons:
1010

1111
script:
1212
- rustup target add thumbv6m-none-eabi
13+
- cargo test --verbose --features="compiletest"
1314
- ./scripts/build-examples.sh
14-
- cargo test --verbose
15-
16-
cache: cargo

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ embedded-hal = { version = "0.2", features = ["unproven"] }
2323
lpc82x = "0.4"
2424
nb = "0.1.1"
2525
void = { version = "1", default-features = false }
26+
# This should be in [dev-dependencies], but those can't be optional. Issue:
27+
# https://github.com/rust-lang/cargo/issues/1596
28+
compiletest_rs = { version = "0.3", optional = true }
2629

2730
[dev-dependencies]
2831
cortex-m-rt = "0.5"
2932
panic-abort = "0.2"
3033

3134

3235
[features]
33-
rt = ["lpc82x/rt"]
36+
# This is needed to make the compiletest stuff optional. It requires std, which
37+
# means we can't build it together with the examples.
38+
compiletest = ["compiletest_rs"]
39+
rt = ["lpc82x/rt"]
3440

3541

3642
[[example]]

src/swm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<T, F, O, Is> UnassignFunction<F, Input>
690690
for Pin<T, pin_state::Swm<O, (Is,)>>
691691
where
692692
T: PinTrait,
693-
F: FunctionTrait<T, Kind=Output>,
693+
F: FunctionTrait<T, Kind=Input>,
694694
{
695695
type Unassigned = Pin<T, pin_state::Swm<O, Is>>;
696696

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extern crate lpc82x_hal;
2+
3+
4+
use lpc82x_hal::Peripherals;
5+
use lpc82x_hal::swm::{
6+
self,
7+
pin_state,
8+
Pin,
9+
};
10+
11+
12+
fn main() {
13+
let mut p = Peripherals::take().unwrap();
14+
15+
let swm = p.swm.split();
16+
let mut syscon = p.syscon.split();
17+
18+
let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
19+
let pio0_1: Pin<_, pin_state::Unused> = swm.pins.pio0_1;
20+
21+
let u0_rxd: swm::Function<_, swm::state::Unassigned> =
22+
swm.movable_functions.u0_rxd;
23+
24+
let (u0_rxd, _) = u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
25+
let (u0_rxd, _) = u0_rxd.assign(pio0_1.into_swm_pin(), &mut swm.handle);
26+
//~^ ERROR no method named `assign` found for type
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extern crate lpc82x_hal;
2+
3+
4+
use lpc82x_hal::Peripherals;
5+
use lpc82x_hal::swm::{
6+
self,
7+
pin_state,
8+
Pin,
9+
};
10+
11+
12+
fn main() {
13+
let mut p = Peripherals::take().unwrap();
14+
15+
let swm = p.swm.split();
16+
let mut syscon = p.syscon.split();
17+
18+
let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
19+
20+
let u0_rxd: swm::Function<_, swm::state::Unassigned> =
21+
swm.movable_functions.u0_rxd;
22+
let u0_txd: swm::Function<_, swm::state::Unassigned> =
23+
swm.movable_functions.u0_txd;
24+
let u1_rxd: swm::Function<_, swm::state::Unassigned> =
25+
swm.movable_functions.u1_rxd;
26+
let u1_txd: swm::Function<_, swm::state::Unassigned> =
27+
swm.movable_functions.u1_txd;
28+
29+
let (u0_rxd, pio0_0) =
30+
u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
31+
let (u1_rxd, pio0_0) =
32+
u1_rxd.assign(pio0_0, &mut swm.handle);
33+
let (u0_txd, pio0_0) =
34+
u0_txd.assign(pio0_0, &mut swm.handle);
35+
let (u1_txd, pio0_0) =
36+
u1_txd.assign(pio0_0, &mut swm.handle);
37+
//~^ ERROR the trait bound
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
extern crate lpc82x_hal;
2+
3+
4+
use lpc82x_hal::Peripherals;
5+
use lpc82x_hal::swm::{
6+
self,
7+
pin_state,
8+
Pin,
9+
};
10+
11+
12+
fn main() {
13+
let mut p = Peripherals::take().unwrap();
14+
15+
let swm = p.swm.split();
16+
let mut syscon = p.syscon.split();
17+
18+
let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
19+
let pio0_1: Pin<_, pin_state::Unused> = swm.pins.pio0_1;
20+
21+
let u0_rxd: swm::Function<_, swm::state::Unassigned> =
22+
swm.movable_functions.u0_rxd;
23+
24+
let (u0_rxd, _) = u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
25+
let (u0_rxd, _) = u0_rxd.unassign(pio0_1.into_swm_pin(), &mut swm.handle);
26+
//~^ ERROR mismatched types [E0308]
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern crate lpc82x_hal;
2+
3+
4+
use lpc82x_hal::Peripherals;
5+
use lpc82x_hal::swm::{
6+
self,
7+
pin_state,
8+
Pin,
9+
};
10+
11+
12+
fn main() {
13+
let mut p = Peripherals::take().unwrap();
14+
15+
let swm = p.swm.split();
16+
let mut syscon = p.syscon.split();
17+
18+
let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
19+
20+
let u0_rxd: swm::Function<_, swm::state::Unassigned> =
21+
swm.movable_functions.u0_rxd;
22+
23+
let (u0_rxd, pio0_0) =
24+
u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
25+
let (u0_rxd, pio0_0) =
26+
u0_rxd.unassign(pio0_0, &mut swm.handle);
27+
let (u0_rxd, pio0_0) =
28+
u0_rxd.unassign(pio0_0, &mut swm.handle);
29+
//~^ ERROR no method named `unassign` found for type
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern crate lpc82x_hal;
2+
3+
4+
use lpc82x_hal::Peripherals;
5+
use lpc82x_hal::swm::{
6+
self,
7+
pin_state,
8+
Pin,
9+
};
10+
11+
12+
fn main() {
13+
let mut p = Peripherals::take().unwrap();
14+
15+
let swm = p.swm.split();
16+
let mut syscon = p.syscon.split();
17+
18+
let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
19+
20+
let u0_txd: swm::Function<_, swm::state::Unassigned> =
21+
swm.movable_functions.u0_txd;
22+
23+
let (u0_txd, pio0_0) =
24+
u0_txd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
25+
let (u0_txd, pio0_0) =
26+
u0_txd.unassign(pio0_0, &mut swm.handle);
27+
let (u0_txd, pio0_0) =
28+
u0_txd.unassign(pio0_0, &mut swm.handle);
29+
//~^ ERROR no method named `unassign` found for type
30+
}

tests/compiletest.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![cfg(feature = "compiletest")]
2+
3+
4+
extern crate compiletest_rs as compiletest;
5+
6+
7+
use std::path::PathBuf;
8+
9+
10+
#[test]
11+
fn compile_test() {
12+
run_mode("compile-fail");
13+
}
14+
15+
fn run_mode(mode: &'static str) {
16+
let mut config = compiletest::Config::default();
17+
18+
config.mode = mode.parse().expect("Failed to parse mode");
19+
config.src_base = PathBuf::from(format!("tests/{}", mode));
20+
21+
// Needed by the compiler to find other crates
22+
config.link_deps();
23+
24+
// Fixes E0464, "multiple matching crates"
25+
config.clean_rmeta();
26+
27+
compiletest::run_tests(&config);
28+
}

0 commit comments

Comments
 (0)