Rollup merge of #35448 - srinivasreddy:rf_compiletest, r=nikomatsakis
run rustfmt on compiletest folder in src/tools/ folder
This commit is contained in:
commit
b17904234a
@ -36,22 +36,22 @@ impl FromStr for Mode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Mode, ()> {
|
||||
match s {
|
||||
"compile-fail" => Ok(CompileFail),
|
||||
"parse-fail" => Ok(ParseFail),
|
||||
"run-fail" => Ok(RunFail),
|
||||
"run-pass" => Ok(RunPass),
|
||||
"run-pass-valgrind" => Ok(RunPassValgrind),
|
||||
"pretty" => Ok(Pretty),
|
||||
"debuginfo-lldb" => Ok(DebugInfoLldb),
|
||||
"debuginfo-gdb" => Ok(DebugInfoGdb),
|
||||
"codegen" => Ok(Codegen),
|
||||
"rustdoc" => Ok(Rustdoc),
|
||||
"codegen-units" => Ok(CodegenUnits),
|
||||
"incremental" => Ok(Incremental),
|
||||
"run-make" => Ok(RunMake),
|
||||
"ui" => Ok(Ui),
|
||||
"mir-opt" => Ok(MirOpt),
|
||||
_ => Err(()),
|
||||
"compile-fail" => Ok(CompileFail),
|
||||
"parse-fail" => Ok(ParseFail),
|
||||
"run-fail" => Ok(RunFail),
|
||||
"run-pass" => Ok(RunPass),
|
||||
"run-pass-valgrind" => Ok(RunPassValgrind),
|
||||
"pretty" => Ok(Pretty),
|
||||
"debuginfo-lldb" => Ok(DebugInfoLldb),
|
||||
"debuginfo-gdb" => Ok(DebugInfoGdb),
|
||||
"codegen" => Ok(Codegen),
|
||||
"rustdoc" => Ok(Rustdoc),
|
||||
"codegen-units" => Ok(CodegenUnits),
|
||||
"incremental" => Ok(Incremental),
|
||||
"run-make" => Ok(RunMake),
|
||||
"ui" => Ok(Ui),
|
||||
"mir-opt" => Ok(MirOpt),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,22 +59,23 @@ impl FromStr for Mode {
|
||||
impl fmt::Display for Mode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(match *self {
|
||||
CompileFail => "compile-fail",
|
||||
ParseFail => "parse-fail",
|
||||
RunFail => "run-fail",
|
||||
RunPass => "run-pass",
|
||||
RunPassValgrind => "run-pass-valgrind",
|
||||
Pretty => "pretty",
|
||||
DebugInfoGdb => "debuginfo-gdb",
|
||||
DebugInfoLldb => "debuginfo-lldb",
|
||||
Codegen => "codegen",
|
||||
Rustdoc => "rustdoc",
|
||||
CodegenUnits => "codegen-units",
|
||||
Incremental => "incremental",
|
||||
RunMake => "run-make",
|
||||
Ui => "ui",
|
||||
MirOpt => "mir-opt",
|
||||
}, f)
|
||||
CompileFail => "compile-fail",
|
||||
ParseFail => "parse-fail",
|
||||
RunFail => "run-fail",
|
||||
RunPass => "run-pass",
|
||||
RunPassValgrind => "run-pass-valgrind",
|
||||
Pretty => "pretty",
|
||||
DebugInfoGdb => "debuginfo-gdb",
|
||||
DebugInfoLldb => "debuginfo-lldb",
|
||||
Codegen => "codegen",
|
||||
Rustdoc => "rustdoc",
|
||||
CodegenUnits => "codegen-units",
|
||||
Incremental => "incremental",
|
||||
RunMake => "run-make",
|
||||
Ui => "ui",
|
||||
MirOpt => "mir-opt",
|
||||
},
|
||||
f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,11 @@ pub struct Error {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
enum WhichLine { ThisLine, FollowPrevious(usize), AdjustBackward(usize) }
|
||||
enum WhichLine {
|
||||
ThisLine,
|
||||
FollowPrevious(usize),
|
||||
AdjustBackward(usize),
|
||||
}
|
||||
|
||||
/// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
|
||||
/// The former is a "follow" that inherits its target from the preceding line;
|
||||
@ -91,25 +95,22 @@ pub fn load_errors(testfile: &Path, cfg: Option<&str>) -> Vec<Error> {
|
||||
|
||||
let tag = match cfg {
|
||||
Some(rev) => format!("//[{}]~", rev),
|
||||
None => format!("//~")
|
||||
None => format!("//~"),
|
||||
};
|
||||
|
||||
rdr.lines()
|
||||
.enumerate()
|
||||
.filter_map(|(line_num, line)| {
|
||||
parse_expected(last_nonfollow_error,
|
||||
line_num + 1,
|
||||
&line.unwrap(),
|
||||
&tag)
|
||||
.map(|(which, error)| {
|
||||
match which {
|
||||
FollowPrevious(_) => {}
|
||||
_ => last_nonfollow_error = Some(error.line_num),
|
||||
}
|
||||
error
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
.enumerate()
|
||||
.filter_map(|(line_num, line)| {
|
||||
parse_expected(last_nonfollow_error, line_num + 1, &line.unwrap(), &tag)
|
||||
.map(|(which, error)| {
|
||||
match which {
|
||||
FollowPrevious(_) => {}
|
||||
_ => last_nonfollow_error = Some(error.line_num),
|
||||
}
|
||||
error
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn parse_expected(last_nonfollow_error: Option<usize>,
|
||||
@ -117,7 +118,10 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
|
||||
line: &str,
|
||||
tag: &str)
|
||||
-> Option<(WhichLine, Error)> {
|
||||
let start = match line.find(tag) { Some(i) => i, None => return None };
|
||||
let start = match line.find(tag) {
|
||||
Some(i) => i,
|
||||
None => return None,
|
||||
};
|
||||
let (follow, adjusts) = if line[start + tag.len()..].chars().next().unwrap() == '|' {
|
||||
(true, 0)
|
||||
} else {
|
||||
@ -125,26 +129,25 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
|
||||
};
|
||||
let kind_start = start + tag.len() + adjusts + (follow as usize);
|
||||
let (kind, msg);
|
||||
match
|
||||
line[kind_start..].split_whitespace()
|
||||
.next()
|
||||
.expect("Encountered unexpected empty comment")
|
||||
.parse::<ErrorKind>()
|
||||
{
|
||||
match line[kind_start..]
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.expect("Encountered unexpected empty comment")
|
||||
.parse::<ErrorKind>() {
|
||||
Ok(k) => {
|
||||
// If we find `//~ ERROR foo` or something like that:
|
||||
kind = Some(k);
|
||||
let letters = line[kind_start..].chars();
|
||||
msg = letters.skip_while(|c| c.is_whitespace())
|
||||
.skip_while(|c| !c.is_whitespace())
|
||||
.collect::<String>();
|
||||
.skip_while(|c| !c.is_whitespace())
|
||||
.collect::<String>();
|
||||
}
|
||||
Err(_) => {
|
||||
// Otherwise we found `//~ foo`:
|
||||
kind = None;
|
||||
let letters = line[kind_start..].chars();
|
||||
msg = letters.skip_while(|c| c.is_whitespace())
|
||||
.collect::<String>();
|
||||
.collect::<String>();
|
||||
}
|
||||
}
|
||||
let msg = msg.trim().to_owned();
|
||||
@ -155,15 +158,25 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
|
||||
preceding //~^ line.");
|
||||
(FollowPrevious(line_num), line_num)
|
||||
} else {
|
||||
let which =
|
||||
if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
|
||||
let which = if adjusts > 0 {
|
||||
AdjustBackward(adjusts)
|
||||
} else {
|
||||
ThisLine
|
||||
};
|
||||
let line_num = line_num - adjusts;
|
||||
(which, line_num)
|
||||
};
|
||||
|
||||
debug!("line={} tag={:?} which={:?} kind={:?} msg={:?}",
|
||||
line_num, tag, which, kind, msg);
|
||||
Some((which, Error { line_num: line_num,
|
||||
kind: kind,
|
||||
msg: msg, }))
|
||||
line_num,
|
||||
tag,
|
||||
which,
|
||||
kind,
|
||||
msg);
|
||||
Some((which,
|
||||
Error {
|
||||
line_num: line_num,
|
||||
kind: kind,
|
||||
msg: msg,
|
||||
}))
|
||||
}
|
||||
|
@ -32,24 +32,21 @@ impl EarlyProps {
|
||||
should_fail: false,
|
||||
};
|
||||
|
||||
iter_header(testfile, None, &mut |ln| {
|
||||
iter_header(testfile,
|
||||
None,
|
||||
&mut |ln| {
|
||||
props.ignore =
|
||||
props.ignore ||
|
||||
parse_name_directive(ln, "ignore-test") ||
|
||||
props.ignore || parse_name_directive(ln, "ignore-test") ||
|
||||
parse_name_directive(ln, &ignore_target(config)) ||
|
||||
parse_name_directive(ln, &ignore_architecture(config)) ||
|
||||
parse_name_directive(ln, &ignore_stage(config)) ||
|
||||
parse_name_directive(ln, &ignore_env(config)) ||
|
||||
(config.mode == common::Pretty &&
|
||||
parse_name_directive(ln, "ignore-pretty")) ||
|
||||
(config.mode == common::Pretty && parse_name_directive(ln, "ignore-pretty")) ||
|
||||
(config.target != config.host &&
|
||||
parse_name_directive(ln, "ignore-cross-compile")) ||
|
||||
ignore_gdb(config, ln) ||
|
||||
ignore_lldb(config, ln);
|
||||
ignore_gdb(config, ln) || ignore_lldb(config, ln);
|
||||
|
||||
props.should_fail =
|
||||
props.should_fail ||
|
||||
parse_name_directive(ln, "should-fail");
|
||||
props.should_fail = props.should_fail || parse_name_directive(ln, "should-fail");
|
||||
});
|
||||
|
||||
return props;
|
||||
@ -61,11 +58,11 @@ impl EarlyProps {
|
||||
format!("ignore-{}", util::get_arch(&config.target))
|
||||
}
|
||||
fn ignore_stage(config: &Config) -> String {
|
||||
format!("ignore-{}",
|
||||
config.stage_id.split('-').next().unwrap())
|
||||
format!("ignore-{}", config.stage_id.split('-').next().unwrap())
|
||||
}
|
||||
fn ignore_env(config: &Config) -> String {
|
||||
format!("ignore-{}", util::get_env(&config.target).unwrap_or("<unknown>"))
|
||||
format!("ignore-{}",
|
||||
util::get_env(&config.target).unwrap_or("<unknown>"))
|
||||
}
|
||||
fn ignore_gdb(config: &Config, line: &str) -> bool {
|
||||
if config.mode != common::DebugInfoGdb {
|
||||
@ -79,13 +76,12 @@ impl EarlyProps {
|
||||
if let Some(ref actual_version) = config.gdb_version {
|
||||
if line.contains("min-gdb-version") {
|
||||
let min_version = line.trim()
|
||||
.split(' ')
|
||||
.last()
|
||||
.expect("Malformed GDB version directive");
|
||||
.split(' ')
|
||||
.last()
|
||||
.expect("Malformed GDB version directive");
|
||||
// Ignore if actual version is smaller the minimum required
|
||||
// version
|
||||
gdb_version_to_int(actual_version) <
|
||||
gdb_version_to_int(min_version)
|
||||
gdb_version_to_int(actual_version) < gdb_version_to_int(min_version)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -106,13 +102,12 @@ impl EarlyProps {
|
||||
if let Some(ref actual_version) = config.lldb_version {
|
||||
if line.contains("min-lldb-version") {
|
||||
let min_version = line.trim()
|
||||
.split(' ')
|
||||
.last()
|
||||
.expect("Malformed lldb version directive");
|
||||
.split(' ')
|
||||
.last()
|
||||
.expect("Malformed lldb version directive");
|
||||
// Ignore if actual version is smaller the minimum required
|
||||
// version
|
||||
lldb_version_to_int(actual_version) <
|
||||
lldb_version_to_int(min_version)
|
||||
lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -126,7 +121,7 @@ impl EarlyProps {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TestProps {
|
||||
// Lines that should be expected, in order, on standard out
|
||||
pub error_patterns: Vec<String> ,
|
||||
pub error_patterns: Vec<String>,
|
||||
// Extra flags to pass to the compiler
|
||||
pub compile_flags: Vec<String>,
|
||||
// Extra flags to pass when the compiled code is run (such as --bench)
|
||||
@ -137,13 +132,13 @@ pub struct TestProps {
|
||||
// Other crates that should be compiled (typically from the same
|
||||
// directory as the test, but for backwards compatibility reasons
|
||||
// we also check the auxiliary directory)
|
||||
pub aux_builds: Vec<String> ,
|
||||
pub aux_builds: Vec<String>,
|
||||
// Environment settings to use for compiling
|
||||
pub rustc_env: Vec<(String,String)> ,
|
||||
pub rustc_env: Vec<(String, String)>,
|
||||
// Environment settings to use during execution
|
||||
pub exec_env: Vec<(String,String)> ,
|
||||
pub exec_env: Vec<(String, String)>,
|
||||
// Lines to check if they appear in the expected debugger output
|
||||
pub check_lines: Vec<String> ,
|
||||
pub check_lines: Vec<String>,
|
||||
// Build documentation for all specified aux-builds as well
|
||||
pub build_aux_docs: bool,
|
||||
// Flag to force a crate to be built with the host architecture
|
||||
@ -226,17 +221,17 @@ impl TestProps {
|
||||
/// tied to a particular revision `foo` (indicated by writing
|
||||
/// `//[foo]`), then the property is ignored unless `cfg` is
|
||||
/// `Some("foo")`.
|
||||
pub fn load_from(&mut self, testfile: &Path, cfg: Option<&str>) {
|
||||
iter_header(testfile, cfg, &mut |ln| {
|
||||
pub fn load_from(&mut self, testfile: &Path, cfg: Option<&str>) {
|
||||
iter_header(testfile,
|
||||
cfg,
|
||||
&mut |ln| {
|
||||
if let Some(ep) = parse_error_pattern(ln) {
|
||||
self.error_patterns.push(ep);
|
||||
}
|
||||
|
||||
if let Some(flags) = parse_compile_flags(ln) {
|
||||
self.compile_flags.extend(
|
||||
flags
|
||||
.split_whitespace()
|
||||
.map(|s| s.to_owned()));
|
||||
self.compile_flags.extend(flags.split_whitespace()
|
||||
.map(|s| s.to_owned()));
|
||||
}
|
||||
|
||||
if let Some(r) = parse_revisions(ln) {
|
||||
@ -279,7 +274,7 @@ impl TestProps {
|
||||
self.pretty_compare_only = parse_pretty_compare_only(ln);
|
||||
}
|
||||
|
||||
if let Some(ab) = parse_aux_build(ln) {
|
||||
if let Some(ab) = parse_aux_build(ln) {
|
||||
self.aux_builds.push(ab);
|
||||
}
|
||||
|
||||
@ -291,7 +286,7 @@ impl TestProps {
|
||||
self.rustc_env.push(ee);
|
||||
}
|
||||
|
||||
if let Some(cl) = parse_check_line(ln) {
|
||||
if let Some(cl) = parse_check_line(ln) {
|
||||
self.check_lines.push(cl);
|
||||
}
|
||||
|
||||
@ -302,21 +297,20 @@ impl TestProps {
|
||||
|
||||
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
|
||||
match env::var(key) {
|
||||
Ok(val) =>
|
||||
Ok(val) => {
|
||||
if self.exec_env.iter().find(|&&(ref x, _)| *x == key).is_none() {
|
||||
self.exec_env.push((key.to_owned(), val))
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(..) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn iter_header(testfile: &Path,
|
||||
cfg: Option<&str>,
|
||||
it: &mut FnMut(&str)) {
|
||||
fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
|
||||
if testfile.is_dir() {
|
||||
return
|
||||
return;
|
||||
}
|
||||
let rdr = BufReader::new(File::open(testfile).unwrap());
|
||||
for ln in rdr.lines() {
|
||||
@ -336,7 +330,7 @@ fn iter_header(testfile: &Path,
|
||||
None => false,
|
||||
};
|
||||
if matches {
|
||||
it(&ln[close_brace+1..]);
|
||||
it(&ln[close_brace + 1..]);
|
||||
}
|
||||
} else {
|
||||
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
|
||||
@ -409,18 +403,17 @@ fn parse_pretty_compare_only(line: &str) -> bool {
|
||||
fn parse_env(line: &str, name: &str) -> Option<(String, String)> {
|
||||
parse_name_value_directive(line, name).map(|nv| {
|
||||
// nv is either FOO or FOO=BAR
|
||||
let mut strs: Vec<String> = nv
|
||||
.splitn(2, '=')
|
||||
.map(str::to_owned)
|
||||
.collect();
|
||||
let mut strs: Vec<String> = nv.splitn(2, '=')
|
||||
.map(str::to_owned)
|
||||
.collect();
|
||||
|
||||
match strs.len() {
|
||||
1 => (strs.pop().unwrap(), "".to_owned()),
|
||||
2 => {
|
||||
let end = strs.pop().unwrap();
|
||||
(strs.pop().unwrap(), end)
|
||||
}
|
||||
n => panic!("Expected 1 or 2 strings, not {}", n)
|
||||
1 => (strs.pop().unwrap(), "".to_owned()),
|
||||
2 => {
|
||||
let end = strs.pop().unwrap();
|
||||
(strs.pop().unwrap(), end)
|
||||
}
|
||||
n => panic!("Expected 1 or 2 strings, not {}", n),
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -442,11 +435,10 @@ fn parse_name_directive(line: &str, directive: &str) -> bool {
|
||||
line.contains(directive) && !line.contains(&("no-".to_owned() + directive))
|
||||
}
|
||||
|
||||
pub fn parse_name_value_directive(line: &str, directive: &str)
|
||||
-> Option<String> {
|
||||
pub fn parse_name_value_directive(line: &str, directive: &str) -> Option<String> {
|
||||
let keycolon = format!("{}:", directive);
|
||||
if let Some(colon) = line.find(&keycolon) {
|
||||
let value = line[(colon + keycolon.len()) .. line.len()].to_owned();
|
||||
let value = line[(colon + keycolon.len())..line.len()].to_owned();
|
||||
debug!("{}: {}", directive, value);
|
||||
Some(value)
|
||||
} else {
|
||||
@ -455,9 +447,8 @@ pub fn parse_name_value_directive(line: &str, directive: &str)
|
||||
}
|
||||
|
||||
pub fn gdb_version_to_int(version_string: &str) -> isize {
|
||||
let error_string = format!(
|
||||
"Encountered GDB version string with unexpected format: {}",
|
||||
version_string);
|
||||
let error_string = format!("Encountered GDB version string with unexpected format: {}",
|
||||
version_string);
|
||||
let error_string = error_string;
|
||||
|
||||
let components: Vec<&str> = version_string.trim().split('.').collect();
|
||||
@ -473,9 +464,8 @@ pub fn gdb_version_to_int(version_string: &str) -> isize {
|
||||
}
|
||||
|
||||
pub fn lldb_version_to_int(version_string: &str) -> isize {
|
||||
let error_string = format!(
|
||||
"Encountered LLDB version string with unexpected format: {}",
|
||||
version_string);
|
||||
let error_string = format!("Encountered LLDB version string with unexpected format: {}",
|
||||
version_string);
|
||||
let error_string = error_string;
|
||||
let major: isize = version_string.parse().ok().expect(&error_string);
|
||||
return major;
|
||||
|
@ -12,7 +12,7 @@ use errors::{Error, ErrorKind};
|
||||
use rustc_serialize::json;
|
||||
use std::str::FromStr;
|
||||
use std::path::Path;
|
||||
use runtest::{ProcRes};
|
||||
use runtest::ProcRes;
|
||||
|
||||
// These structs are a subset of the ones found in
|
||||
// `syntax::json`.
|
||||
@ -58,8 +58,8 @@ struct DiagnosticCode {
|
||||
|
||||
pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
|
||||
output.lines()
|
||||
.flat_map(|line| parse_line(file_name, line, output, proc_res))
|
||||
.collect()
|
||||
.flat_map(|line| parse_line(file_name, line, output, proc_res))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
|
||||
@ -73,9 +73,11 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) ->
|
||||
expected_errors
|
||||
}
|
||||
Err(error) => {
|
||||
proc_res.fatal(Some(&format!(
|
||||
"failed to decode compiler output as json: `{}`\noutput: {}\nline: {}",
|
||||
error, line, output)));
|
||||
proc_res.fatal(Some(&format!("failed to decode compiler output as json: \
|
||||
`{}`\noutput: {}\nline: {}",
|
||||
error,
|
||||
line,
|
||||
output)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -87,16 +89,15 @@ fn push_expected_errors(expected_errors: &mut Vec<Error>,
|
||||
diagnostic: &Diagnostic,
|
||||
default_spans: &[&DiagnosticSpan],
|
||||
file_name: &str) {
|
||||
let spans_in_this_file: Vec<_> =
|
||||
diagnostic.spans.iter()
|
||||
.filter(|span| Path::new(&span.file_name) == Path::new(&file_name))
|
||||
.collect();
|
||||
let spans_in_this_file: Vec<_> = diagnostic.spans
|
||||
.iter()
|
||||
.filter(|span| Path::new(&span.file_name) == Path::new(&file_name))
|
||||
.collect();
|
||||
|
||||
let primary_spans: Vec<_> =
|
||||
spans_in_this_file.iter()
|
||||
.cloned()
|
||||
.filter(|span| span.is_primary)
|
||||
.collect();
|
||||
let primary_spans: Vec<_> = spans_in_this_file.iter()
|
||||
.cloned()
|
||||
.filter(|span| span.is_primary)
|
||||
.collect();
|
||||
let primary_spans = if primary_spans.is_empty() {
|
||||
// subdiagnostics often don't have a span of their own;
|
||||
// inherit the span from the parent in that case
|
||||
@ -144,24 +145,20 @@ fn push_expected_errors(expected_errors: &mut Vec<Error>,
|
||||
for span in primary_spans {
|
||||
let msg = with_code(span, first_line);
|
||||
let kind = ErrorKind::from_str(&diagnostic.level).ok();
|
||||
expected_errors.push(
|
||||
Error {
|
||||
line_num: span.line_start,
|
||||
kind: kind,
|
||||
msg: msg,
|
||||
}
|
||||
);
|
||||
expected_errors.push(Error {
|
||||
line_num: span.line_start,
|
||||
kind: kind,
|
||||
msg: msg,
|
||||
});
|
||||
}
|
||||
}
|
||||
for next_line in message_lines {
|
||||
for span in primary_spans {
|
||||
expected_errors.push(
|
||||
Error {
|
||||
line_num: span.line_start,
|
||||
kind: None,
|
||||
msg: with_code(span, next_line),
|
||||
}
|
||||
);
|
||||
expected_errors.push(Error {
|
||||
line_num: span.line_start,
|
||||
kind: None,
|
||||
msg: with_code(span, next_line),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,33 +167,28 @@ fn push_expected_errors(expected_errors: &mut Vec<Error>,
|
||||
let start_line = primary_spans.iter().map(|s| s.line_start).min().expect("\
|
||||
every suggestion should have at least one span");
|
||||
for (index, line) in rendered.lines().enumerate() {
|
||||
expected_errors.push(
|
||||
Error {
|
||||
line_num: start_line + index,
|
||||
kind: Some(ErrorKind::Suggestion),
|
||||
msg: line.to_string()
|
||||
}
|
||||
);
|
||||
expected_errors.push(Error {
|
||||
line_num: start_line + index,
|
||||
kind: Some(ErrorKind::Suggestion),
|
||||
msg: line.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add notes for the backtrace
|
||||
for span in primary_spans {
|
||||
for frame in &span.expansion {
|
||||
push_backtrace(expected_errors,
|
||||
frame,
|
||||
file_name);
|
||||
push_backtrace(expected_errors, frame, file_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Add notes for any labels that appear in the message.
|
||||
for span in spans_in_this_file.iter()
|
||||
.filter(|span| span.label.is_some())
|
||||
{
|
||||
.filter(|span| span.label.is_some()) {
|
||||
expected_errors.push(Error {
|
||||
line_num: span.line_start,
|
||||
kind: Some(ErrorKind::Note),
|
||||
msg: span.label.clone().unwrap()
|
||||
msg: span.label.clone().unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -210,13 +202,11 @@ fn push_backtrace(expected_errors: &mut Vec<Error>,
|
||||
expansion: &DiagnosticSpanMacroExpansion,
|
||||
file_name: &str) {
|
||||
if Path::new(&expansion.span.file_name) == Path::new(&file_name) {
|
||||
expected_errors.push(
|
||||
Error {
|
||||
line_num: expansion.span.line_start,
|
||||
kind: Some(ErrorKind::Note),
|
||||
msg: format!("in this expansion of {}", expansion.macro_decl_name),
|
||||
}
|
||||
);
|
||||
expected_errors.push(Error {
|
||||
line_num: expansion.span.line_start,
|
||||
kind: Some(ErrorKind::Note),
|
||||
msg: format!("in this expansion of {}", expansion.macro_decl_name),
|
||||
});
|
||||
}
|
||||
|
||||
for previous_expansion in &expansion.span.expansion {
|
||||
|
@ -12,7 +12,7 @@ use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{ExitStatus, Command, Child, Output, Stdio};
|
||||
use std::process::{Child, Command, ExitStatus, Output, Stdio};
|
||||
|
||||
pub fn dylib_env_var() -> &'static str {
|
||||
if cfg!(windows) {
|
||||
@ -29,7 +29,7 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
|
||||
// search path for the child.
|
||||
let var = dylib_env_var();
|
||||
let mut path = env::split_paths(&env::var_os(var).unwrap_or(OsString::new()))
|
||||
.collect::<Vec<_>>();
|
||||
.collect::<Vec<_>>();
|
||||
if let Some(p) = aux_path {
|
||||
path.insert(0, PathBuf::from(p))
|
||||
}
|
||||
@ -40,20 +40,25 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
|
||||
cmd.env(var, newpath);
|
||||
}
|
||||
|
||||
pub struct Result {pub status: ExitStatus, pub out: String, pub err: String}
|
||||
pub struct Result {
|
||||
pub status: ExitStatus,
|
||||
pub out: String,
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
pub fn run(lib_path: &str,
|
||||
prog: &str,
|
||||
aux_path: Option<&str>,
|
||||
args: &[String],
|
||||
env: Vec<(String, String)> ,
|
||||
input: Option<String>) -> Option<Result> {
|
||||
env: Vec<(String, String)>,
|
||||
input: Option<String>)
|
||||
-> Option<Result> {
|
||||
|
||||
let mut cmd = Command::new(prog);
|
||||
cmd.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
add_target_env(&mut cmd, lib_path, aux_path);
|
||||
for (key, val) in env {
|
||||
cmd.env(&key, &val);
|
||||
@ -64,31 +69,31 @@ pub fn run(lib_path: &str,
|
||||
if let Some(input) = input {
|
||||
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
|
||||
}
|
||||
let Output { status, stdout, stderr } =
|
||||
process.wait_with_output().unwrap();
|
||||
let Output { status, stdout, stderr } = process.wait_with_output().unwrap();
|
||||
|
||||
Some(Result {
|
||||
status: status,
|
||||
out: String::from_utf8(stdout).unwrap(),
|
||||
err: String::from_utf8(stderr).unwrap()
|
||||
err: String::from_utf8(stderr).unwrap(),
|
||||
})
|
||||
},
|
||||
Err(..) => None
|
||||
}
|
||||
Err(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_background(lib_path: &str,
|
||||
prog: &str,
|
||||
aux_path: Option<&str>,
|
||||
args: &[String],
|
||||
env: Vec<(String, String)> ,
|
||||
input: Option<String>) -> Option<Child> {
|
||||
prog: &str,
|
||||
aux_path: Option<&str>,
|
||||
args: &[String],
|
||||
env: Vec<(String, String)>,
|
||||
input: Option<String>)
|
||||
-> Option<Child> {
|
||||
|
||||
let mut cmd = Command::new(prog);
|
||||
cmd.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
add_target_env(&mut cmd, lib_path, aux_path);
|
||||
for (key, val) in env {
|
||||
cmd.env(&key, &val);
|
||||
@ -101,7 +106,7 @@ pub fn run_background(lib_path: &str,
|
||||
}
|
||||
|
||||
Some(process)
|
||||
},
|
||||
Err(..) => None
|
||||
}
|
||||
Err(..) => None,
|
||||
}
|
||||
}
|
||||
|
@ -34,14 +34,21 @@ pub unsafe fn raise_fd_limit() {
|
||||
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
|
||||
let mut maxfiles: libc::c_int = 0;
|
||||
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
|
||||
if libc::sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size,
|
||||
null_mut(), 0) != 0 {
|
||||
if libc::sysctl(&mut mib[0],
|
||||
2,
|
||||
&mut maxfiles as *mut _ as *mut _,
|
||||
&mut size,
|
||||
null_mut(),
|
||||
0) != 0 {
|
||||
let err = io::Error::last_os_error();
|
||||
panic!("raise_fd_limit: error calling sysctl: {}", err);
|
||||
}
|
||||
|
||||
// Fetch the current resource limits
|
||||
let mut rlim = libc::rlimit{rlim_cur: 0, rlim_max: 0};
|
||||
let mut rlim = libc::rlimit {
|
||||
rlim_cur: 0,
|
||||
rlim_max: 0,
|
||||
};
|
||||
if libc::getrlimit(libc::RLIMIT_NOFILE, &mut rlim) != 0 {
|
||||
let err = io::Error::last_os_error();
|
||||
panic!("raise_fd_limit: error calling getrlimit: {}", err);
|
||||
|
@ -13,24 +13,23 @@
|
||||
|
||||
pub fn diff_lines(actual: &str, expected: &str) -> Vec<String> {
|
||||
// mega simplistic diff algorithm that just prints the things added/removed
|
||||
zip_all(actual.lines(), expected.lines()).enumerate().filter_map(|(i, (a,e))| {
|
||||
match (a, e) {
|
||||
(Some(a), Some(e)) => {
|
||||
if lines_match(e, a) {
|
||||
None
|
||||
} else {
|
||||
Some(format!("{:3} - |{}|\n + |{}|\n", i, e, a))
|
||||
zip_all(actual.lines(), expected.lines())
|
||||
.enumerate()
|
||||
.filter_map(|(i, (a, e))| {
|
||||
match (a, e) {
|
||||
(Some(a), Some(e)) => {
|
||||
if lines_match(e, a) {
|
||||
None
|
||||
} else {
|
||||
Some(format!("{:3} - |{}|\n + |{}|\n", i, e, a))
|
||||
}
|
||||
}
|
||||
},
|
||||
(Some(a), None) => {
|
||||
Some(format!("{:3} -\n + |{}|\n", i, a))
|
||||
},
|
||||
(None, Some(e)) => {
|
||||
Some(format!("{:3} - |{}|\n +\n", i, e))
|
||||
},
|
||||
(None, None) => panic!("Cannot get here")
|
||||
}
|
||||
}).collect()
|
||||
(Some(a), None) => Some(format!("{:3} -\n + |{}|\n", i, a)),
|
||||
(None, Some(e)) => Some(format!("{:3} - |{}|\n +\n", i, e)),
|
||||
(None, None) => panic!("Cannot get here"),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn lines_match(expected: &str, mut actual: &str) -> bool {
|
||||
@ -38,13 +37,11 @@ fn lines_match(expected: &str, mut actual: &str) -> bool {
|
||||
match actual.find(part) {
|
||||
Some(j) => {
|
||||
if i == 0 && j != 0 {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
actual = &actual[j + part.len()..];
|
||||
}
|
||||
None => {
|
||||
return false
|
||||
}
|
||||
None => return false,
|
||||
}
|
||||
}
|
||||
actual.is_empty() || expected.ends_with("[..]")
|
||||
@ -55,7 +52,7 @@ struct ZipAll<I1: Iterator, I2: Iterator> {
|
||||
second: I2,
|
||||
}
|
||||
|
||||
impl<T, I1: Iterator<Item=T>, I2: Iterator<Item=T>> Iterator for ZipAll<I1, I2> {
|
||||
impl<T, I1: Iterator<Item = T>, I2: Iterator<Item = T>> Iterator for ZipAll<I1, I2> {
|
||||
type Item = (Option<T>, Option<T>);
|
||||
fn next(&mut self) -> Option<(Option<T>, Option<T>)> {
|
||||
let first = self.first.next();
|
||||
@ -63,12 +60,12 @@ impl<T, I1: Iterator<Item=T>, I2: Iterator<Item=T>> Iterator for ZipAll<I1, I2>
|
||||
|
||||
match (first, second) {
|
||||
(None, None) => None,
|
||||
(a, b) => Some((a, b))
|
||||
(a, b) => Some((a, b)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn zip_all<T, I1: Iterator<Item=T>, I2: Iterator<Item=T>>(a: I1, b: I2) -> ZipAll<I1, I2> {
|
||||
fn zip_all<T, I1: Iterator<Item = T>, I2: Iterator<Item = T>>(a: I1, b: I2) -> ZipAll<I1, I2> {
|
||||
ZipAll {
|
||||
first: a,
|
||||
second: b,
|
||||
|
@ -12,46 +12,42 @@ use std::env;
|
||||
use common::Config;
|
||||
|
||||
/// Conversion table from triple OS name to Rust SYSNAME
|
||||
const OS_TABLE: &'static [(&'static str, &'static str)] = &[
|
||||
("android", "android"),
|
||||
("bitrig", "bitrig"),
|
||||
("darwin", "macos"),
|
||||
("dragonfly", "dragonfly"),
|
||||
("freebsd", "freebsd"),
|
||||
("ios", "ios"),
|
||||
("linux", "linux"),
|
||||
("mingw32", "windows"),
|
||||
("netbsd", "netbsd"),
|
||||
("openbsd", "openbsd"),
|
||||
("win32", "windows"),
|
||||
("windows", "windows"),
|
||||
("solaris", "solaris"),
|
||||
("emscripten", "emscripten"),
|
||||
];
|
||||
const OS_TABLE: &'static [(&'static str, &'static str)] = &[("android", "android"),
|
||||
("bitrig", "bitrig"),
|
||||
("darwin", "macos"),
|
||||
("dragonfly", "dragonfly"),
|
||||
("freebsd", "freebsd"),
|
||||
("ios", "ios"),
|
||||
("linux", "linux"),
|
||||
("mingw32", "windows"),
|
||||
("netbsd", "netbsd"),
|
||||
("openbsd", "openbsd"),
|
||||
("win32", "windows"),
|
||||
("windows", "windows"),
|
||||
("solaris", "solaris"),
|
||||
("emscripten", "emscripten")];
|
||||
|
||||
const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
|
||||
("aarch64", "aarch64"),
|
||||
("amd64", "x86_64"),
|
||||
("arm", "arm"),
|
||||
("arm64", "aarch64"),
|
||||
("hexagon", "hexagon"),
|
||||
("i386", "x86"),
|
||||
("i686", "x86"),
|
||||
("mips", "mips"),
|
||||
("msp430", "msp430"),
|
||||
("powerpc", "powerpc"),
|
||||
("powerpc64", "powerpc64"),
|
||||
("s390x", "systemz"),
|
||||
("sparc", "sparc"),
|
||||
("x86_64", "x86_64"),
|
||||
("xcore", "xcore"),
|
||||
("asmjs", "asmjs"),
|
||||
];
|
||||
const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[("aarch64", "aarch64"),
|
||||
("amd64", "x86_64"),
|
||||
("arm", "arm"),
|
||||
("arm64", "aarch64"),
|
||||
("hexagon", "hexagon"),
|
||||
("i386", "x86"),
|
||||
("i686", "x86"),
|
||||
("mips", "mips"),
|
||||
("msp430", "msp430"),
|
||||
("powerpc", "powerpc"),
|
||||
("powerpc64", "powerpc64"),
|
||||
("s390x", "systemz"),
|
||||
("sparc", "sparc"),
|
||||
("x86_64", "x86_64"),
|
||||
("xcore", "xcore"),
|
||||
("asmjs", "asmjs")];
|
||||
|
||||
pub fn get_os(triple: &str) -> &'static str {
|
||||
for &(triple_os, os) in OS_TABLE {
|
||||
if triple.contains(triple_os) {
|
||||
return os
|
||||
return os;
|
||||
}
|
||||
}
|
||||
panic!("Cannot determine OS from triple");
|
||||
@ -59,7 +55,7 @@ pub fn get_os(triple: &str) -> &'static str {
|
||||
pub fn get_arch(triple: &str) -> &'static str {
|
||||
for &(triple_arch, arch) in ARCH_TABLE {
|
||||
if triple.contains(triple_arch) {
|
||||
return arch
|
||||
return arch;
|
||||
}
|
||||
}
|
||||
panic!("Cannot determine Architecture from triple");
|
||||
@ -74,17 +70,21 @@ pub fn make_new_path(path: &str) -> String {
|
||||
// Windows just uses PATH as the library search path, so we have to
|
||||
// maintain the current value while adding our own
|
||||
match env::var(lib_path_env_var()) {
|
||||
Ok(curr) => {
|
||||
format!("{}{}{}", path, path_div(), curr)
|
||||
}
|
||||
Err(..) => path.to_owned()
|
||||
Ok(curr) => format!("{}{}{}", path, path_div(), curr),
|
||||
Err(..) => path.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lib_path_env_var() -> &'static str { "PATH" }
|
||||
fn path_div() -> &'static str { ";" }
|
||||
pub fn lib_path_env_var() -> &'static str {
|
||||
"PATH"
|
||||
}
|
||||
fn path_div() -> &'static str {
|
||||
";"
|
||||
}
|
||||
|
||||
pub fn logv(config: &Config, s: String) {
|
||||
debug!("{}", s);
|
||||
if config.verbose { println!("{}", s); }
|
||||
if config.verbose {
|
||||
println!("{}", s);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user