Skip to content
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

Add compiletest infrastructure #94

Merged
merged 3 commits into from
Jun 8, 2018
Merged
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: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ addons:

script:
- rustup target add thumbv6m-none-eabi
- cargo test --verbose --features="compiletest"
- ./scripts/build-examples.sh
- cargo test --verbose

cache: cargo
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ embedded-hal = { version = "0.2", features = ["unproven"] }
lpc82x = "0.4"
nb = "0.1.1"
void = { version = "1", default-features = false }
# This should be in [dev-dependencies], but those can't be optional. Issue:
# https://github.com/rust-lang/cargo/issues/1596
compiletest_rs = { version = "0.3", optional = true }

[dev-dependencies]
cortex-m-rt = "0.5"
panic-abort = "0.2"


[features]
rt = ["lpc82x/rt"]
# This is needed to make the compiletest stuff optional. It requires std, which
# means we can't build it together with the examples.
compiletest = ["compiletest_rs"]
rt = ["lpc82x/rt"]


[[example]]
Expand Down
2 changes: 1 addition & 1 deletion src/swm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ impl<T, F, O, Is> UnassignFunction<F, Input>
for Pin<T, pin_state::Swm<O, (Is,)>>
where
T: PinTrait,
F: FunctionTrait<T, Kind=Output>,
F: FunctionTrait<T, Kind=Input>,
{
type Unassigned = Pin<T, pin_state::Swm<O, Is>>;

Expand Down
27 changes: 27 additions & 0 deletions tests/compile-fail/swm/assign-function-to-multiple-pins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate lpc82x_hal;


use lpc82x_hal::Peripherals;
use lpc82x_hal::swm::{
self,
pin_state,
Pin,
};


fn main() {
let mut p = Peripherals::take().unwrap();

let swm = p.swm.split();
let mut syscon = p.syscon.split();

let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
let pio0_1: Pin<_, pin_state::Unused> = swm.pins.pio0_1;

let u0_rxd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_rxd;

let (u0_rxd, _) = u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
let (u0_rxd, _) = u0_rxd.assign(pio0_1.into_swm_pin(), &mut swm.handle);
//~^ ERROR no method named `assign` found for type
}
38 changes: 38 additions & 0 deletions tests/compile-fail/swm/assign-multiple-output-functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extern crate lpc82x_hal;


use lpc82x_hal::Peripherals;
use lpc82x_hal::swm::{
self,
pin_state,
Pin,
};


fn main() {
let mut p = Peripherals::take().unwrap();

let swm = p.swm.split();
let mut syscon = p.syscon.split();

let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;

let u0_rxd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_rxd;
let u0_txd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_txd;
let u1_rxd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u1_rxd;
let u1_txd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u1_txd;

let (u0_rxd, pio0_0) =
u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
let (u1_rxd, pio0_0) =
u1_rxd.assign(pio0_0, &mut swm.handle);
let (u0_txd, pio0_0) =
u0_txd.assign(pio0_0, &mut swm.handle);
let (u1_txd, pio0_0) =
u1_txd.assign(pio0_0, &mut swm.handle);
//~^ ERROR the trait bound
}
27 changes: 27 additions & 0 deletions tests/compile-fail/swm/unassign-function-from-wrong-pin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate lpc82x_hal;


use lpc82x_hal::Peripherals;
use lpc82x_hal::swm::{
self,
pin_state,
Pin,
};


fn main() {
let mut p = Peripherals::take().unwrap();

let swm = p.swm.split();
let mut syscon = p.syscon.split();

let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;
let pio0_1: Pin<_, pin_state::Unused> = swm.pins.pio0_1;

let u0_rxd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_rxd;

let (u0_rxd, _) = u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
let (u0_rxd, _) = u0_rxd.unassign(pio0_1.into_swm_pin(), &mut swm.handle);
//~^ ERROR mismatched types [E0308]
}
30 changes: 30 additions & 0 deletions tests/compile-fail/swm/unassign-unassigned-input-function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern crate lpc82x_hal;


use lpc82x_hal::Peripherals;
use lpc82x_hal::swm::{
self,
pin_state,
Pin,
};


fn main() {
let mut p = Peripherals::take().unwrap();

let swm = p.swm.split();
let mut syscon = p.syscon.split();

let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;

let u0_rxd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_rxd;

let (u0_rxd, pio0_0) =
u0_rxd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
let (u0_rxd, pio0_0) =
u0_rxd.unassign(pio0_0, &mut swm.handle);
let (u0_rxd, pio0_0) =
u0_rxd.unassign(pio0_0, &mut swm.handle);
//~^ ERROR no method named `unassign` found for type
}
30 changes: 30 additions & 0 deletions tests/compile-fail/swm/unassign-unassigned-output-function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern crate lpc82x_hal;


use lpc82x_hal::Peripherals;
use lpc82x_hal::swm::{
self,
pin_state,
Pin,
};


fn main() {
let mut p = Peripherals::take().unwrap();

let swm = p.swm.split();
let mut syscon = p.syscon.split();

let pio0_0: Pin<_, pin_state::Unused> = swm.pins.pio0_0;

let u0_txd: swm::Function<_, swm::state::Unassigned> =
swm.movable_functions.u0_txd;

let (u0_txd, pio0_0) =
u0_txd.assign(pio0_0.into_swm_pin(), &mut swm.handle);
let (u0_txd, pio0_0) =
u0_txd.unassign(pio0_0, &mut swm.handle);
let (u0_txd, pio0_0) =
u0_txd.unassign(pio0_0, &mut swm.handle);
//~^ ERROR no method named `unassign` found for type
}
28 changes: 28 additions & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![cfg(feature = "compiletest")]


extern crate compiletest_rs as compiletest;


use std::path::PathBuf;


#[test]
fn compile_test() {
run_mode("compile-fail");
}

fn run_mode(mode: &'static str) {
let mut config = compiletest::Config::default();

config.mode = mode.parse().expect("Failed to parse mode");
config.src_base = PathBuf::from(format!("tests/{}", mode));

// Needed by the compiler to find other crates
config.link_deps();

// Fixes E0464, "multiple matching crates"
config.clean_rmeta();

compiletest::run_tests(&config);
}