diff options
| author | Miguel Ojeda <[email protected]> | 2025-05-02 21:51:27 +0000 |
|---|---|---|
| committer | Miguel Ojeda <[email protected]> | 2025-05-27 18:09:59 +0000 |
| commit | 950b306c296ec1e90d2d76f1974d2de2375a3d82 (patch) | |
| tree | 6b13860b7543c2da26c61a08b2c3ddb8bea15e04 /rust/macros/lib.rs | |
| parent | rust: kunit: support KUnit-mapped `assert!` macros in `#[test]`s (diff) | |
| download | kernel-950b306c296ec1e90d2d76f1974d2de2375a3d82.tar.gz kernel-950b306c296ec1e90d2d76f1974d2de2375a3d82.zip | |
rust: kunit: support checked `-> Result`s in KUnit `#[test]`s
Currently, return values of KUnit `#[test]` functions are ignored.
Thus introduce support for `-> Result` functions by checking their
returned values.
At the same time, require that test functions return `()` or `Result<T,
E>`, which should avoid mistakes, especially with non-`#[must_use]`
types. Other types can be supported in the future if needed.
With this, a failing test like:
#[test]
fn my_test() -> Result {
f()?;
Ok(())
}
will output:
[ 3.744214] KTAP version 1
[ 3.744287] # Subtest: my_test_suite
[ 3.744378] # speed: normal
[ 3.744399] 1..1
[ 3.745817] # my_test: ASSERTION FAILED at rust/kernel/lib.rs:321
[ 3.745817] Expected is_test_result_ok(my_test()) to be true, but is false
[ 3.747152] # my_test.speed: normal
[ 3.747199] not ok 1 my_test
[ 3.747345] not ok 4 my_test_suite
Reviewed-by: David Gow <[email protected]>
Acked-by: Danilo Krummrich <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Used `::kernel` for paths. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/macros/lib.rs')
0 files changed, 0 insertions, 0 deletions
