ITADN

#[serial] changes the return type of some tests which return Results

#126Closednilrem3 创建于 2025-03-19
N
nilrem3commented
The following test does not compile: ``` #[cfg(test)] mod test { use serial_test::serial; #[test] #[serial] fn test() -> Result<Result<(), ()>, ()> { Ok(Ok(())) } } ``` Instead, `cargo test` fails with the following error: ``` note: expected enum `Result<Result<(), ()>, ()>` found enum `Result<(), _>` note: this error originates in the attribute macro `serial` (in Nightly builds, run with -Z macro-backtrace for more info) ``` Removing the line `#[serial]` causes `cargo test` to work normally. This error also occurs with tests that return `Result<std::process::ExitCode, _>`. the serial proc macro seems to make the assumption that any test with the return type `Result<T, _>` will have `T=()`, but since `Result<T, _>` implements `Termination` for any `T: Termination`, there are other valid choices of return type.
关闭于 2025-03-21 2 条评论