【问题标题】:Is it possible to write a test in Rust so it does not run on a specific operating system?是否可以用 Rust 编写测试,使其不在特定操作系统上运行?
【发布时间】:2018-03-31 22:58:53
【问题描述】:

我正在写一个测试:

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

是否可以让这个测试在使用 Windows 时不运行而只在 Linux 上运行?

【问题讨论】:

    标签: rust


    【解决方案1】:

    您可以选择根本不编译测试

    #[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
    }
    

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多