Skip to content

Commit

Permalink
Merge pull request #299 from Sh3Rm4n/test-defmt-test
Browse files Browse the repository at this point in the history
Test defmt-test
  • Loading branch information
japaric authored Dec 10, 2020
2 parents c599ba2 + b91cd36 commit 5ae5d37
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions firmware/qemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version = "0.1.0"
[dependencies]
defmt = { path = "../.." }
defmt-semihosting = { path = "../defmt-semihosting" }
defmt-test = { path = "../defmt-test" }
cortex-m = "0.6.0"
cortex-m-rt = "0.6.10"
cortex-m-semihosting = "0.3.3"
Expand Down Expand Up @@ -56,3 +57,7 @@ test = false
name = "alloc"
test = false
required-features = ["alloc"]

[[bin]]
name = "defmt-test"
test = false
6 changes: 6 additions & 0 deletions firmware/qemu/src/bin/defmt-test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0.000000 INFO (1/3) running `assert_true`...
0.000000 INFO (2/3) running `assert_imported_max`...
0.000000 INFO (3/3) running `assert_eq`...
0.000000 ERROR panicked at 'assertion failed: `(left == right)`: TODO: write actual tests'
left: `24`
right: `42`
6 changes: 6 additions & 0 deletions firmware/qemu/src/bin/defmt-test.release.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0.000000 INFO (1/3) running `assert_true`...
0.000000 INFO (2/3) running `assert_imported_max`...
0.000000 INFO (3/3) running `assert_eq`...
0.000000 ERROR panicked at 'assertion failed: `(left == right)`: TODO: write actual tests'
left: `24`
right: `42`
35 changes: 35 additions & 0 deletions firmware/qemu/src/bin/defmt-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![no_std]
#![no_main]

use defmt_semihosting as _; // global logger
use core::u8::MAX;

#[defmt_test::tests]
mod tests {
use super::MAX;
#[test]
fn assert_true() {
defmt::assert!(true)
}

#[test]
fn assert_imported_max() {
defmt::assert_eq!(255, MAX)
}

#[test]
fn assert_eq() {
defmt::assert_eq!(24, 42, "TODO: write actual tests")
}
}

// like `panic-semihosting` but doesn't print to stdout (that would corrupt the defmt stream)
#[cfg(target_os = "none")]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
use cortex_m_semihosting::debug;

loop {
debug::exit(debug::EXIT_SUCCESS)
}
}
1 change: 1 addition & 0 deletions firmware/qemu/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test "assert-eq"
test "assert-ne"
test "double-write"
test "unwrap"
test "defmt-test"
if rustc -V | grep nightly; then
test "alloc" "alloc"
fi

0 comments on commit 5ae5d37

Please sign in to comment.