]> git.proxmox.com Git - rustc.git/blob - src/vendor/html5ever/tests/foreach_html5lib_test/mod.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / vendor / html5ever / tests / foreach_html5lib_test / mod.rs
1 // Copyright 2014-2017 The html5ever Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 use std::fs;
11 use std::ffi::OsStr;
12 use std::path::Path;
13 use std::ops::FnMut;
14
15 pub fn foreach_html5lib_test<Mk>(
16 src_dir: &Path,
17 subdir: &'static str,
18 ext: &'static OsStr,
19 mut mk: Mk)
20 where Mk: FnMut(&Path, fs::File)
21 {
22 let mut test_dir_path = src_dir.to_path_buf();
23 test_dir_path.push("html5lib-tests");
24 test_dir_path.push(subdir);
25
26 let maybe_test_files = fs::read_dir(&test_dir_path);
27 match maybe_test_files {
28 Ok(test_files) => {
29 for entry in test_files {
30 let path = entry.unwrap().path();
31 if path.extension() == Some(ext) {
32 let file = fs::File::open(&path).unwrap();
33 mk(&path, file);
34 }
35 }
36 },
37 Err(_) => {
38 panic!("Before launching the tests, please run this command:\n\n\tgit submodule update --init\n\nto retrieve an html5lib-tests snapshot.");
39 }
40 }
41 }