]> git.proxmox.com Git - rustc.git/blame - vendor/syn/tests/repo/mod.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / vendor / syn / tests / repo / mod.rs
CommitLineData
f035d41b
XL
1mod progress;
2
3use self::progress::Progress;
60c5eb7d
XL
4use anyhow::Result;
5use flate2::read::GzDecoder;
6use std::fs;
7use std::path::Path;
8use tar::Archive;
9use walkdir::DirEntry;
e74abb32 10
6a06907d 11const REVISION: &str = "e708cbd91c9cae4426d69270248362b423324556";
f035d41b
XL
12
13#[rustfmt::skip]
14static EXCLUDE: &[&str] = &[
1b1a35ee 15 // Compile-fail expr parameter in const generic position: f::<1 + 2>()
5869c6ff
XL
16 "src/test/ui/const-generics/closing-args-token.rs",
17 "src/test/ui/const-generics/const-expression-parameter.rs",
1b1a35ee 18
f035d41b 19 // Deprecated anonymous parameter syntax in traits
5869c6ff
XL
20 "src/test/ui/issues/issue-13105.rs",
21 "src/test/ui/issues/issue-13775.rs",
22 "src/test/ui/issues/issue-34074.rs",
23 "src/test/ui/proc-macro/trait-fn-args-2015.rs",
f035d41b 24
1b1a35ee 25 // Not actually test cases
5869c6ff
XL
26 "src/test/rustdoc-ui/test-compile-fail2.rs",
27 "src/test/rustdoc-ui/test-compile-fail3.rs",
28 "src/test/ui/include-single-expr-helper.rs",
29 "src/test/ui/include-single-expr-helper-1.rs",
5869c6ff
XL
30 "src/test/ui/json-bom-plus-crlf-multifile-aux.rs",
31 "src/test/ui/lint/expansion-time-include.rs",
32 "src/test/ui/macros/auxiliary/macro-comma-support.rs",
33 "src/test/ui/macros/auxiliary/macro-include-items-expr.rs",
6a06907d 34 "src/test/ui/parser/auxiliary/issue-21146-inc.rs",
f035d41b 35];
e74abb32
XL
36
37pub fn base_dir_filter(entry: &DirEntry) -> bool {
38 let path = entry.path();
39 if path.is_dir() {
40 return true; // otherwise walkdir does not visit the files
41 }
42 if path.extension().map(|e| e != "rs").unwrap_or(true) {
43 return false;
44 }
f035d41b
XL
45
46 let mut path_string = path.to_string_lossy();
47 if cfg!(windows) {
48 path_string = path_string.replace('\\', "/").into();
49 }
5869c6ff 50 let path = if let Some(path) = path_string.strip_prefix("tests/rust/") {
3dfed10e
XL
51 path
52 } else {
53 panic!("unexpected path in Rust dist: {}", path_string);
54 };
f035d41b 55
5869c6ff 56 if path.starts_with("src/test/compile-fail") || path.starts_with("src/test/rustfix") {
e74abb32
XL
57 return false;
58 }
59
5869c6ff 60 if path.starts_with("src/test/ui") {
f035d41b 61 let stderr_path = entry.path().with_extension("stderr");
e74abb32
XL
62 if stderr_path.exists() {
63 // Expected to fail in some way
64 return false;
65 }
66 }
67
f035d41b
XL
68 !EXCLUDE.contains(&path)
69}
70
71#[allow(dead_code)]
72pub fn edition(path: &Path) -> &'static str {
73 if path.ends_with("dyn-2015-no-warnings-without-lints.rs") {
74 "2015"
75 } else {
76 "2018"
e74abb32
XL
77 }
78}
79
80pub fn clone_rust() {
60c5eb7d
XL
81 let needs_clone = match fs::read_to_string("tests/rust/COMMIT") {
82 Err(_) => true,
83 Ok(contents) => contents.trim() != REVISION,
84 };
85 if needs_clone {
86 download_and_unpack().unwrap();
87 }
f035d41b 88 let mut missing = String::new();
5869c6ff 89 let test_src = Path::new("tests/rust");
f035d41b
XL
90 for exclude in EXCLUDE {
91 if !test_src.join(exclude).exists() {
5869c6ff 92 missing += "\ntests/rust/";
f035d41b
XL
93 missing += exclude;
94 }
95 }
96 if !missing.is_empty() {
97 panic!("excluded test file does not exist:{}\n", missing);
98 }
60c5eb7d
XL
99}
100
101fn download_and_unpack() -> Result<()> {
102 let url = format!(
103 "https://github.com/rust-lang/rust/archive/{}.tar.gz",
104 REVISION
105 );
106 let response = reqwest::blocking::get(&url)?.error_for_status()?;
f035d41b
XL
107 let progress = Progress::new(response);
108 let decoder = GzDecoder::new(progress);
60c5eb7d
XL
109 let mut archive = Archive::new(decoder);
110 let prefix = format!("rust-{}", REVISION);
111
112 let tests_rust = Path::new("tests/rust");
113 if tests_rust.exists() {
114 fs::remove_dir_all(tests_rust)?;
115 }
116
117 for entry in archive.entries()? {
118 let mut entry = entry?;
119 let path = entry.path()?;
120 if path == Path::new("pax_global_header") {
121 continue;
122 }
123 let relative = path.strip_prefix(&prefix)?;
124 let out = tests_rust.join(relative);
125 entry.unpack(&out)?;
126 }
127
128 fs::write("tests/rust/COMMIT", REVISION)?;
129 Ok(())
e74abb32 130}