@@ -5,9 +5,7 @@ use std::io::BufReader;
5
5
use std:: io:: prelude:: * ;
6
6
use std:: path:: { Path , PathBuf } ;
7
7
use std:: process:: Command ;
8
- use std:: sync:: OnceLock ;
9
8
10
- use regex:: Regex ;
11
9
use tracing:: * ;
12
10
13
11
use crate :: common:: { Config , Debugger , FailMode , Mode , PassMode } ;
@@ -797,7 +795,6 @@ struct HeaderLine<'ln> {
797
795
798
796
pub ( crate ) struct CheckDirectiveResult < ' ln > {
799
797
is_known_directive : bool ,
800
- directive_name : & ' ln str ,
801
798
trailing_directive : Option < & ' ln str > ,
802
799
}
803
800
@@ -832,11 +829,7 @@ pub(crate) fn check_directive<'a>(
832
829
}
833
830
. then_some ( trailing) ;
834
831
835
- CheckDirectiveResult {
836
- is_known_directive : is_known ( & directive_name) ,
837
- directive_name : directive_ln,
838
- trailing_directive,
839
- }
832
+ CheckDirectiveResult { is_known_directive : is_known ( & directive_name) , trailing_directive }
840
833
}
841
834
842
835
fn iter_header (
@@ -851,16 +844,17 @@ fn iter_header(
851
844
return ;
852
845
}
853
846
854
- // Coverage tests in coverage-run mode always have these extra directives,
855
- // without needing to specify them manually in every test file.
856
- // (Some of the comments below have been copied over from the old
857
- // `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
847
+ // Coverage tests in coverage-run mode always have these extra directives, without needing to
848
+ // specify them manually in every test file. (Some of the comments below have been copied over
849
+ // from the old `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
850
+ //
851
+ // FIXME(jieyouxu): I feel like there's a better way to do this, leaving for later.
858
852
if mode == Mode :: CoverageRun {
859
853
let extra_directives: & [ & str ] = & [
860
854
"needs-profiler-support" ,
861
- // FIXME(pietroalbini): this test currently does not work on cross-compiled
862
- // targets because remote-test is not capable of sending back the *.profraw
863
- // files generated by the LLVM instrumentation.
855
+ // FIXME(pietroalbini): this test currently does not work on cross-compiled targets
856
+ // because remote-test is not capable of sending back the *.profraw files generated by
857
+ // the LLVM instrumentation.
864
858
"ignore-cross-compile" ,
865
859
] ;
866
860
// Process the extra implied directives, with a dummy line number of 0.
@@ -869,17 +863,13 @@ fn iter_header(
869
863
}
870
864
}
871
865
866
+ // NOTE(jieyouxu): once we get rid of `Makefile`s we can unconditionally check for `//@`.
872
867
let comment = if testfile. extension ( ) . is_some_and ( |e| e == "rs" ) { "//@" } else { "#" } ;
873
868
874
869
let mut rdr = BufReader :: with_capacity ( 1024 , rdr) ;
875
870
let mut ln = String :: new ( ) ;
876
871
let mut line_number = 0 ;
877
872
878
- // Match on error annotations like `//~ERROR`.
879
- static REVISION_MAGIC_COMMENT_RE : OnceLock < Regex > = OnceLock :: new ( ) ;
880
- let revision_magic_comment_re =
881
- REVISION_MAGIC_COMMENT_RE . get_or_init ( || Regex :: new ( "//(\\ [.*\\ ])?~.*" ) . unwrap ( ) ) ;
882
-
883
873
loop {
884
874
line_number += 1 ;
885
875
ln. clear ( ) ;
@@ -892,85 +882,54 @@ fn iter_header(
892
882
// with a warm page cache. Maybe with a cold one.
893
883
let original_line = & ln;
894
884
let ln = ln. trim ( ) ;
895
- if ln. starts_with ( "fn" ) || ln. starts_with ( "mod" ) {
896
- return ;
897
-
898
- // First try to accept `ui_test` style comments (`//@`)
899
- } else if let Some ( ( header_revision, non_revisioned_directive_line) ) =
900
- line_directive ( comment, ln)
901
- {
902
- // Perform unknown directive check on Rust files.
903
- if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
904
- let directive_ln = non_revisioned_directive_line. trim ( ) ;
905
-
906
- let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
907
- check_directive ( directive_ln, mode, ln) ;
908
-
909
- if !is_known_directive {
910
- * poisoned = true ;
911
885
912
- eprintln ! (
913
- "error: detected unknown compiletest test directive `{}` in {}:{}" ,
914
- directive_ln,
915
- testfile. display( ) ,
916
- line_number,
917
- ) ;
886
+ let Some ( ( header_revision, non_revisioned_directive_line) ) = line_directive ( comment, ln)
887
+ else {
888
+ continue ;
889
+ } ;
918
890
919
- return ;
920
- }
891
+ // Perform unknown directive check on Rust files.
892
+ if testfile. extension ( ) . map ( |e| e == "rs" ) . unwrap_or ( false ) {
893
+ let directive_ln = non_revisioned_directive_line. trim ( ) ;
921
894
922
- if let Some ( trailing_directive) = & trailing_directive {
923
- * poisoned = true ;
895
+ let CheckDirectiveResult { is_known_directive , trailing_directive } =
896
+ check_directive ( directive_ln , mode , ln ) ;
924
897
925
- eprintln ! (
926
- "error: detected trailing compiletest test directive `{}` in {}:{}\n \
927
- help: put the trailing directive in it's own line: `//@ {}`",
928
- trailing_directive,
929
- testfile. display( ) ,
930
- line_number,
931
- trailing_directive,
932
- ) ;
933
-
934
- return ;
935
- }
936
- }
898
+ if !is_known_directive {
899
+ * poisoned = true ;
937
900
938
- it ( HeaderLine {
939
- line_number,
940
- original_line,
941
- header_revision,
942
- directive : non_revisioned_directive_line,
943
- } ) ;
944
- // Then we try to check for legacy-style candidates, which are not the magic ~ERROR family
945
- // error annotations.
946
- } else if !revision_magic_comment_re. is_match ( ln) {
947
- let Some ( ( _, rest) ) = line_directive ( "//" , ln) else {
948
- continue ;
949
- } ;
901
+ eprintln ! (
902
+ "error: detected unknown compiletest test directive `{}` in {}:{}" ,
903
+ directive_ln,
904
+ testfile. display( ) ,
905
+ line_number,
906
+ ) ;
950
907
951
- if rest. trim_start ( ) . starts_with ( ':' ) {
952
- // This is likely a markdown link:
953
- // `[link_name]: https://example.org`
954
- continue ;
908
+ return ;
955
909
}
956
910
957
- let rest = rest. trim_start ( ) ;
958
-
959
- let CheckDirectiveResult { is_known_directive, directive_name, .. } =
960
- check_directive ( rest, mode, ln) ;
961
-
962
- if is_known_directive {
911
+ if let Some ( trailing_directive) = & trailing_directive {
963
912
* poisoned = true ;
913
+
964
914
eprintln ! (
965
- "error: detected legacy-style directive {} in compiletest test: {}:{}, please use `ui_test`-style directives `//@` instead: {:#?}" ,
966
- directive_name,
915
+ "error: detected trailing compiletest test directive `{}` in {}:{}\n \
916
+ help: put the trailing directive in it's own line: `//@ {}`",
917
+ trailing_directive,
967
918
testfile. display( ) ,
968
919
line_number,
969
- line_directive ( "//" , ln ) ,
920
+ trailing_directive ,
970
921
) ;
922
+
971
923
return ;
972
924
}
973
925
}
926
+
927
+ it ( HeaderLine {
928
+ line_number,
929
+ original_line,
930
+ header_revision,
931
+ directive : non_revisioned_directive_line,
932
+ } ) ;
974
933
}
975
934
}
976
935
0 commit comments