Skip to content

Commit

Permalink
add tests for scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
hdhoang committed Dec 17, 2018
1 parent 1b6ff62 commit b37d9db
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ os:

matrix:
include:
- env: JOB=tests
os: linux
script:
make test

- env: JOB=rustfmt
os: linux
install:
Expand All @@ -33,7 +38,6 @@ install:
script:
- make
- cargo build --features use_semihosting
- "[[ ${TRAVIS_OS_NAME} != 'windows' ]] && make bloat"

cache:
cargo: true
Expand All @@ -53,7 +57,7 @@ branches:

deploy:
on:
condition: "${TRAVIS_OS_NAME} == 'linux'"
condition: "${TRAVIS_OS_NAME} != 'linux'"
provider: releases
api_key:
secure: "hSYihrRGZNCwdZQkmQoIlPHsUYewhaKJpui45vR8vYyUg3S1l2lGPTkIffA5VILZ/ozZiB/uynYNJlRxGG0+ZyZzZRsHEUS8dY/GpYHEjEvAMVJE/JkG4gKcXD7q9Tvwdik7huzzilAjbw4wAdkY3IiIXMQhpoPc3Dele7RTUdilpWzi3UtZyvrs0k0f2Gfovu2yXkkpXsC5Pwm17Pe0sGa+ilB1OlZ1lWrCA8zHtSBH+V4IztgKf1c7kPr5nWG8uLvMYmlun9l0/ahymh8SJyAOm0EHkhfZYCX/EG2JG0NYTAQJ88Ags+xbDWaoGtNo+R+yzAUG5PfcaAXKAj6I10Rsg6/ckCSFlliDtKi6qrV2+YmbnXchy97PqlJM0zZKWzpvncXlhJ46O3DoMm4L5btj9hCahagqfJpNEZ8olnLlVhzFTGBGPyQVvMudPXcFSDMHLGejNPxua5lq+LOlEH2gSezDc9Qzm96tpiYu1lKt8Ousz7lAin9BS/7+ES7W2Fx2I5cQ7965kxARGzyhHCQXOkGPrj/M6tW6qlec3AS6yM+oxTvQnKJPhbERaClio46NukUbIG4CZ+Hwi2jtb8tLQ6g1J7fbA2ac3faiw3MmZDNmGSW0DGaOUkv/EGuoHc5sTNR6fITYTbkH2g24G1iYnsg3kLNiseSkODJxySo="
Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ opt-level = 3
debug = true
lto = false
opt-level = 3

[workspace]
members = ["tests"]
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ fmt:
rustup component add rustfmt
cargo fmt

test:
cd tests; cargo test --target $(shell rustup target list | grep default | cut -d ' ' -f 1)

clippy:
rustup component add clippy
cargo clippy
Expand All @@ -33,4 +36,4 @@ clean:
rm -f anne-key.dfu
rm -rf _book/

.PHONY: all build clean debug openocd bloat fmt clippy
.PHONY: all build clean debug openocd bloat fmt clippy test
2 changes: 1 addition & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Message<'a> {
}

#[non_exhaustive]
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum MsgType {
Reserved,
Error,
Expand Down
6 changes: 6 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "anne-tests"
version = "0.0.0"

[dependencies]
scroll = "^0.9"
23 changes: 23 additions & 0 deletions tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![feature(non_exhaustive)]
extern crate core;
extern crate scroll;
use scroll::{Cwrite, Pread};

#[path = "../../src/protocol.rs"]
mod protocol;
use protocol::MsgType;

#[test]
fn msgtype_round_trip() {
let mut buffer: [u8; 5] = [255; 5];
let e = MsgType::Error;
let f = MsgType::FwInfo;
buffer.cwrite(e, 0);
buffer.cwrite(f, 4);
assert_eq!(e, buffer.pread(0).unwrap());
assert_eq!(f, buffer.pread(4).unwrap());
assert_eq!(buffer, [1, 255, 255, 255, 10]);
assert!(buffer.pread::<MsgType>(2).is_err());
}

fn main() {}

0 comments on commit b37d9db

Please sign in to comment.