@@ -60,8 +60,36 @@ pub(crate) struct SpecPath<'a> {
6060 pub root_dir : RootDir ,
6161 /// A relative offset into `root_dir`.
6262 pub path : Cow < ' a , Utf8Path > ,
63+ pub r#type : SpecType ,
6364}
6465
66+ #[ derive( Clone , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
67+ pub ( crate ) enum SpecType {
68+ /// A catch-all for all `*.html` test spec. files. This is likely incorrect, but it works well
69+ /// enough for now!
70+ Html ,
71+ // NOTE: Other types exist, but we haven't been forced to support them yet. 🙂
72+ }
73+
74+ impl SpecType {
75+ fn iter ( ) -> impl Iterator < Item = Self > {
76+ [ Self :: Html ] . into_iter ( )
77+ }
78+
79+ pub fn from_base_name ( base_name : & str ) -> Option < ( Self , & str ) > {
80+ Self :: iter ( ) . find_map ( |variant| {
81+ base_name
82+ . strip_suffix ( variant. file_extension ( ) )
83+ . map ( |some| ( variant, some) )
84+ } )
85+ }
86+
87+ pub fn file_extension ( & self ) -> & ' static str {
88+ match self {
89+ SpecType :: Html => ".html" ,
90+ }
91+ }
92+ }
6593/// A symbolic path to an executed WPT test entry and its metadata, contained in a test
6694/// specification (see also [`SpecPath`]). In combination with [`SpecPath`], this is useful for
6795/// correlating entries from [`ExecutionReport`]s and [`metadata::File`]s.
@@ -118,10 +146,17 @@ impl<'a> TestEntryPath<'a> {
118146 None => return Err ( err ( ) ) ,
119147 } ;
120148
149+ let ( spec_type, path) = if let Some ( path) = path. strip_suffix ( ".html" ) {
150+ ( SpecType :: Html , path)
151+ } else {
152+ return Err ( err ( ) ) ;
153+ } ;
154+
121155 Ok ( Self {
122156 spec_path : SpecPath {
123157 root_dir,
124158 path : Utf8Path :: new ( path) . into ( ) ,
159+ r#type : spec_type,
125160 } ,
126161 test_entry : TestEntry {
127162 variant : variant. map ( Into :: into) ,
@@ -144,12 +179,16 @@ impl<'a> TestEntryPath<'a> {
144179 rel_meta_file_path : rel_meta_file_path. as_std_path ( ) ,
145180 test_name,
146181 } ;
147- let rel_meta_file_path = Utf8Path :: new (
148- rel_meta_file_path
182+ let ( spec_type , rel_meta_file_path) = {
183+ let test_base_name = rel_meta_file_path
149184 . as_str ( )
150185 . strip_suffix ( ".ini" )
151- . ok_or_else ( err) ?,
152- ) ;
186+ . ok_or_else ( err) ?;
187+
188+ let ( spec_type, stripped) = SpecType :: from_base_name ( test_base_name) . ok_or_else ( err) ?;
189+
190+ ( spec_type, Utf8Path :: new ( stripped) )
191+ } ;
153192
154193 let ( root_dir, path) = browser
155194 . strip_wpt_root_dir_prefix ( rel_meta_file_path)
@@ -161,6 +200,10 @@ impl<'a> TestEntryPath<'a> {
161200
162201 let ( base_name, variant) = Self :: split_test_base_name_from_variant ( test_name) ;
163202
203+ let base_name = match spec_type {
204+ SpecType :: Html => base_name. strip_suffix ( ".html" ) . ok_or_else ( err) ?,
205+ } ;
206+
164207 if path. components ( ) . next_back ( ) != Some ( Utf8Component :: Normal ( base_name) ) {
165208 return Err ( err ( ) ) ;
166209 }
@@ -169,6 +212,7 @@ impl<'a> TestEntryPath<'a> {
169212 spec_path : SpecPath {
170213 root_dir,
171214 path : path. into ( ) ,
215+ r#type : spec_type,
172216 } ,
173217 test_entry : TestEntry {
174218 variant : variant. map ( Into :: into) ,
@@ -188,14 +232,20 @@ impl<'a> TestEntryPath<'a> {
188232
189233 pub fn into_owned ( self ) -> TestEntryPath < ' static > {
190234 let Self {
191- spec_path : SpecPath { root_dir, path } ,
235+ spec_path :
236+ SpecPath {
237+ root_dir,
238+ path,
239+ r#type,
240+ } ,
192241 test_entry : TestEntry { variant } ,
193242 } = self ;
194243
195244 TestEntryPath {
196245 spec_path : SpecPath {
197246 root_dir : root_dir. clone ( ) ,
198247 path : path. clone ( ) . into_owned ( ) . into ( ) ,
248+ r#type,
199249 } ,
200250 test_entry : TestEntry {
201251 variant : variant. clone ( ) . map ( |v| v. into_owned ( ) . into ( ) ) ,
@@ -205,13 +255,19 @@ impl<'a> TestEntryPath<'a> {
205255
206256 pub ( crate ) fn test_name ( & self ) -> impl Display + ' _ {
207257 let Self {
208- spec_path : SpecPath { root_dir : _, path } ,
258+ spec_path :
259+ SpecPath {
260+ root_dir : _,
261+ path,
262+ r#type,
263+ } ,
209264 test_entry : TestEntry { variant } ,
210265 } = self ;
211266 let base_name = path. file_name ( ) . unwrap ( ) ;
267+ let file_extension = r#type. file_extension ( ) ;
212268
213269 lazy_format ! ( move |f| {
214- write!( f, "{base_name}" ) ?;
270+ write!( f, "{base_name}{file_extension} " ) ?;
215271 if let Some ( variant) = variant {
216272 write!( f, "{variant}" ) ?;
217273 }
@@ -221,15 +277,21 @@ impl<'a> TestEntryPath<'a> {
221277
222278 pub ( crate ) fn runner_url_path ( & self ) -> impl Display + ' _ {
223279 let Self {
224- spec_path : SpecPath { root_dir, path } ,
280+ spec_path :
281+ SpecPath {
282+ root_dir,
283+ path,
284+ r#type,
285+ } ,
225286 test_entry : TestEntry { variant } ,
226287 } = self ;
227288 lazy_format ! ( move |f| {
228289 write!(
229290 f,
230- "{}{}" ,
291+ "{}{}{} " ,
231292 root_dir. url_prefix( ) ,
232- path. components( ) . join_with( '/' )
293+ path. components( ) . join_with( '/' ) ,
294+ r#type. file_extension( )
233295 ) ?;
234296 if let Some ( variant) = variant. as_ref( ) {
235297 write!( f, "{}" , variant) ?;
@@ -240,17 +302,27 @@ impl<'a> TestEntryPath<'a> {
240302
241303 pub ( crate ) fn rel_metadata_path ( & self ) -> impl Display + ' _ {
242304 let Self {
243- spec_path : SpecPath { root_dir, path } ,
305+ spec_path :
306+ SpecPath {
307+ root_dir,
308+ path,
309+ r#type,
310+ } ,
244311 test_entry : TestEntry { variant : _ } ,
245312 } = self ;
246313
247314 let root_dir_dir = root_dir
248315 . components ( )
249316 . chain ( [ "meta" ] . iter ( ) . cloned ( ) )
250317 . join_with ( std:: path:: MAIN_SEPARATOR ) ;
318+ let file_extension = r#type. file_extension ( ) ;
251319
252320 lazy_format ! ( move |f| {
253- write!( f, "{root_dir_dir}{}{path}.ini" , std:: path:: MAIN_SEPARATOR )
321+ write!(
322+ f,
323+ "{root_dir_dir}{}{path}{file_extension}.ini" ,
324+ std:: path:: MAIN_SEPARATOR
325+ )
254326 } )
255327 }
256328}
@@ -372,7 +444,8 @@ fn parse_test_entry_path() {
372444 TestEntryPath {
373445 spec_path: SpecPath {
374446 root_dir: FirefoxRootDir :: Mozilla . into( ) ,
375- path: Utf8Path :: new( "blarg/cts.https.html" ) . into( ) ,
447+ path: Utf8Path :: new( "blarg/cts.https" ) . into( ) ,
448+ r#type: SpecType :: Html ,
376449 } ,
377450 test_entry: TestEntry {
378451 variant: Some ( "?stuff=things" . into( ) ) ,
@@ -390,7 +463,8 @@ fn parse_test_entry_path() {
390463 TestEntryPath {
391464 spec_path: SpecPath {
392465 root_dir: FirefoxRootDir :: Upstream . into( ) ,
393- path: Utf8Path :: new( "stuff/things/cts.https.html" ) . into( ) ,
466+ path: Utf8Path :: new( "stuff/things/cts.https" ) . into( ) ,
467+ r#type: SpecType :: Html ,
394468 } ,
395469 test_entry: TestEntry { variant: None }
396470 }
@@ -406,7 +480,8 @@ fn parse_test_entry_path() {
406480 TestEntryPath {
407481 spec_path: SpecPath {
408482 root_dir: ServoRootDir :: WebGpu . into( ) ,
409- path: Utf8Path :: new( "webgpu/cts.https.html" ) . into( ) ,
483+ path: Utf8Path :: new( "webgpu/cts.https" ) . into( ) ,
484+ r#type: SpecType :: Html ,
410485 } ,
411486 test_entry: TestEntry {
412487 variant: Some ( "?stuff=things" . into( ) ) ,
0 commit comments