]> git.proxmox.com Git - rustc.git/blame - vendor/syn/tests/repo/mod.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / vendor / syn / tests / repo / mod.rs
CommitLineData
60c5eb7d
XL
1use anyhow::Result;
2use flate2::read::GzDecoder;
3use std::fs;
4use std::path::Path;
5use tar::Archive;
6use walkdir::DirEntry;
e74abb32 7
60c5eb7d 8const REVISION: &str = "7979016aff545f7b41cc517031026020b340989d";
e74abb32
XL
9
10pub fn base_dir_filter(entry: &DirEntry) -> bool {
11 let path = entry.path();
12 if path.is_dir() {
13 return true; // otherwise walkdir does not visit the files
14 }
15 if path.extension().map(|e| e != "rs").unwrap_or(true) {
16 return false;
17 }
18 let path_string = path.to_string_lossy();
19 let path_string = if cfg!(windows) {
20 path_string.replace('\\', "/").into()
21 } else {
22 path_string
23 };
24 // TODO assert that parsing fails on the parse-fail cases
25 if path_string.starts_with("tests/rust/src/test/parse-fail")
26 || path_string.starts_with("tests/rust/src/test/compile-fail")
27 || path_string.starts_with("tests/rust/src/test/rustfix")
28 {
29 return false;
30 }
31
32 if path_string.starts_with("tests/rust/src/test/ui") {
33 let stderr_path = path.with_extension("stderr");
34 if stderr_path.exists() {
35 // Expected to fail in some way
36 return false;
37 }
38 }
39
40 match path_string.as_ref() {
41 // Deprecated placement syntax
42 "tests/rust/src/test/ui/obsolete-in-place/bad.rs" |
43 // Deprecated anonymous parameter syntax in traits
44 "tests/rust/src/test/ui/error-codes/e0119/auxiliary/issue-23563-a.rs" |
45 "tests/rust/src/test/ui/issues/issue-13105.rs" |
46 "tests/rust/src/test/ui/issues/issue-13775.rs" |
47 "tests/rust/src/test/ui/issues/issue-34074.rs" |
48 // Deprecated await macro syntax
49 "tests/rust/src/test/ui/async-await/await-macro.rs" |
50 // 2015-style dyn that libsyntax rejects
51 "tests/rust/src/test/ui/dyn-keyword/dyn-2015-no-warnings-without-lints.rs" |
52 // not actually test cases
60c5eb7d
XL
53 "tests/rust/src/test/ui/include-single-expr-helper.rs" |
54 "tests/rust/src/test/ui/include-single-expr-helper-1.rs" |
55 "tests/rust/src/test/ui/issues/auxiliary/issue-21146-inc.rs" |
e74abb32 56 "tests/rust/src/test/ui/macros/auxiliary/macro-comma-support.rs" |
60c5eb7d 57 "tests/rust/src/test/ui/macros/auxiliary/macro-include-items-expr.rs" => false,
e74abb32
XL
58 _ => true,
59 }
60}
61
62pub fn clone_rust() {
60c5eb7d
XL
63 let needs_clone = match fs::read_to_string("tests/rust/COMMIT") {
64 Err(_) => true,
65 Ok(contents) => contents.trim() != REVISION,
66 };
67 if needs_clone {
68 download_and_unpack().unwrap();
69 }
70}
71
72fn download_and_unpack() -> Result<()> {
73 let url = format!(
74 "https://github.com/rust-lang/rust/archive/{}.tar.gz",
75 REVISION
76 );
77 let response = reqwest::blocking::get(&url)?.error_for_status()?;
78 let decoder = GzDecoder::new(response);
79 let mut archive = Archive::new(decoder);
80 let prefix = format!("rust-{}", REVISION);
81
82 let tests_rust = Path::new("tests/rust");
83 if tests_rust.exists() {
84 fs::remove_dir_all(tests_rust)?;
85 }
86
87 for entry in archive.entries()? {
88 let mut entry = entry?;
89 let path = entry.path()?;
90 if path == Path::new("pax_global_header") {
91 continue;
92 }
93 let relative = path.strip_prefix(&prefix)?;
94 let out = tests_rust.join(relative);
95 entry.unpack(&out)?;
96 }
97
98 fs::write("tests/rust/COMMIT", REVISION)?;
99 Ok(())
e74abb32 100}