ktest 0.1.6

A custom test framework for Rust-based operating system kernels
Documentation
#![no_std]

#![feature(try_blocks)]

#![cfg_attr(test, no_main)]
#![cfg_attr(test, feature(custom_test_frameworks))]
#![cfg_attr(test, test_runner(runner))]
#![cfg_attr(test, reexport_test_harness_main = "test_harness")]

#[cfg(test)]
extern crate self as ktest;

mod args;
mod log;
pub mod memory;
pub mod macros;
pub mod test;
mod qemu;

/// Re-export the test runner function for use in test binaries.
pub use ktest_macros::ktest;
pub use macros::klib::{KlibConfig, KlibConfigBuilder};
pub use test::{runner::runner, Test, split_module_path, split_module_path_len};

/// Maximum length for strings used in this library, to avoid dynamic allocations.
const MAX_STRING_LENGTH: usize = 1024;

/// Initialize the test harness with the given test group. This function should be called
/// before the main test function is called.
/// 
/// For example, in your lib.rs:
/// 
/// ```
/// ktest::init_harness("library");
/// test_main();
/// ```
/// 
/// If you are using the `klib!` macro, this function is called automatically.
/// 
pub fn init_harness(test_group: &str) {
    args::set_test_group(test_group);
}

/// A panic handler that delegates to the test runner's panic handler. This should be
/// included in libraries which use `ktest` to allow recovery from panics during tests.
/// 
/// Only include this in test builds.
/// 
/// For example, in your lib.rs:
/// 
/// ```
/// #[cfg(test)]
/// #[panic_handler]
/// fn panic(info: &core::panic::PanicInfo) -> ! {
///     ktest::panic(info)
/// }
/// ```
/// 
/// If you are using the `klib!` macro, this function is included automatically.
pub fn panic(info: &core::panic::PanicInfo) -> ! {
    use crate::test::runner::TestRunner;
    use crate::test::runner::TEST_RUNNER;

    TEST_RUNNER.get().unwrap().handle_panic(info)
}