From 9ab8c632ee2ede9a350104278864154d933ed1db Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 4 Jan 2024 11:08:01 +1100 Subject: [PATCH] Extract a `split_flags` helper in header directive parsing --- src/tools/compiletest/src/header.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index f85f9e674ab..a9f022664cf 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -321,16 +321,23 @@ impl TestProps { |r| r, ); - if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { - self.compile_flags.extend( - flags - .split("'") - .enumerate() - .flat_map(|(i, f)| { + fn split_flags(flags: &str) -> Vec { + // Individual flags can be single-quoted to preserve spaces; see + // . + flags + .split("'") + .enumerate() + .flat_map( + |(i, f)| { if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() } - }) - .map(|s| s.to_owned()), - ); + }, + ) + .map(move |s| s.to_owned()) + .collect::>() + } + + if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) { + self.compile_flags.extend(split_flags(&flags)); } if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() { panic!("`compiler-flags` directive should be spelled `compile-flags`");