Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiletest: Unit tests for EarlyProps (+ small cleanup) #68533

Merged
merged 7 commits into from
Jan 28, 2020
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
7 changes: 1 addition & 6 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,17 +1149,14 @@ impl Step for Compiletest {
// requires that a C++ compiler was configured which isn't always the case.
if !builder.config.dry_run && suite == "run-make-fulldeps" {
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
cmd.arg("--cc")
.arg(builder.cc(target))
.arg("--cxx")
.arg(builder.cxx(target).unwrap())
.arg("--cflags")
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
.arg("--llvm-components")
.arg(llvm_components.trim())
.arg("--llvm-cxxflags")
.arg(llvm_cxxflags.trim());
.arg(llvm_components.trim());
if let Some(ar) = builder.ar(target) {
cmd.arg("--ar").arg(ar);
}
Expand Down Expand Up @@ -1197,8 +1194,6 @@ impl Step for Compiletest {
.arg("--cflags")
.arg("")
.arg("--llvm-components")
.arg("")
.arg("--llvm-cxxflags")
.arg("");
}

Expand Down
1 change: 0 additions & 1 deletion src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ pub struct Config {
pub ar: String,
pub linker: Option<String>,
pub llvm_components: String,
pub llvm_cxxflags: String,

/// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
pub nodejs: Option<String>,
Expand Down
236 changes: 123 additions & 113 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum ParsedNameDirective {

/// Properties which must be known very early, before actually running
/// the test.
#[derive(Default)]
pub struct EarlyProps {
pub ignore: bool,
pub should_fail: bool,
Expand All @@ -34,18 +35,16 @@ pub struct EarlyProps {

impl EarlyProps {
pub fn from_file(config: &Config, testfile: &Path) -> Self {
let mut props = EarlyProps {
ignore: false,
should_fail: false,
aux: Vec::new(),
aux_crate: Vec::new(),
revisions: vec![],
};
let file = File::open(testfile).unwrap();
Self::from_reader(config, testfile, file)
}

pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
let mut props = EarlyProps::default();
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
let rustc_has_sanitizer_support = env::var_os("RUSTC_SANITIZER_SUPPORT").is_some();

iter_header(testfile, None, &mut |ln| {
iter_header(testfile, None, rdr, &mut |ln| {
// we should check if any only-<platform> exists and if it exists
// and does not matches the current platform, skip the test
if !props.ignore {
Expand Down Expand Up @@ -392,138 +391,143 @@ impl TestProps {
/// `//[foo]`), then the property is ignored unless `cfg` is
/// `Some("foo")`.
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
iter_header(testfile, cfg, &mut |ln| {
if let Some(ep) = config.parse_error_pattern(ln) {
self.error_patterns.push(ep);
}
if !testfile.is_dir() {
let file = File::open(testfile).unwrap();

if let Some(flags) = config.parse_compile_flags(ln) {
self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
}
iter_header(testfile, cfg, file, &mut |ln| {
if let Some(ep) = config.parse_error_pattern(ln) {
self.error_patterns.push(ep);
}

if let Some(edition) = config.parse_edition(ln) {
self.compile_flags.push(format!("--edition={}", edition));
}
if let Some(flags) = config.parse_compile_flags(ln) {
self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
}

if let Some(r) = config.parse_revisions(ln) {
self.revisions.extend(r);
}
if let Some(edition) = config.parse_edition(ln) {
self.compile_flags.push(format!("--edition={}", edition));
}

if self.run_flags.is_none() {
self.run_flags = config.parse_run_flags(ln);
}
if let Some(r) = config.parse_revisions(ln) {
self.revisions.extend(r);
}

if self.pp_exact.is_none() {
self.pp_exact = config.parse_pp_exact(ln, testfile);
}
if self.run_flags.is_none() {
self.run_flags = config.parse_run_flags(ln);
}

if !self.should_ice {
self.should_ice = config.parse_should_ice(ln);
}
if self.pp_exact.is_none() {
self.pp_exact = config.parse_pp_exact(ln, testfile);
}

if !self.build_aux_docs {
self.build_aux_docs = config.parse_build_aux_docs(ln);
}
if !self.should_ice {
self.should_ice = config.parse_should_ice(ln);
}

if !self.force_host {
self.force_host = config.parse_force_host(ln);
}
if !self.build_aux_docs {
self.build_aux_docs = config.parse_build_aux_docs(ln);
}

if !self.check_stdout {
self.check_stdout = config.parse_check_stdout(ln);
}
if !self.force_host {
self.force_host = config.parse_force_host(ln);
}

if !self.check_run_results {
self.check_run_results = config.parse_check_run_results(ln);
}
if !self.check_stdout {
self.check_stdout = config.parse_check_stdout(ln);
}

if !self.dont_check_compiler_stdout {
self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
}
if !self.check_run_results {
self.check_run_results = config.parse_check_run_results(ln);
}

if !self.dont_check_compiler_stderr {
self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
}
if !self.dont_check_compiler_stdout {
self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
}

if !self.no_prefer_dynamic {
self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
}
if !self.dont_check_compiler_stderr {
self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
}

if !self.pretty_expanded {
self.pretty_expanded = config.parse_pretty_expanded(ln);
}
if !self.no_prefer_dynamic {
self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
}

if let Some(m) = config.parse_pretty_mode(ln) {
self.pretty_mode = m;
}
if !self.pretty_expanded {
self.pretty_expanded = config.parse_pretty_expanded(ln);
}

if !self.pretty_compare_only {
self.pretty_compare_only = config.parse_pretty_compare_only(ln);
}
if let Some(m) = config.parse_pretty_mode(ln) {
self.pretty_mode = m;
}

if let Some(ab) = config.parse_aux_build(ln) {
self.aux_builds.push(ab);
}
if !self.pretty_compare_only {
self.pretty_compare_only = config.parse_pretty_compare_only(ln);
}

if let Some(ac) = config.parse_aux_crate(ln) {
self.aux_crates.push(ac);
}
if let Some(ab) = config.parse_aux_build(ln) {
self.aux_builds.push(ab);
}

if let Some(ee) = config.parse_env(ln, "exec-env") {
self.exec_env.push(ee);
}
if let Some(ac) = config.parse_aux_crate(ln) {
self.aux_crates.push(ac);
}

if let Some(ee) = config.parse_env(ln, "rustc-env") {
self.rustc_env.push(ee);
}
if let Some(ee) = config.parse_env(ln, "exec-env") {
self.exec_env.push(ee);
}

if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") {
self.unset_rustc_env.push(ev);
}
if let Some(ee) = config.parse_env(ln, "rustc-env") {
self.rustc_env.push(ee);
}

if let Some(cl) = config.parse_check_line(ln) {
self.check_lines.push(cl);
}
if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") {
self.unset_rustc_env.push(ev);
}

if let Some(of) = config.parse_forbid_output(ln) {
self.forbid_output.push(of);
}
if let Some(cl) = config.parse_check_line(ln) {
self.check_lines.push(cl);
}

if !self.check_test_line_numbers_match {
self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
}
if let Some(of) = config.parse_forbid_output(ln) {
self.forbid_output.push(of);
}

self.update_pass_mode(ln, cfg, config);
self.update_fail_mode(ln, config);
if !self.check_test_line_numbers_match {
self.check_test_line_numbers_match =
config.parse_check_test_line_numbers_match(ln);
}

if !self.ignore_pass {
self.ignore_pass = config.parse_ignore_pass(ln);
}
self.update_pass_mode(ln, cfg, config);
self.update_fail_mode(ln, config);

if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
self.normalize_stdout.push(rule);
}
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
self.normalize_stderr.push(rule);
}
if !self.ignore_pass {
self.ignore_pass = config.parse_ignore_pass(ln);
}

if let Some(code) = config.parse_failure_status(ln) {
self.failure_status = code;
}
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
self.normalize_stdout.push(rule);
}
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
self.normalize_stderr.push(rule);
}

if !self.run_rustfix {
self.run_rustfix = config.parse_run_rustfix(ln);
}
if let Some(code) = config.parse_failure_status(ln) {
self.failure_status = code;
}

if !self.rustfix_only_machine_applicable {
self.rustfix_only_machine_applicable =
config.parse_rustfix_only_machine_applicable(ln);
}
if !self.run_rustfix {
self.run_rustfix = config.parse_run_rustfix(ln);
}

if self.assembly_output.is_none() {
self.assembly_output = config.parse_assembly_output(ln);
}
});
if !self.rustfix_only_machine_applicable {
self.rustfix_only_machine_applicable =
config.parse_rustfix_only_machine_applicable(ln);
}

if self.assembly_output.is_none() {
self.assembly_output = config.parse_assembly_output(ln);
}
});
}

if self.failure_status == -1 {
self.failure_status = match config.mode {
Expand Down Expand Up @@ -617,7 +621,7 @@ impl TestProps {
}
}

fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
fn iter_header<R: Read>(testfile: &Path, cfg: Option<&str>, rdr: R, it: &mut dyn FnMut(&str)) {
if testfile.is_dir() {
return;
}
Expand All @@ -628,12 +632,18 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
// It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
let comment_with_brace = comment.to_string() + "[";

let rdr = BufReader::new(File::open(testfile).unwrap());
for ln in rdr.lines() {
let mut rdr = BufReader::new(rdr);
let mut ln = String::new();

loop {
ln.clear();
if rdr.read_line(&mut ln).unwrap() == 0 {
break;
}

// Assume that any directives will be found before the first
// module or function. This doesn't seem to be an optimization
// with a warm page cache. Maybe with a cold one.
let ln = ln.unwrap();
let ln = ln.trim();
if ln.starts_with("fn") || ln.starts_with("mod") {
return;
Expand Down
Loading