From ac3879525a80f2ec844794d857224985ba1e5842 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 15 Jan 2024 14:48:52 -0800 Subject: [PATCH] Try to make symlink testdata more robust --- testdata/symlink/src/lib.rs | 10 +--------- testdata/symlink/tests/main.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 testdata/symlink/tests/main.rs diff --git a/testdata/symlink/src/lib.rs b/testdata/symlink/src/lib.rs index 7129f12d..e5c13ca2 100644 --- a/testdata/symlink/src/lib.rs +++ b/testdata/symlink/src/lib.rs @@ -1,15 +1,7 @@ use std::path::Path; -fn read_through_symlink() -> String { +pub fn read_through_symlink() -> String { let path = Path::new("testdata/symlink"); assert!(path.is_symlink()); std::fs::read_to_string(path).unwrap() } - -#[cfg(test)] -mod test { - #[test] - fn read_through_symlink_test() { - assert_eq!(super::read_through_symlink().trim(), "Hello, world!"); - } -} diff --git a/testdata/symlink/tests/main.rs b/testdata/symlink/tests/main.rs new file mode 100644 index 00000000..a36d4a69 --- /dev/null +++ b/testdata/symlink/tests/main.rs @@ -0,0 +1,22 @@ +use std::fs::{read_link, read_to_string}; +use std::path::Path; + +use cargo_mutants_testdata_symlink::read_through_symlink; + +#[test] +fn read_through_symlink_test() { + assert_eq!(read_through_symlink().trim(), "Hello, world!"); +} + +/// This should fail from the baseline test if the symlink is somehow +/// missing. +#[test] +fn symlink_testdata_exists() { + let target = Path::new("testdata/target"); + let symlink = Path::new("testdata/symlink"); + assert!(symlink.is_symlink()); + assert!(target.is_file()); + assert_eq!(read_link(&symlink).unwrap(), Path::new("target")); + assert_eq!(read_to_string(&target).unwrap().trim(), "Hello, world!"); + assert_eq!(read_to_string(&symlink).unwrap().trim(), "Hello, world!"); +}