Skip to content

Commit 5a0439f

Browse files
committed
compiletest: Use DirectiveLine also for debuginfo (read: debugger) tests
This not only reduces code duplication already, it also gives us revision parsing for free which we need in upcoming commits. Long term we should probably use newtypes to avoid mixing up zero-based and one-based line numbers. For now, rename var name to `zero_based_line_no` to make things slightly clearer. `check_lines` uses zero-based, but `DirectiveLine` use one-based.
1 parent 838a912 commit 5a0439f

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod cfg;
2828
mod directive_names;
2929
mod file;
3030
mod handlers;
31-
mod line;
31+
pub(crate) mod line;
3232
mod needs;
3333
#[cfg(test)]
3434
mod tests;

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl DebuggerCommands {
2828
let mut check_lines = vec![];
2929
let mut counter = 0;
3030
let reader = BufReader::new(File::open(file.as_std_path()).unwrap());
31-
for (line_no, line) in reader.lines().enumerate() {
31+
for (zero_based_line_no, line) in reader.lines().enumerate() {
3232
counter += 1;
3333
let line = line.map_err(|e| format!("Error while parsing debugger commands: {}", e))?;
3434

@@ -38,15 +38,21 @@ impl DebuggerCommands {
3838
continue;
3939
}
4040

41-
let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
41+
let Some(directive) =
42+
crate::directives::line::line_directive(file, zero_based_line_no + 1, &line)
43+
else {
4244
continue;
4345
};
4446

45-
if let Some(command) = parse_name_value(&line, &command_directive) {
46-
commands.push(command);
47+
if directive.name == command_directive
48+
&& let Some(command) = directive.value_after_colon()
49+
{
50+
commands.push(command.to_string());
4751
}
48-
if let Some(pattern) = parse_name_value(&line, &check_directive) {
49-
check_lines.push((line_no, pattern));
52+
if directive.name == check_directive
53+
&& let Some(check) = directive.value_after_colon()
54+
{
55+
check_lines.push((zero_based_line_no, check.to_string()));
5056
}
5157
}
5258

@@ -105,18 +111,6 @@ impl DebuggerCommands {
105111
}
106112
}
107113

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-
120114
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
121115
fn check_single_line(line: &str, check_line: &str) -> bool {
122116
// Allow check lines to leave parts unspecified (e.g., uninitialized

0 commit comments

Comments
 (0)