Skip to content

Commit

Permalink
test: add no_std compatibly test crate
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Dohrmann <[email protected]>
  • Loading branch information
Freax13 committed Oct 23, 2023
1 parent aecbe8c commit 251359d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "test"
version = "0.1.0"
edition = "2021"

[dependencies]
46 changes: 46 additions & 0 deletions test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! This crate contains a very stripped down copy of the `test` crate.
//! `test` usually requires full `std` support, but we need to use it from a
//! `no_std` target.
//! The `test` crate is implicitly used by the `#[test]` attribute.
#![no_std]

#[derive(Clone, Copy)]
pub struct TestDescAndFn {
pub testfn: StaticTestFn,
pub desc: TestDesc,
}

#[derive(Clone, Copy)]
pub struct StaticTestFn(pub fn());

#[derive(Clone, Copy)]
pub struct TestDesc {
pub name: StaticTestName,
pub ignore: bool,
pub ignore_message: Option<&'static str>,
pub source_file: &'static str,
pub start_line: usize,
pub start_col: usize,
pub end_line: usize,
pub end_col: usize,
pub should_panic: ShouldPanic,
pub compile_fail: bool,
pub no_run: bool,
pub test_type: TestType,
}

#[derive(Clone, Copy)]
pub struct StaticTestName(pub &'static str);

#[derive(Clone, Copy)]
pub enum TestType {
UnitTest,
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum ShouldPanic {
Yes,
No,
}

pub fn assert_test_result(_: ()) {}

0 comments on commit 251359d

Please sign in to comment.