Skip to content

Commit

Permalink
Merge pull request #199 from dtolnay/list
Browse files Browse the repository at this point in the history
List out the normalization names in only one place
  • Loading branch information
dtolnay committed Oct 8, 2022
2 parents 5ad0497 + b5ea8bd commit 6a1e302
Showing 1 changed file with 39 additions and 45 deletions.
84 changes: 39 additions & 45 deletions src/normalize.rs
Expand Up @@ -2,6 +2,7 @@
#[path = "tests.rs"]
mod tests;

use self::Normalization::*;
use crate::directory::Directory;
use crate::run::PathDependency;
use std::cmp;
Expand All @@ -17,6 +18,40 @@ pub struct Context<'a> {
pub path_dependencies: &'a [PathDependency],
}

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

impl Normalization {
const ALL: &'static [Self] = &[$($name,)*];
}
};
}

normalizations! {
Basic,
StripCouldNotCompile,
StripCouldNotCompile2,
StripForMoreInformation,
StripForMoreInformation2,
TrimEnd,
RustLib,
TypeDirBackslash,
WorkspaceLines,
PathDependencies,
CargoRegistry,
ArrowOtherCrate,
RelativeToDir,
LinesOutsideInputFile,
Unindent,
AndOthers,
// New normalization steps are to be inserted here at the end so that any
// snapshots saved before your normalization change remain passing.
}

/// For a given compiler output, produces the set of saved outputs against which
/// the compiler's output would be considered correct. If the test's saved
/// stderr file is identical to any one of these variations, the test will pass.
Expand All @@ -31,27 +66,10 @@ pub struct Context<'a> {
pub fn diagnostics(output: &str, context: Context) -> Variations {
let output = output.replace("\r\n", "\n");

let variations = [
Basic,
StripCouldNotCompile,
StripCouldNotCompile2,
StripForMoreInformation,
StripForMoreInformation2,
TrimEnd,
RustLib,
TypeDirBackslash,
WorkspaceLines,
PathDependencies,
CargoRegistry,
ArrowOtherCrate,
RelativeToDir,
LinesOutsideInputFile,
Unindent,
AndOthers,
]
.iter()
.map(|normalization| apply(&output, *normalization, context))
.collect();
let variations = Normalization::ALL
.iter()
.map(|normalization| apply(&output, *normalization, context))
.collect();

Variations { variations }
}
Expand All @@ -70,30 +88,6 @@ impl Variations {
}
}

#[derive(PartialOrd, PartialEq, Copy, Clone)]
enum Normalization {
Basic,
StripCouldNotCompile,
StripCouldNotCompile2,
StripForMoreInformation,
StripForMoreInformation2,
TrimEnd,
RustLib,
TypeDirBackslash,
WorkspaceLines,
PathDependencies,
CargoRegistry,
ArrowOtherCrate,
RelativeToDir,
LinesOutsideInputFile,
Unindent,
AndOthers,
// New normalization steps are to be inserted here at the end so that any
// snapshots saved before your normalization change remain passing.
}

use self::Normalization::*;

pub fn trim<S: AsRef<[u8]>>(output: S) -> String {
let bytes = output.as_ref();
let mut normalized = String::from_utf8_lossy(bytes).into_owned();
Expand Down

0 comments on commit 6a1e302

Please sign in to comment.