Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fuzz/fuzz_targets/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod directory;
mod normalize;

use crate::directory::Directory;
use crate::normalize::Context;
use crate::normalize::{Context, Normalization};
use crate::run::PathDependency;
use libfuzzer_sys::fuzz_target;
use std::path::Path;
Expand All @@ -18,6 +18,7 @@ mod run {
pub struct PathDependency {
pub name: String,
pub normalized_path: super::Directory,
pub normalization: super::Normalization,
}
}

Expand All @@ -34,6 +35,7 @@ fuzz_target!(|string: &str| {
path_dependencies: &[PathDependency {
name: String::from("diesel"),
normalized_path: Directory::new("/home/user/documents/rust/diesel/diesel"),
normalization: Normalization::PathDependencies,
}],
};
let _ = normalize::diagnostics(string, context);
Expand Down
28 changes: 16 additions & 12 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub(crate) struct Context<'a> {

macro_rules! normalizations {
($($name:ident,)*) => {
#[derive(PartialOrd, PartialEq, Copy, Clone)]
enum Normalization {
#[derive(PartialOrd, PartialEq, Copy, Clone, Debug)]
pub(crate) enum Normalization {
$($name,)*
}

Expand Down Expand Up @@ -65,6 +65,7 @@ normalizations! {
HeadingNote,
UnindentSuggestion,
CustomRegistry,
MorePathDependencies,
// New normalization steps are to be inserted here at the end so that any
// snapshots saved before your normalization change remain passing.
}
Expand Down Expand Up @@ -265,16 +266,19 @@ impl<'a> Filter<'a> {
}
if self.normalization >= PathDependencies && !other_crate {
for path_dep in self.context.path_dependencies {
let path_dep_pat = path_dep
.normalized_path
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
if let Some(i) = line_lower.find(&path_dep_pat) {
let var = format!("${}", path_dep.name.to_uppercase().replace('-', "_"));
line.replace_range(i..i + path_dep_pat.len() - 1, &var);
other_crate = true;
break;
if self.normalization >= path_dep.normalization {
let path_dep_pat = path_dep
.normalized_path
.to_string_lossy()
.to_ascii_lowercase()
.replace('\\', "/");
if let Some(i) = line_lower.find(&path_dep_pat) {
let var =
format!("${}", path_dep.name.to_uppercase().replace('-', "_"));
line.replace_range(i..i + path_dep_pat.len() - 1, &var);
other_crate = true;
break;
}
}
}
}
Expand Down
47 changes: 32 additions & 15 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::expand::{ExpandedTest, expand_globs};
use crate::flock::Lock;
use crate::manifest::{Bin, Manifest, Name, Package, Workspace};
use crate::message::{self, Fail, Warn};
use crate::normalize::{self, Context, Variations};
use crate::normalize::{self, Context, Normalization, Variations};
use crate::path::CanonicalPath;
use crate::{Expected, Runner, Test, features};
use serde_derive::Deserialize;
Expand Down Expand Up @@ -39,6 +39,7 @@ pub(crate) struct Project {
pub(crate) struct PathDependency {
pub name: String,
pub normalized_path: Directory,
pub normalization: Normalization,
}

struct Report {
Expand Down Expand Up @@ -130,22 +131,38 @@ impl Runner {

let mut features = features::find();

let path_dependencies = source_manifest
.dependencies
.iter()
.filter_map(|(name, dep)| {
let path = dep.path.as_ref()?;
if packages.iter().any(|p| &p.name == name) {
let mut path_dependencies = Vec::new();
let mut collect_path_dependencies =
|dependencies: &Map<String, Dependency>, normalization: Normalization| {
for (name, dep) in dependencies {
if let Some(path) = &dep.path
// Skip path dependencies coming from the workspace itself
None
} else {
Some(PathDependency {
name: name.clone(),
normalized_path: path.canonicalize().ok()?,
})
&& !packages.iter().any(|p| &p.name == name)
&& let Ok(normalized_path) = path.canonicalize()
{
path_dependencies.push(PathDependency {
name: name.clone(),
normalized_path,
normalization,
});
}
}
})
.collect();
};
collect_path_dependencies(
&source_manifest.dependencies,
Normalization::PathDependencies,
);
collect_path_dependencies(
&source_manifest.dev_dependencies,
Normalization::MorePathDependencies,
);
for target in source_manifest.target.values() {
collect_path_dependencies(&target.dependencies, Normalization::MorePathDependencies);
collect_path_dependencies(
&target.dev_dependencies,
Normalization::MorePathDependencies,
);
}

let crate_name = &source_manifest.package.name;
let project_dir = path!(target_dir / "tests" / "trybuild" / crate_name /);
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ macro_rules! test_normalize {
path_dependencies: &[crate::run::PathDependency {
name: String::from("diesel"),
normalized_path: crate::directory::Directory::new("/home/user/documents/rust/diesel/diesel"),
normalization: crate::normalize::Normalization::PathDependencies,
}],
};
let original = $original;
Expand Down