Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Running Test Cases on Windows #280

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions tests/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -134,14 +139,20 @@ 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)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this fail to work on Windows systems that have the system language set to some other language than English?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I will look in to the localization impact.


project
.cargo_fuzz()
.arg("add")
.arg("new_fuzz_target")
.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();
}
Expand Down
5 changes: 3 additions & 2 deletions tests/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down