diff options
Diffstat (limited to 'crates/tools/src/lib.rs')
-rw-r--r-- | crates/tools/src/lib.rs | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 311bcb4d8..ef9c613a7 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs | |||
@@ -58,10 +58,8 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { | |||
58 | None => continue 'outer, | 58 | None => continue 'outer, |
59 | } | 59 | } |
60 | }; | 60 | }; |
61 | let text: String = itertools::join( | 61 | let text: String = |
62 | block.map(|(_, line)| line).chain(::std::iter::once("")), | 62 | itertools::join(block.map(|(_, line)| line).chain(::std::iter::once("")), "\n"); |
63 | "\n", | ||
64 | ); | ||
65 | assert!(!text.trim().is_empty() && text.ends_with('\n')); | 63 | assert!(!text.trim().is_empty() && text.ends_with('\n')); |
66 | res.push((start_line, Test { name, text, ok })) | 64 | res.push((start_line, Test { name, text, ok })) |
67 | } | 65 | } |
@@ -78,11 +76,7 @@ pub fn generate(mode: Mode) -> Result<()> { | |||
78 | } | 76 | } |
79 | 77 | ||
80 | pub fn project_root() -> PathBuf { | 78 | pub fn project_root() -> PathBuf { |
81 | Path::new(&env!("CARGO_MANIFEST_DIR")) | 79 | Path::new(&env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap().to_path_buf() |
82 | .ancestors() | ||
83 | .nth(2) | ||
84 | .unwrap() | ||
85 | .to_path_buf() | ||
86 | } | 80 | } |
87 | 81 | ||
88 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { | 82 | pub fn run(cmdline: &str, dir: &str) -> Result<()> { |
@@ -90,10 +84,7 @@ pub fn run(cmdline: &str, dir: &str) -> Result<()> { | |||
90 | let project_dir = project_root().join(dir); | 84 | let project_dir = project_root().join(dir); |
91 | let mut args = cmdline.split_whitespace(); | 85 | let mut args = cmdline.split_whitespace(); |
92 | let exec = args.next().unwrap(); | 86 | let exec = args.next().unwrap(); |
93 | let status = Command::new(exec) | 87 | let status = Command::new(exec).args(args).current_dir(project_dir).status()?; |
94 | .args(args) | ||
95 | .current_dir(project_dir) | ||
96 | .status()?; | ||
97 | if !status.success() { | 88 | if !status.success() { |
98 | bail!("`{}` exited with {}", cmdline, status); | 89 | bail!("`{}` exited with {}", cmdline, status); |
99 | } | 90 | } |
@@ -112,10 +103,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
112 | }; | 103 | }; |
113 | 104 | ||
114 | if mode == Verify { | 105 | if mode == Verify { |
115 | run( | 106 | run(&format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), ".")?; |
116 | &format!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN), | ||
117 | ".", | ||
118 | )?; | ||
119 | } else { | 107 | } else { |
120 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; | 108 | run(&format!("rustup run {} -- cargo fmt", TOOLCHAIN), ".")?; |
121 | } | 109 | } |
@@ -124,10 +112,7 @@ pub fn run_rustfmt(mode: Mode) -> Result<()> { | |||
124 | 112 | ||
125 | pub fn install_rustfmt() -> Result<()> { | 113 | pub fn install_rustfmt() -> Result<()> { |
126 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; | 114 | run(&format!("rustup install {}", TOOLCHAIN), ".")?; |
127 | run( | 115 | run(&format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), ".") |
128 | &format!("rustup component add rustfmt --toolchain {}", TOOLCHAIN), | ||
129 | ".", | ||
130 | ) | ||
131 | } | 116 | } |
132 | 117 | ||
133 | pub fn install_format_hook() -> Result<()> { | 118 | pub fn install_format_hook() -> Result<()> { |
@@ -156,10 +141,7 @@ pub fn run_fuzzer() -> Result<()> { | |||
156 | _ => run("cargo install cargo-fuzz", ".")?, | 141 | _ => run("cargo install cargo-fuzz", ".")?, |
157 | }; | 142 | }; |
158 | 143 | ||
159 | run( | 144 | run("rustup run nightly -- cargo fuzz run parser", "./crates/ra_syntax") |
160 | "rustup run nightly -- cargo fuzz run parser", | ||
161 | "./crates/ra_syntax", | ||
162 | ) | ||
163 | } | 145 | } |
164 | 146 | ||
165 | pub fn gen_tests(mode: Mode) -> Result<()> { | 147 | pub fn gen_tests(mode: Mode) -> Result<()> { |
@@ -245,11 +227,7 @@ fn existing_tests(dir: &Path, ok: bool) -> Result<HashMap<String, (PathBuf, Test | |||
245 | file_name[5..file_name.len() - 3].to_string() | 227 | file_name[5..file_name.len() - 3].to_string() |
246 | }; | 228 | }; |
247 | let text = fs::read_to_string(&path)?; | 229 | let text = fs::read_to_string(&path)?; |
248 | let test = Test { | 230 | let test = Test { name: name.clone(), text, ok }; |
249 | name: name.clone(), | ||
250 | text, | ||
251 | ok, | ||
252 | }; | ||
253 | if let Some(old) = res.insert(name, (path, test)) { | 231 | if let Some(old) = res.insert(name, (path, test)) { |
254 | println!("Duplicate test: {:?}", old); | 232 | println!("Duplicate test: {:?}", old); |
255 | } | 233 | } |