Skip to content

Commit f186dad

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 an upcoming commit.
1 parent 0bd13c3 commit f186dad

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/tools/compiletest/src/directives.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::directives::directive_names::{
1515
};
1616
pub(crate) use crate::directives::file::FileDirectives;
1717
use crate::directives::handlers::DIRECTIVE_HANDLERS_MAP;
18-
use crate::directives::line::{DirectiveLine, line_directive};
18+
use crate::directives::line::DirectiveLine;
1919
use crate::directives::needs::CachedNeedsConditions;
2020
use crate::edition::{Edition, parse_edition};
2121
use crate::errors::ErrorKind;
@@ -29,6 +29,7 @@ mod directive_names;
2929
mod file;
3030
mod handlers;
3131
mod line;
32+
pub(crate) use line::line_directive;
3233
mod line_number;
3334
pub(crate) use line_number::LineNumber;
3435
mod needs;

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

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

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

7-
use crate::directives::LineNumber;
7+
use crate::directives::{LineNumber, line_directive};
88
use crate::runtest::ProcRes;
99

1010
/// Representation of information to invoke a debugger and check its output
@@ -37,15 +37,19 @@ impl DebuggerCommands {
3737
continue;
3838
}
3939

40-
let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
40+
let Some(directive) = line_directive(file, line_number, &line) else {
4141
continue;
4242
};
4343

44-
if let Some(command) = parse_name_value(&line, &command_directive) {
45-
commands.push(command);
44+
if directive.name == command_directive
45+
&& let Some(command) = directive.value_after_colon()
46+
{
47+
commands.push(command.to_string());
4648
}
47-
if let Some(pattern) = parse_name_value(&line, &check_directive) {
48-
check_lines.push((line_number, pattern));
49+
if directive.name == check_directive
50+
&& let Some(pattern) = directive.value_after_colon()
51+
{
52+
check_lines.push((line_number, pattern.to_string()));
4953
}
5054
}
5155

@@ -103,18 +107,6 @@ impl DebuggerCommands {
103107
}
104108
}
105109

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

0 commit comments

Comments
 (0)