@@ -12,6 +12,7 @@ use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
1212use crate :: directives:: directive_names:: {
1313 KNOWN_DIRECTIVE_NAMES , KNOWN_HTMLDOCCK_DIRECTIVE_NAMES , KNOWN_JSONDOCCK_DIRECTIVE_NAMES ,
1414} ;
15+ pub ( crate ) use crate :: directives:: file:: FileDirectives ;
1516use crate :: directives:: line:: { DirectiveLine , line_directive} ;
1617use crate :: directives:: needs:: CachedNeedsConditions ;
1718use crate :: edition:: { Edition , parse_edition} ;
@@ -23,6 +24,7 @@ use crate::{fatal, help};
2324pub ( crate ) mod auxiliary;
2425mod cfg;
2526mod directive_names;
27+ mod file;
2628mod line;
2729mod needs;
2830#[ cfg( test) ]
@@ -41,31 +43,29 @@ impl DirectivesCache {
4143/// Properties which must be known very early, before actually running
4244/// the test.
4345#[ derive( Default ) ]
44- pub struct EarlyProps {
46+ pub ( crate ) struct EarlyProps {
4547 /// Auxiliary crates that should be built and made available to this test.
4648 /// Included in [`EarlyProps`] so that the indicated files can participate
4749 /// in up-to-date checking. Building happens via [`TestProps::aux`] instead.
4850 pub ( crate ) aux : AuxProps ,
49- pub revisions : Vec < String > ,
51+ pub ( crate ) revisions : Vec < String > ,
5052}
5153
5254impl EarlyProps {
53- pub fn from_file ( config : & Config , testfile : & Utf8Path ) -> Self {
54- let file_contents =
55- fs:: read_to_string ( testfile) . expect ( "read test file to parse earlyprops" ) ;
56- Self :: from_file_contents ( config, testfile, & file_contents)
57- }
58-
59- pub fn from_file_contents ( config : & Config , testfile : & Utf8Path , file_contents : & str ) -> Self {
55+ pub ( crate ) fn from_file_directives (
56+ config : & Config ,
57+ file_directives : & FileDirectives < ' _ > ,
58+ ) -> Self {
59+ let testfile = file_directives. path ;
6060 let mut props = EarlyProps :: default ( ) ;
6161 let mut poisoned = false ;
62+
6263 iter_directives (
6364 config. mode ,
6465 & mut poisoned,
65- testfile,
66- file_contents,
66+ file_directives,
6767 // (dummy comment to force args into vertical layout)
68- & mut |ref ln: DirectiveLine < ' _ > | {
68+ & mut |ln : & DirectiveLine < ' _ > | {
6969 parse_and_update_aux ( config, ln, testfile, & mut props. aux ) ;
7070 config. parse_and_update_revisions ( testfile, ln, & mut props. revisions ) ;
7171 } ,
@@ -358,15 +358,15 @@ impl TestProps {
358358 let mut has_edition = false ;
359359 if !testfile. is_dir ( ) {
360360 let file_contents = fs:: read_to_string ( testfile) . unwrap ( ) ;
361+ let file_directives = FileDirectives :: from_file_contents ( testfile, & file_contents) ;
361362
362363 let mut poisoned = false ;
363364
364365 iter_directives (
365366 config. mode ,
366367 & mut poisoned,
367- testfile,
368- & file_contents,
369- & mut |ref ln: DirectiveLine < ' _ > | {
368+ & file_directives,
369+ & mut |ln : & DirectiveLine < ' _ > | {
370370 if !ln. applies_to_test_revision ( test_revision) {
371371 return ;
372372 }
@@ -851,13 +851,10 @@ fn check_directive<'a>(
851851fn iter_directives (
852852 mode : TestMode ,
853853 poisoned : & mut bool ,
854- testfile : & Utf8Path ,
855- file_contents : & str ,
856- it : & mut dyn FnMut ( DirectiveLine < ' _ > ) ,
854+ file_directives : & FileDirectives < ' _ > ,
855+ it : & mut dyn FnMut ( & DirectiveLine < ' _ > ) ,
857856) {
858- if testfile. is_dir ( ) {
859- return ;
860- }
857+ let testfile = file_directives. path ;
861858
862859 // Coverage tests in coverage-run mode always have these extra directives, without needing to
863860 // specify them manually in every test file.
@@ -875,21 +872,15 @@ fn iter_directives(
875872 for directive_str in extra_directives {
876873 let directive_line = line_directive ( 0 , directive_str)
877874 . unwrap_or_else ( || panic ! ( "bad extra-directive line: {directive_str:?}" ) ) ;
878- it ( directive_line) ;
875+ it ( & directive_line) ;
879876 }
880877 }
881878
882- for ( line_number, ln) in ( 1 ..) . zip ( file_contents. lines ( ) ) {
883- let ln = ln. trim ( ) ;
884-
885- let Some ( directive_line) = line_directive ( line_number, ln) else {
886- continue ;
887- } ;
888-
879+ for directive_line @ & DirectiveLine { line_number, .. } in & file_directives. lines {
889880 // Perform unknown directive check on Rust files.
890881 if testfile. extension ( ) == Some ( "rs" ) {
891882 let CheckDirectiveResult { is_known_directive, trailing_directive } =
892- check_directive ( & directive_line, mode) ;
883+ check_directive ( directive_line, mode) ;
893884
894885 if !is_known_directive {
895886 * poisoned = true ;
@@ -1349,7 +1340,7 @@ pub(crate) fn make_test_description(
13491340 name : String ,
13501341 path : & Utf8Path ,
13511342 filterable_path : & Utf8Path ,
1352- file_contents : & str ,
1343+ file_directives : & FileDirectives < ' _ > ,
13531344 test_revision : Option < & str > ,
13541345 poisoned : & mut bool ,
13551346) -> CollectedTestDesc {
@@ -1363,9 +1354,8 @@ pub(crate) fn make_test_description(
13631354 iter_directives (
13641355 config. mode ,
13651356 & mut local_poisoned,
1366- path,
1367- file_contents,
1368- & mut |ref ln @ DirectiveLine { line_number, .. } | {
1357+ file_directives,
1358+ & mut |ln @ & DirectiveLine { line_number, .. } | {
13691359 if !ln. applies_to_test_revision ( test_revision) {
13701360 return ;
13711361 }
0 commit comments