From c09a8e52233ddafe7cefeca8c9f1c5979f63f80e Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 12 Jul 2018 10:44:13 +0200 Subject: Adapt codegen-unit tests to new CGU naming scheme. --- src/tools/compiletest/src/runtest.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/tools/compiletest') diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4b246ab6745..b1361730826 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2209,12 +2209,12 @@ impl<'test> TestCx<'test> { .stdout .lines() .filter(|line| line.starts_with(PREFIX)) - .map(str_to_mono_item) + .map(|line| str_to_mono_item(line, true)) .collect(); let expected: Vec = errors::load_errors(&self.testpaths.file, None) .iter() - .map(|e| str_to_mono_item(&e.msg[..])) + .map(|e| str_to_mono_item(&e.msg[..], false)) .collect(); let mut missing = Vec::new(); @@ -2299,14 +2299,14 @@ impl<'test> TestCx<'test> { } // [MONO_ITEM] name [@@ (cgu)+] - fn str_to_mono_item(s: &str) -> MonoItem { + fn str_to_mono_item(s: &str, cgu_has_crate_disambiguator: bool) -> MonoItem { let s = if s.starts_with(PREFIX) { (&s[PREFIX.len()..]).trim() } else { s.trim() }; - let full_string = format!("{}{}", PREFIX, s.trim().to_owned()); + let full_string = format!("{}{}", PREFIX, s); let parts: Vec<&str> = s .split(CGU_MARKER) @@ -2323,7 +2323,13 @@ impl<'test> TestCx<'test> { .split(' ') .map(str::trim) .filter(|s| !s.is_empty()) - .map(str::to_owned) + .map(|s| { + if cgu_has_crate_disambiguator { + remove_crate_disambiguator_from_cgu(s) + } else { + s.to_string() + } + }) .collect() } else { HashSet::new() @@ -2348,6 +2354,23 @@ impl<'test> TestCx<'test> { string } + + fn remove_crate_disambiguator_from_cgu(cgu: &str) -> String { + // The first '.' is the start of the crate disambiguator + let disambiguator_start = cgu.find('.') + .expect("Could not find start of crate disambiguator in CGU spec"); + + // The first non-alphanumeric character is the end of the disambiguator + let disambiguator_end = cgu[disambiguator_start + 1 ..] + .find(|c| !char::is_alphanumeric(c)) + .expect("Could not find end of crate disambiguator in CGU spec") + + disambiguator_start + 1; + + let mut result = cgu[0 .. disambiguator_start].to_string(); + result.push_str(&cgu[disambiguator_end ..]); + + result + } } fn init_incremental_test(&self) { -- cgit 1.4.1-3-g733a5