是否可以在Rust中编写测试,以便它不能在特定的操作系统上运行?

时间:2018-03-31 13:07:31

标签: rust

我正在写一个测试:

#[cfg(test)]
mod tests {
    #[test]
    fn test_something() {
        //content of test function
    }
}

是否可以在使用Windows时运行此测试并仅在Linux上运行?

1 个答案:

答案 0 :(得分:3)

您可以选择不编译测试

#[cfg(not(target_os = "windows"))]
#[test]
fn test_something() {
    //content of test function
}

或者您可以选择编译它但不运行它:

#[test]
#[cfg_attr(target_os = "windows", ignore)]
fn test_something() {
    //content of test function
}

另见: