Skip to content

Commit ac2f3fa

Browse files
committed
Auto merge of #68533 - tmiasko:compiletest, r=nikomatsakis
compiletest: Unit tests for `EarlyProps` (+ small cleanup) * Parse `EarlyProps` from a reader * Add unit tests for `EarlyProps` * Remove unused `llvm-cxxflags` option * Remove unnecessary memory allocations in `iter_header` * Update mode list displayed in `--help`
2 parents b181835 + 3c02afe commit ac2f3fa

File tree

6 files changed

+280
-125
lines changed

6 files changed

+280
-125
lines changed

src/bootstrap/test.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1149,17 +1149,14 @@ impl Step for Compiletest {
11491149
// requires that a C++ compiler was configured which isn't always the case.
11501150
if !builder.config.dry_run && suite == "run-make-fulldeps" {
11511151
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1152-
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
11531152
cmd.arg("--cc")
11541153
.arg(builder.cc(target))
11551154
.arg("--cxx")
11561155
.arg(builder.cxx(target).unwrap())
11571156
.arg("--cflags")
11581157
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
11591158
.arg("--llvm-components")
1160-
.arg(llvm_components.trim())
1161-
.arg("--llvm-cxxflags")
1162-
.arg(llvm_cxxflags.trim());
1159+
.arg(llvm_components.trim());
11631160
if let Some(ar) = builder.ar(target) {
11641161
cmd.arg("--ar").arg(ar);
11651162
}
@@ -1197,8 +1194,6 @@ impl Step for Compiletest {
11971194
.arg("--cflags")
11981195
.arg("")
11991196
.arg("--llvm-components")
1200-
.arg("")
1201-
.arg("--llvm-cxxflags")
12021197
.arg("");
12031198
}
12041199

src/tools/compiletest/src/common.rs

-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ pub struct Config {
319319
pub ar: String,
320320
pub linker: Option<String>,
321321
pub llvm_components: String,
322-
pub llvm_cxxflags: String,
323322

324323
/// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
325324
pub nodejs: Option<String>,

src/tools/compiletest/src/header.rs

+123-113
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum ParsedNameDirective {
2424

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

3536
impl EarlyProps {
3637
pub fn from_file(config: &Config, testfile: &Path) -> Self {
37-
let mut props = EarlyProps {
38-
ignore: false,
39-
should_fail: false,
40-
aux: Vec::new(),
41-
aux_crate: Vec::new(),
42-
revisions: vec![],
43-
};
38+
let file = File::open(testfile).unwrap();
39+
Self::from_reader(config, testfile, file)
40+
}
4441

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

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

400-
if let Some(flags) = config.parse_compile_flags(ln) {
401-
self.compile_flags.extend(flags.split_whitespace().map(|s| s.to_owned()));
402-
}
397+
iter_header(testfile, cfg, file, &mut |ln| {
398+
if let Some(ep) = config.parse_error_pattern(ln) {
399+
self.error_patterns.push(ep);
400+
}
403401

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

408-
if let Some(r) = config.parse_revisions(ln) {
409-
self.revisions.extend(r);
410-
}
406+
if let Some(edition) = config.parse_edition(ln) {
407+
self.compile_flags.push(format!("--edition={}", edition));
408+
}
411409

412-
if self.run_flags.is_none() {
413-
self.run_flags = config.parse_run_flags(ln);
414-
}
410+
if let Some(r) = config.parse_revisions(ln) {
411+
self.revisions.extend(r);
412+
}
415413

416-
if self.pp_exact.is_none() {
417-
self.pp_exact = config.parse_pp_exact(ln, testfile);
418-
}
414+
if self.run_flags.is_none() {
415+
self.run_flags = config.parse_run_flags(ln);
416+
}
419417

420-
if !self.should_ice {
421-
self.should_ice = config.parse_should_ice(ln);
422-
}
418+
if self.pp_exact.is_none() {
419+
self.pp_exact = config.parse_pp_exact(ln, testfile);
420+
}
423421

424-
if !self.build_aux_docs {
425-
self.build_aux_docs = config.parse_build_aux_docs(ln);
426-
}
422+
if !self.should_ice {
423+
self.should_ice = config.parse_should_ice(ln);
424+
}
427425

428-
if !self.force_host {
429-
self.force_host = config.parse_force_host(ln);
430-
}
426+
if !self.build_aux_docs {
427+
self.build_aux_docs = config.parse_build_aux_docs(ln);
428+
}
431429

432-
if !self.check_stdout {
433-
self.check_stdout = config.parse_check_stdout(ln);
434-
}
430+
if !self.force_host {
431+
self.force_host = config.parse_force_host(ln);
432+
}
435433

436-
if !self.check_run_results {
437-
self.check_run_results = config.parse_check_run_results(ln);
438-
}
434+
if !self.check_stdout {
435+
self.check_stdout = config.parse_check_stdout(ln);
436+
}
439437

440-
if !self.dont_check_compiler_stdout {
441-
self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
442-
}
438+
if !self.check_run_results {
439+
self.check_run_results = config.parse_check_run_results(ln);
440+
}
443441

444-
if !self.dont_check_compiler_stderr {
445-
self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
446-
}
442+
if !self.dont_check_compiler_stdout {
443+
self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
444+
}
447445

448-
if !self.no_prefer_dynamic {
449-
self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
450-
}
446+
if !self.dont_check_compiler_stderr {
447+
self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
448+
}
451449

452-
if !self.pretty_expanded {
453-
self.pretty_expanded = config.parse_pretty_expanded(ln);
454-
}
450+
if !self.no_prefer_dynamic {
451+
self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
452+
}
455453

456-
if let Some(m) = config.parse_pretty_mode(ln) {
457-
self.pretty_mode = m;
458-
}
454+
if !self.pretty_expanded {
455+
self.pretty_expanded = config.parse_pretty_expanded(ln);
456+
}
459457

460-
if !self.pretty_compare_only {
461-
self.pretty_compare_only = config.parse_pretty_compare_only(ln);
462-
}
458+
if let Some(m) = config.parse_pretty_mode(ln) {
459+
self.pretty_mode = m;
460+
}
463461

464-
if let Some(ab) = config.parse_aux_build(ln) {
465-
self.aux_builds.push(ab);
466-
}
462+
if !self.pretty_compare_only {
463+
self.pretty_compare_only = config.parse_pretty_compare_only(ln);
464+
}
467465

468-
if let Some(ac) = config.parse_aux_crate(ln) {
469-
self.aux_crates.push(ac);
470-
}
466+
if let Some(ab) = config.parse_aux_build(ln) {
467+
self.aux_builds.push(ab);
468+
}
471469

472-
if let Some(ee) = config.parse_env(ln, "exec-env") {
473-
self.exec_env.push(ee);
474-
}
470+
if let Some(ac) = config.parse_aux_crate(ln) {
471+
self.aux_crates.push(ac);
472+
}
475473

476-
if let Some(ee) = config.parse_env(ln, "rustc-env") {
477-
self.rustc_env.push(ee);
478-
}
474+
if let Some(ee) = config.parse_env(ln, "exec-env") {
475+
self.exec_env.push(ee);
476+
}
479477

480-
if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") {
481-
self.unset_rustc_env.push(ev);
482-
}
478+
if let Some(ee) = config.parse_env(ln, "rustc-env") {
479+
self.rustc_env.push(ee);
480+
}
483481

484-
if let Some(cl) = config.parse_check_line(ln) {
485-
self.check_lines.push(cl);
486-
}
482+
if let Some(ev) = config.parse_name_value_directive(ln, "unset-rustc-env") {
483+
self.unset_rustc_env.push(ev);
484+
}
487485

488-
if let Some(of) = config.parse_forbid_output(ln) {
489-
self.forbid_output.push(of);
490-
}
486+
if let Some(cl) = config.parse_check_line(ln) {
487+
self.check_lines.push(cl);
488+
}
491489

492-
if !self.check_test_line_numbers_match {
493-
self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
494-
}
490+
if let Some(of) = config.parse_forbid_output(ln) {
491+
self.forbid_output.push(of);
492+
}
495493

496-
self.update_pass_mode(ln, cfg, config);
497-
self.update_fail_mode(ln, config);
494+
if !self.check_test_line_numbers_match {
495+
self.check_test_line_numbers_match =
496+
config.parse_check_test_line_numbers_match(ln);
497+
}
498498

499-
if !self.ignore_pass {
500-
self.ignore_pass = config.parse_ignore_pass(ln);
501-
}
499+
self.update_pass_mode(ln, cfg, config);
500+
self.update_fail_mode(ln, config);
502501

503-
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
504-
self.normalize_stdout.push(rule);
505-
}
506-
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
507-
self.normalize_stderr.push(rule);
508-
}
502+
if !self.ignore_pass {
503+
self.ignore_pass = config.parse_ignore_pass(ln);
504+
}
509505

510-
if let Some(code) = config.parse_failure_status(ln) {
511-
self.failure_status = code;
512-
}
506+
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
507+
self.normalize_stdout.push(rule);
508+
}
509+
if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
510+
self.normalize_stderr.push(rule);
511+
}
513512

514-
if !self.run_rustfix {
515-
self.run_rustfix = config.parse_run_rustfix(ln);
516-
}
513+
if let Some(code) = config.parse_failure_status(ln) {
514+
self.failure_status = code;
515+
}
517516

518-
if !self.rustfix_only_machine_applicable {
519-
self.rustfix_only_machine_applicable =
520-
config.parse_rustfix_only_machine_applicable(ln);
521-
}
517+
if !self.run_rustfix {
518+
self.run_rustfix = config.parse_run_rustfix(ln);
519+
}
522520

523-
if self.assembly_output.is_none() {
524-
self.assembly_output = config.parse_assembly_output(ln);
525-
}
526-
});
521+
if !self.rustfix_only_machine_applicable {
522+
self.rustfix_only_machine_applicable =
523+
config.parse_rustfix_only_machine_applicable(ln);
524+
}
525+
526+
if self.assembly_output.is_none() {
527+
self.assembly_output = config.parse_assembly_output(ln);
528+
}
529+
});
530+
}
527531

528532
if self.failure_status == -1 {
529533
self.failure_status = match config.mode {
@@ -617,7 +621,7 @@ impl TestProps {
617621
}
618622
}
619623

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

631-
let rdr = BufReader::new(File::open(testfile).unwrap());
632-
for ln in rdr.lines() {
635+
let mut rdr = BufReader::new(rdr);
636+
let mut ln = String::new();
637+
638+
loop {
639+
ln.clear();
640+
if rdr.read_line(&mut ln).unwrap() == 0 {
641+
break;
642+
}
643+
633644
// Assume that any directives will be found before the first
634645
// module or function. This doesn't seem to be an optimization
635646
// with a warm page cache. Maybe with a cold one.
636-
let ln = ln.unwrap();
637647
let ln = ln.trim();
638648
if ln.starts_with("fn") || ln.starts_with("mod") {
639649
return;

0 commit comments

Comments
 (0)