Skip to content

Commit 505a208

Browse files
committed
Split off a separate name/value parser for debuginfo test commands
1 parent 29b7717 commit 505a208

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl Config {
11211121
line.starts_with("no-") && self.parse_name_directive(&line[3..], directive)
11221122
}
11231123

1124-
pub fn parse_name_value_directive(
1124+
fn parse_name_value_directive(
11251125
&self,
11261126
line: &str,
11271127
directive: &str,

src/tools/compiletest/src/runtest/debugger.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::io::{BufRead, BufReader};
44

55
use camino::{Utf8Path, Utf8PathBuf};
66

7-
use crate::common::Config;
87
use crate::runtest::ProcRes;
98

109
/// Representation of information to invoke a debugger and check its output
@@ -20,11 +19,7 @@ pub(super) struct DebuggerCommands {
2019
}
2120

2221
impl DebuggerCommands {
23-
pub fn parse_from(
24-
file: &Utf8Path,
25-
config: &Config,
26-
debugger_prefix: &str,
27-
) -> Result<Self, String> {
22+
pub fn parse_from(file: &Utf8Path, debugger_prefix: &str) -> Result<Self, String> {
2823
let command_directive = format!("{debugger_prefix}-command");
2924
let check_directive = format!("{debugger_prefix}-check");
3025

@@ -47,14 +42,10 @@ impl DebuggerCommands {
4742
continue;
4843
};
4944

50-
if let Some(command) =
51-
config.parse_name_value_directive(&line, &command_directive, file, line_no)
52-
{
45+
if let Some(command) = parse_name_value(&line, &command_directive) {
5346
commands.push(command);
5447
}
55-
if let Some(pattern) =
56-
config.parse_name_value_directive(&line, &check_directive, file, line_no)
57-
{
48+
if let Some(pattern) = parse_name_value(&line, &check_directive) {
5849
check_lines.push((line_no, pattern));
5950
}
6051
}
@@ -114,6 +105,18 @@ impl DebuggerCommands {
114105
}
115106
}
116107

108+
/// Split off from the main `parse_name_value_directive`, so that improvements
109+
/// to directive handling aren't held back by debuginfo test commands.
110+
fn parse_name_value(line: &str, name: &str) -> Option<String> {
111+
if let Some(after_name) = line.strip_prefix(name)
112+
&& let Some(value) = after_name.strip_prefix(':')
113+
{
114+
Some(value.to_owned())
115+
} else {
116+
None
117+
}
118+
}
119+
117120
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
118121
fn check_single_line(line: &str, check_line: &str) -> bool {
119122
// Allow check lines to leave parts unspecified (e.g., uninitialized

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl TestCx<'_> {
5959
}
6060

6161
// Parse debugger commands etc from test files
62-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "cdb")
62+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb")
6363
.unwrap_or_else(|e| self.fatal(&e));
6464

6565
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
@@ -130,7 +130,7 @@ impl TestCx<'_> {
130130
}
131131

132132
fn run_debuginfo_gdb_test_no_opt(&self) {
133-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "gdb")
133+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb")
134134
.unwrap_or_else(|e| self.fatal(&e));
135135
let mut cmds = dbg_cmds.commands.join("\n");
136136

@@ -397,7 +397,7 @@ impl TestCx<'_> {
397397
}
398398

399399
// Parse debugger commands etc from test files
400-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, self.config, "lldb")
400+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb")
401401
.unwrap_or_else(|e| self.fatal(&e));
402402

403403
// Write debugger script:

0 commit comments

Comments
 (0)