Skip to content

Commit 8b29afc

Browse files
committed
Migrate all TestProps directive processing into smaller named handlers
Use `git diff --color-moved --color-moved-ws=ignore-all-space` (or similar) to verify that the directive-processing lines have been moved without changes.
1 parent f23a3a9 commit 8b29afc

File tree

2 files changed

+355
-273
lines changed

2 files changed

+355
-273
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 14 additions & 272 deletions
Original file line numberDiff line numberDiff line change
@@ -373,279 +373,7 @@ impl TestProps {
373373

374374
if let Some(handler) = DIRECTIVE_HANDLERS_MAP.get(ln.name) {
375375
handler.handle(config, ln, self);
376-
// This directive has been handled, so move on to the next one.
377-
return;
378-
}
379-
380-
use directives::*;
381-
let props = &mut *self;
382-
383-
config.push_name_value_directive(ln, DOC_FLAGS, &mut props.doc_flags, |r| r);
384-
385-
fn split_flags(flags: &str) -> Vec<String> {
386-
// Individual flags can be single-quoted to preserve spaces; see
387-
// <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
388-
flags
389-
.split('\'')
390-
.enumerate()
391-
.flat_map(|(i, f)| {
392-
// (preserve line breaks)
393-
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
394-
})
395-
.map(move |s| s.to_owned())
396-
.collect::<Vec<_>>()
397-
}
398-
399-
if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) {
400-
let flags = split_flags(&flags);
401-
for (i, flag) in flags.iter().enumerate() {
402-
if flag == "--edition" || flag.starts_with("--edition=") {
403-
panic!("you must use `//@ edition` to configure the edition");
404-
}
405-
if (flag == "-C"
406-
&& flags.get(i + 1).is_some_and(|v| v.starts_with("incremental=")))
407-
|| flag.starts_with("-Cincremental=")
408-
{
409-
panic!(
410-
// (preserve line breaks)
411-
"you must use `//@ incremental` to enable incremental compilation"
412-
);
413-
}
414-
}
415-
props.compile_flags.extend(flags);
416-
}
417-
418-
if let Some(range) = parse_edition_range(config, ln) {
419-
props.edition = Some(range.edition_to_test(config.edition));
420-
}
421-
422-
config.parse_and_update_revisions(ln, &mut props.revisions);
423-
424-
if let Some(flags) = config.parse_name_value_directive(ln, RUN_FLAGS) {
425-
props.run_flags.extend(split_flags(&flags));
426-
}
427-
428-
if props.pp_exact.is_none() {
429-
props.pp_exact = config.parse_pp_exact(ln);
430-
}
431-
432-
config.set_name_directive(ln, SHOULD_ICE, &mut props.should_ice);
433-
config.set_name_directive(ln, BUILD_AUX_DOCS, &mut props.build_aux_docs);
434-
config.set_name_directive(
435-
// (preserve line breaks)
436-
ln,
437-
UNIQUE_DOC_OUT_DIR,
438-
&mut props.unique_doc_out_dir,
439-
);
440-
441-
config.set_name_directive(ln, FORCE_HOST, &mut props.force_host);
442-
config.set_name_directive(ln, CHECK_STDOUT, &mut props.check_stdout);
443-
config.set_name_directive(ln, CHECK_RUN_RESULTS, &mut props.check_run_results);
444-
config.set_name_directive(
445-
ln,
446-
DONT_CHECK_COMPILER_STDOUT,
447-
&mut props.dont_check_compiler_stdout,
448-
);
449-
config.set_name_directive(
450-
ln,
451-
DONT_CHECK_COMPILER_STDERR,
452-
&mut props.dont_check_compiler_stderr,
453-
);
454-
config.set_name_directive(ln, NO_PREFER_DYNAMIC, &mut props.no_prefer_dynamic);
455-
456-
if let Some(m) = config.parse_name_value_directive(ln, PRETTY_MODE) {
457-
props.pretty_mode = m;
458-
}
459-
460-
config.set_name_directive(
461-
// (preserve line breaks)
462-
ln,
463-
PRETTY_COMPARE_ONLY,
464-
&mut props.pretty_compare_only,
465-
);
466-
467-
// Call a helper method to deal with aux-related directives.
468-
parse_and_update_aux(config, ln, &mut props.aux);
469-
470-
config.push_name_value_directive(
471-
// (preserve line breaks)
472-
ln,
473-
EXEC_ENV,
474-
&mut props.exec_env,
475-
Config::parse_env,
476-
);
477-
config.push_name_value_directive(
478-
// (preserve line breaks)
479-
ln,
480-
UNSET_EXEC_ENV,
481-
&mut props.unset_exec_env,
482-
|r| r.trim().to_owned(),
483-
);
484-
config.push_name_value_directive(
485-
ln,
486-
RUSTC_ENV,
487-
&mut props.rustc_env,
488-
Config::parse_env,
489-
);
490-
config.push_name_value_directive(
491-
ln,
492-
UNSET_RUSTC_ENV,
493-
&mut props.unset_rustc_env,
494-
|r| r.trim().to_owned(),
495-
);
496-
config.push_name_value_directive(
497-
// (preserve line breaks)
498-
ln,
499-
FORBID_OUTPUT,
500-
&mut props.forbid_output,
501-
|r| r,
502-
);
503-
config.set_name_directive(
504-
ln,
505-
CHECK_TEST_LINE_NUMBERS_MATCH,
506-
&mut props.check_test_line_numbers_match,
507-
);
508-
509-
props.update_pass_mode(ln, config);
510-
props.update_fail_mode(ln, config);
511-
512-
config.set_name_directive(ln, IGNORE_PASS, &mut props.ignore_pass);
513-
514-
if let Some(NormalizeRule { kind, regex, replacement }) =
515-
config.parse_custom_normalization(ln)
516-
{
517-
let rule_tuple = (regex, replacement);
518-
match kind {
519-
NormalizeKind::Stdout => props.normalize_stdout.push(rule_tuple),
520-
NormalizeKind::Stderr => props.normalize_stderr.push(rule_tuple),
521-
NormalizeKind::Stderr32bit => {
522-
if config.target_cfg().pointer_width == 32 {
523-
props.normalize_stderr.push(rule_tuple);
524-
}
525-
}
526-
NormalizeKind::Stderr64bit => {
527-
if config.target_cfg().pointer_width == 64 {
528-
props.normalize_stderr.push(rule_tuple);
529-
}
530-
}
531-
}
532-
}
533-
534-
if let Some(code) = config
535-
.parse_name_value_directive(ln, FAILURE_STATUS)
536-
.and_then(|code| code.trim().parse::<i32>().ok())
537-
{
538-
props.failure_status = Some(code);
539-
}
540-
541-
config.set_name_directive(
542-
ln,
543-
DONT_CHECK_FAILURE_STATUS,
544-
&mut props.dont_check_failure_status,
545-
);
546-
547-
config.set_name_directive(ln, RUN_RUSTFIX, &mut props.run_rustfix);
548-
config.set_name_directive(
549-
ln,
550-
RUSTFIX_ONLY_MACHINE_APPLICABLE,
551-
&mut props.rustfix_only_machine_applicable,
552-
);
553-
config.set_name_value_directive(
554-
// (preserve line breaks)
555-
ln,
556-
ASSEMBLY_OUTPUT,
557-
&mut props.assembly_output,
558-
|r| r.trim().to_string(),
559-
);
560-
config.set_name_directive(
561-
// (preserve line breaks)
562-
ln,
563-
STDERR_PER_BITWIDTH,
564-
&mut props.stderr_per_bitwidth,
565-
);
566-
config.set_name_directive(ln, INCREMENTAL, &mut props.incremental);
567-
568-
// Unlike the other `name_value_directive`s this needs to be handled manually,
569-
// because it sets a `bool` flag.
570-
if let Some(known_bug) = config.parse_name_value_directive(ln, KNOWN_BUG) {
571-
let known_bug = known_bug.trim();
572-
if known_bug == "unknown"
573-
|| known_bug.split(',').all(|issue_ref| {
574-
issue_ref
575-
.trim()
576-
.split_once('#')
577-
.filter(|(_, number)| {
578-
// (preserve line breaks)
579-
number.chars().all(|digit| digit.is_numeric())
580-
})
581-
.is_some()
582-
})
583-
{
584-
props.known_bug = true;
585-
} else {
586-
panic!(
587-
"Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
588-
);
589-
}
590-
} else if config.parse_name_directive(ln, KNOWN_BUG) {
591-
panic!(
592-
"Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
593-
);
594-
}
595-
596-
config.set_name_value_directive(
597-
// (preserve line breaks)
598-
ln,
599-
TEST_MIR_PASS,
600-
&mut props.mir_unit_test,
601-
|s| s.trim().to_string(),
602-
);
603-
config.set_name_directive(ln, REMAP_SRC_BASE, &mut props.remap_src_base);
604-
605-
if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
606-
props.llvm_cov_flags.extend(split_flags(&flags));
607376
}
608-
609-
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
610-
props.filecheck_flags.extend(split_flags(&flags));
611-
}
612-
613-
config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut props.no_auto_check_cfg);
614-
615-
props.update_add_core_stubs(ln, config);
616-
617-
if let Some(flags) =
618-
// (preserve line breaks)
619-
config.parse_name_value_directive(ln, CORE_STUBS_COMPILE_FLAGS)
620-
{
621-
let flags = split_flags(&flags);
622-
for flag in &flags {
623-
if flag == "--edition" || flag.starts_with("--edition=") {
624-
panic!("you must use `//@ edition` to configure the edition");
625-
}
626-
}
627-
props.core_stubs_compile_flags.extend(flags);
628-
}
629-
630-
if let Some(err_kind) =
631-
// (preserve line breaks)
632-
config.parse_name_value_directive(ln, DONT_REQUIRE_ANNOTATIONS)
633-
{
634-
props
635-
.dont_require_annotations
636-
.insert(ErrorKind::expect_from_user_str(err_kind.trim()));
637-
}
638-
639-
config.set_name_directive(
640-
ln,
641-
DISABLE_GDB_PRETTY_PRINTERS,
642-
&mut props.disable_gdb_pretty_printers,
643-
);
644-
config.set_name_directive(
645-
ln,
646-
COMPARE_OUTPUT_BY_LINES,
647-
&mut props.compare_output_by_lines,
648-
);
649377
},
650378
);
651379

@@ -1730,3 +1458,17 @@ impl EditionRange {
17301458
}
17311459
}
17321460
}
1461+
1462+
fn split_flags(flags: &str) -> Vec<String> {
1463+
// Individual flags can be single-quoted to preserve spaces; see
1464+
// <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
1465+
flags
1466+
.split('\'')
1467+
.enumerate()
1468+
.flat_map(|(i, f)| {
1469+
// (preserve line breaks)
1470+
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
1471+
})
1472+
.map(move |s| s.to_owned())
1473+
.collect::<Vec<_>>()
1474+
}

0 commit comments

Comments
 (0)