zerodds_conformance/
lib.rs1#![no_std]
24#![forbid(unsafe_code)]
25#![warn(missing_docs)]
26
27extern crate alloc;
28
29#[cfg(feature = "std")]
30extern crate std;
31
32pub mod autobahn_ws;
33pub mod coap_plugtest;
34pub mod dds_xml_xvendor;
35pub mod h2spec_grpc;
36pub mod oasis_mqtt;
37
38#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum CaseResult {
41 Pass,
43 Fail(alloc::string::String),
45 Skip(&'static str),
47}
48
49impl CaseResult {
50 #[must_use]
52 pub fn is_acceptable(&self) -> bool {
53 !matches!(self, Self::Fail(_))
54 }
55}
56
57pub struct TestCase {
59 pub name: &'static str,
61 pub run: fn() -> CaseResult,
63}
64
65#[must_use]
67pub fn run_suite(suite: &[TestCase]) -> (usize, usize, usize) {
68 let mut pass = 0usize;
69 let mut skip = 0usize;
70 let mut fail = 0usize;
71 for c in suite {
72 match (c.run)() {
73 CaseResult::Pass => pass += 1,
74 CaseResult::Skip(_) => skip += 1,
75 CaseResult::Fail(_) => fail += 1,
76 }
77 }
78 (pass, skip, fail)
79}
80
81#[cfg(test)]
82#[allow(clippy::expect_used, clippy::unwrap_used, clippy::panic)]
83mod tests {
84 use super::*;
85
86 #[test]
87 fn case_result_pass_acceptable() {
88 assert!(CaseResult::Pass.is_acceptable());
89 assert!(CaseResult::Skip("foo").is_acceptable());
90 assert!(!CaseResult::Fail("bar".into()).is_acceptable());
91 }
92
93 #[test]
94 fn run_suite_reports_counts() {
95 fn p() -> CaseResult {
96 CaseResult::Pass
97 }
98 fn s() -> CaseResult {
99 CaseResult::Skip("x")
100 }
101 fn f() -> CaseResult {
102 CaseResult::Fail("y".into())
103 }
104 let suite = [
105 TestCase { name: "a", run: p },
106 TestCase { name: "b", run: s },
107 TestCase { name: "c", run: f },
108 ];
109 let (p, s, f) = run_suite(&suite);
110 assert_eq!((p, s, f), (1, 1, 1));
111 }
112}