Attribute Macro test_with::file

source · []
#[file]
Expand description

Run test case when the file exist.

#[cfg(test)]
mod tests {

    // hostname exists
    #[test_with::file(/etc/hostname)]
    #[test]
    fn test_works() {
        assert!(true);
    }

    // nothing file does not exist
    #[test_with::file(/etc/nothing)]
    #[test]
    fn test_ignored() {
        panic!("should be ignored")
    }

    // hostname and hosts exist
    #[test_with::file(/etc/hostname, /etc/hosts)]
    #[test]
    fn test_works_too() {
        assert!(true);
    }
}