Skip to content

Commit

Permalink
Tweak tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 18, 2023
1 parent dbb29bd commit 036f77a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions tests/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ use std::{
};

use anyhow::{bail, Context as _, Result};
use camino::Utf8Path;
use easy_ext::ext;
use fs_err as fs;
use tempfile::TempDir;

pub fn fixtures_path() -> &'static Utf8Path {
Utf8Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures"))
pub fn fixtures_path() -> &'static Path {
Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures"))
}

fn ensure_llvm_tools_installed() {
Expand Down Expand Up @@ -81,7 +80,7 @@ pub fn test_report(
assert_output(output_path, expected)
}

pub fn assert_output(output_path: &Utf8Path, expected: &str) -> Result<()> {
pub fn assert_output(output_path: &Path, expected: &str) -> Result<()> {
if env::var_os("CI").is_some() {
let mut child = Command::new("git")
.args(["--no-pager", "diff", "--no-index", "--"])
Expand All @@ -95,7 +94,7 @@ pub fn assert_output(output_path: &Utf8Path, expected: &str) -> Result<()> {
Ok(())
}

pub fn normalize_output(output_path: &Utf8Path, args: &[&str]) -> Result<()> {
pub fn normalize_output(output_path: &Path, args: &[&str]) -> Result<()> {
if args.contains(&"--json") {
let s = fs::read_to_string(output_path)?;
let mut json = serde_json::from_str::<cargo_llvm_cov::json::LlvmCovJsonExport>(&s).unwrap();
Expand All @@ -117,7 +116,7 @@ pub fn test_project(model: &str) -> Result<TempDir> {
let workspace_root = tmpdir.path();
let model_path = fixtures_path().join("crates").join(model);

for (file_name, from) in git_ls_files(model_path.as_std_path(), &[])? {
for (file_name, from) in git_ls_files(&model_path, &[])? {
let to = &workspace_root.join(file_name);
if !to.parent().unwrap().is_dir() {
fs::create_dir_all(to.parent().unwrap())?;
Expand Down
8 changes: 4 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

mod auxiliary;

use std::path::Path;

use anyhow::Context as _;
use auxiliary::{
assert_output, cargo_llvm_cov, fixtures_path, normalize_output, perturb_one_header,
test_project, test_report, CommandExt,
};
use camino::Utf8Path;
use fs_err as fs;
use tempfile::tempdir;

Expand Down Expand Up @@ -175,11 +176,10 @@ fn merge() {
#[test]
fn merge_failure_mode_all() {
let tempdir = tempdir().unwrap();
let output_dir = Utf8Path::from_path(tempdir.path()).unwrap();
merge_with_failure_mode(output_dir, true);
merge_with_failure_mode(tempdir.path(), true);
}

fn merge_with_failure_mode(output_dir: &Utf8Path, failure_mode_all: bool) {
fn merge_with_failure_mode(output_dir: &Path, failure_mode_all: bool) {
let model = "merge";
fs::create_dir_all(output_dir).unwrap();
for (extension, args) in test_set() {
Expand Down

0 comments on commit 036f77a

Please sign in to comment.