@@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader};
44
55use camino:: { Utf8Path , Utf8PathBuf } ;
66
7- use crate :: directives:: LineNumber ;
7+ use crate :: directives:: { LineNumber , line_directive } ;
88use crate :: runtest:: ProcRes ;
99
1010/// Representation of information to invoke a debugger and check its output
@@ -17,10 +17,16 @@ pub(super) struct DebuggerCommands {
1717 check_lines : Vec < ( LineNumber , String ) > ,
1818 /// Source file name
1919 file : Utf8PathBuf ,
20+ /// The revision being tested, if any
21+ revision : Option < String > ,
2022}
2123
2224impl DebuggerCommands {
23- pub fn parse_from ( file : & Utf8Path , debugger_prefix : & str ) -> Result < Self , String > {
25+ pub fn parse_from (
26+ file : & Utf8Path ,
27+ debugger_prefix : & str ,
28+ test_revision : Option < & str > ,
29+ ) -> Result < Self , String > {
2430 let command_directive = format ! ( "{debugger_prefix}-command" ) ;
2531 let check_directive = format ! ( "{debugger_prefix}-check" ) ;
2632
@@ -37,19 +43,33 @@ impl DebuggerCommands {
3743 continue ;
3844 }
3945
40- let Some ( line ) = line . trim_start ( ) . strip_prefix ( "//@" ) . map ( str :: trim_start ) else {
46+ let Some ( directive ) = line_directive ( file , line_number , & line ) else {
4147 continue ;
4248 } ;
4349
44- if let Some ( command ) = parse_name_value ( & line , & command_directive ) {
45- commands . push ( command ) ;
50+ if !directive . applies_to_test_revision ( test_revision ) {
51+ continue ;
4652 }
47- if let Some ( pattern) = parse_name_value ( & line, & check_directive) {
48- check_lines. push ( ( line_number, pattern) ) ;
53+
54+ if directive. name == command_directive
55+ && let Some ( command) = directive. value_after_colon ( )
56+ {
57+ commands. push ( command. to_string ( ) ) ;
58+ }
59+ if directive. name == check_directive
60+ && let Some ( pattern) = directive. value_after_colon ( )
61+ {
62+ check_lines. push ( ( line_number, pattern. to_string ( ) ) ) ;
4963 }
5064 }
5165
52- Ok ( Self { commands, breakpoint_lines, check_lines, file : file. to_path_buf ( ) } )
66+ Ok ( Self {
67+ commands,
68+ breakpoint_lines,
69+ check_lines,
70+ file : file. to_path_buf ( ) ,
71+ revision : test_revision. map ( str:: to_owned) ,
72+ } )
5373 }
5474
5575 /// Given debugger output and lines to check, ensure that every line is
@@ -81,9 +101,11 @@ impl DebuggerCommands {
81101 Ok ( ( ) )
82102 } else {
83103 let fname = self . file . file_name ( ) . unwrap ( ) ;
104+ let revision_suffix =
105+ self . revision . as_ref ( ) . map_or ( String :: new ( ) , |r| format ! ( "#{}" , r) ) ;
84106 let mut msg = format ! (
85- "check directive(s) from `{}` not found in debugger output. errors:" ,
86- self . file
107+ "check directive(s) from `{}{} ` not found in debugger output. errors:" ,
108+ self . file, revision_suffix
87109 ) ;
88110
89111 for ( src_lineno, err_line) in missing {
@@ -103,18 +125,6 @@ impl DebuggerCommands {
103125 }
104126}
105127
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-
118128/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
119129fn check_single_line ( line : & str , check_line : & str ) -> bool {
120130 // Allow check lines to leave parts unspecified (e.g., uninitialized
0 commit comments