oxedyne/fe2o3/fe2o3_test/src/lib.rs
2.2 KiB, 10 runs
created by r1870400018:1079, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! A testing utility crate for the Hematite ecosystem that provides a structured way to organise and run |
| 2 | //! tests. |
| 3 | //! |
| 4 | //! # Test Organisation |
| 5 | //! |
| 6 | //! Tests in Hematite projects typically follow this structure: |
| 7 | //! |
| 8 | //! - A `tests/main.rs` file as the entry point that configures logging and runs all test modules |
| 9 | //! - Individual test modules (e.g. `tests/map.rs`, `tests/string.rs`) containing related test functions |
| 10 | //! - Use of the `test_it!` macro to implement filterable, grouped test cases |
| 11 | //! |
| 12 | //! # Example Usage |
| 13 | //! |
| 14 | //! In your `tests/main.rs`: |
| 15 | //! ```ignore |
| 16 | //! mod map; |
| 17 | //! mod string; |
| 18 | //! |
| 19 | //! use oxedyne_fe2o3_core::prelude::*; |
| 20 | //! |
| 21 | //! #[test] |
| 22 | //! fn main() -> Outcome<()> { |
| 23 | //! // Set up logging before running tests |
| 24 | //! log_set_level!("test"); |
| 25 | //! |
| 26 | //! let outcome = run_tests(); |
| 27 | //! |
| 28 | //! // Allow logger thread to complete before exiting |
| 29 | //! log_finish_wait!(); |
| 30 | //! |
| 31 | //! outcome |
| 32 | //! } |
| 33 | //! |
| 34 | //! fn run_tests() -> Outcome<()> { |
| 35 | //! let filter = "all"; // Or specific test group |
| 36 | //! |
| 37 | //! res!(map::test_map_func(filter)); |
| 38 | //! res!(string::test_string_func(filter)); |
| 39 | //! |
| 40 | //! Ok(()) |
| 41 | //! } |
| 42 | //! ``` |
| 43 | //! |
| 44 | //! In your test modules (e.g. `tests/map.rs`): |
| 45 | //! ```rust |
| 46 | //! use oxedyne_fe2o3_core::{prelude::*, test::test_it}; |
| 47 | //! |
| 48 | //! pub fn test_map_func(filter: &'static str) -> Outcome<()> { |
| 49 | //! // Run test cases that match the filter |
| 50 | //! res!(test_it(filter, &["Map Find 000", "all", "map"], || { |
| 51 | //! // Your test code here |
| 52 | //! Ok(()) |
| 53 | //! })); |
| 54 | //! |
| 55 | //! // Additional test cases... |
| 56 | //! res!(test_it(filter, &["Map Find 010", "all", "map"], || { |
| 57 | //! // More test code |
| 58 | //! Ok(()) |
| 59 | //! })); |
| 60 | //! |
| 61 | //! Ok(()) |
| 62 | //! } |
| 63 | //! ``` |
| 64 | //! |
| 65 | //! The `test_it` macro allows you to: |
| 66 | //! - Group related test cases together in a single test function |
| 67 | //! - Filter which tests run using tags |
| 68 | //! - Provide descriptive names for test cases |
| 69 | //! - Ensure proper error handling and logging throughout the test suite |
| 70 | //! |
| 71 | #![forbid(unsafe_code)] |
| 72 | pub mod data; |
| 73 | pub mod error; |
| 74 | /// Scratch directories for fixtures that need a real filesystem, kept out of the |
| 75 | /// system temporary directory and swept clean of what earlier runs left behind. |
| 76 | pub mod scratch; |