From 3efdb1f1b65a2ce0b48cae779d7a8999f53a41b8 Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Sun, 3 Oct 2021 14:05:47 -0700 Subject: [PATCH 1/2] Use toml serializer for path string to handle platfrom-dependent escaping - needed for Windows support --- tests/tests/project.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tests/project.rs b/tests/tests/project.rs index f9abbf7..53822c6 100644 --- a/tests/tests/project.rs +++ b/tests/tests/project.rs @@ -4,6 +4,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; +use toml; pub fn target_tests() -> PathBuf { let mut path = env::current_exe().unwrap(); @@ -107,12 +108,12 @@ impl ProjectBuilder { r#" [[bin]] name = "{name}" - path = "{path}" + path = {path} test = false doc = false "#, name = name, - path = path.display(), + path = toml::to_string(&path).unwrap(), ) .unwrap(); From 2ea614d54e8f0a6b5a7d349c2314403dc412e3db Mon Sep 17 00:00:00 2001 From: Blake Johnson Date: Sun, 3 Oct 2021 15:21:25 -0700 Subject: [PATCH 2/2] Set expected error strings based on target_family when expected error is from the OS --- tests/tests/main.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/tests/main.rs b/tests/tests/main.rs index cb69755..80f0121 100644 --- a/tests/tests/main.rs +++ b/tests/tests/main.rs @@ -70,16 +70,21 @@ fn init_twice() { assert!(project.fuzz_target_path("fuzz_target_1").is_file()); // Second init should fail. + #[cfg(not(target_family = "windows"))] + let expected_err = "File exists (os error 17)"; + #[cfg(target_family = "windows")] + let expected_err = "Cannot create a file when that file already exists. (os error 183)"; + project .cargo_fuzz() .arg("init") .assert() - .stderr(predicates::str::contains("File exists (os error 17)").and( - predicates::str::contains(format!( + .stderr( + predicates::str::contains(expected_err).and(predicates::str::contains(format!( "failed to create directory {}", project.fuzz_dir().display() - )), - )) + ))), + ) .failure(); } @@ -134,6 +139,12 @@ fn add_twice() { .assert() .success(); assert!(project.fuzz_target_path("new_fuzz_target").is_file()); + + #[cfg(not(target_family = "windows"))] + let expected_err = "File exists (os error 17)"; + #[cfg(target_family = "windows")] + let expected_err = "The file exists. (os error 80)"; + project .cargo_fuzz() .arg("add") @@ -141,7 +152,7 @@ fn add_twice() { .assert() .stderr( predicate::str::contains("could not add target") - .and(predicate::str::contains("File exists (os error 17)")), + .and(predicate::str::contains(expected_err)), ) .failure(); }