aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-31 13:16:09 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-31 13:16:09 +0000
commit700b334a28b73133a25416319475eafe3ec11f90 (patch)
treec37c3675eec2e0e789c8d82669640116da31f80f
parenta3ee07ac149867d1d7b9c00a752d0c46c337a878 (diff)
parentf61830d6768ecb0d2a9c5f4c80ed9c561c9daa6f (diff)
Merge #393
393: Add a fuzzing subcommand r=matklad a=DJMcNab Part of https://github.com/rust-analyzer/rust-analyzer/issues/61#issuecomment-450641045. Co-authored-by: DJMcNab <[email protected]>
-rw-r--r--.cargo/config18
-rw-r--r--crates/tools/src/lib.rs17
-rw-r--r--crates/tools/src/main.rs7
3 files changed, 35 insertions, 7 deletions
diff --git a/.cargo/config b/.cargo/config
index c319d33f2..b9db30c96 100644
--- a/.cargo/config
+++ b/.cargo/config
@@ -1,10 +1,16 @@
1[alias] 1[alias]
2# Automatically generates the ast and syntax kinds files 2# Automatically generates the ast and syntax kinds files
3gen-syntax = "run --package tools --bin tools -- gen-syntax" 3gen-syntax = "run --package tools --bin tools -- gen-syntax"
4gen-tests = "run --package tools --bin tools -- gen-tests" 4# Extracts the tests from
5gen-tests = "run --package tools --bin tools -- gen-tests"
6# Installs the visual studio code extension
5install-code = "run --package tools --bin tools -- install-code" 7install-code = "run --package tools --bin tools -- install-code"
6format = "run --package tools --bin tools -- format" 8# Formats the full repository or installs the git hook to do it automatically.
7format-hook = "run --package tools --bin tools -- format-hook" 9format = "run --package tools --bin tools -- format"
10format-hook = "run --package tools --bin tools -- format-hook"
11# Runs the fuzzing test suite (currently only parser)
12fuzz-tests = "run --package tools --bin tools -- fuzz-tests"
8 13
9render-test = "run --package ra_cli -- render-test" 14render-test = "run --package ra_cli -- render-test"
10parse = "run --package ra_cli -- parse" 15# Parse a file. This should be piped the file contents
16parse = "run --package ra_cli -- parse"
diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs
index e5b32c25c..fa619af33 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/tools/src/lib.rs
@@ -139,3 +139,20 @@ pub fn install_format_hook() -> Result<()> {
139 } 139 }
140 Ok(()) 140 Ok(())
141} 141}
142
143pub fn run_fuzzer() -> Result<()> {
144 match Command::new("cargo")
145 .args(&["fuzz", "--help"])
146 .stderr(Stdio::null())
147 .stdout(Stdio::null())
148 .status()
149 {
150 Ok(status) if status.success() => (),
151 _ => run("cargo install cargo-fuzz", ".")?,
152 };
153
154 run(
155 "rustup run nightly -- cargo fuzz run parser",
156 "./crates/ra_syntax",
157 )
158}
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs
index 7edf8f52d..9d73d57c4 100644
--- a/crates/tools/src/main.rs
+++ b/crates/tools/src/main.rs
@@ -7,7 +7,10 @@ use std::{
7use clap::{App, Arg, SubCommand}; 7use clap::{App, Arg, SubCommand};
8use failure::bail; 8use failure::bail;
9 9
10use tools::{collect_tests, generate, install_format_hook, run, run_rustfmt, Mode, Overwrite, Result, Test, Verify, project_root}; 10use tools::{
11 collect_tests, generate,install_format_hook, run, run_rustfmt,
12 Mode, Overwrite, Result, Test, Verify, project_root, run_fuzzer
13};
11 14
12const GRAMMAR_DIR: &str = "crates/ra_syntax/src/grammar"; 15const GRAMMAR_DIR: &str = "crates/ra_syntax/src/grammar";
13const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/ok"; 16const OK_INLINE_TESTS_DIR: &str = "crates/ra_syntax/tests/data/parser/inline/ok";
@@ -27,6 +30,7 @@ fn main() -> Result<()> {
27 .subcommand(SubCommand::with_name("install-code")) 30 .subcommand(SubCommand::with_name("install-code"))
28 .subcommand(SubCommand::with_name("format")) 31 .subcommand(SubCommand::with_name("format"))
29 .subcommand(SubCommand::with_name("format-hook")) 32 .subcommand(SubCommand::with_name("format-hook"))
33 .subcommand(SubCommand::with_name("fuzz-tests"))
30 .get_matches(); 34 .get_matches();
31 let mode = if matches.is_present("verify") { 35 let mode = if matches.is_present("verify") {
32 Verify 36 Verify
@@ -42,6 +46,7 @@ fn main() -> Result<()> {
42 "gen-syntax" => generate(Overwrite)?, 46 "gen-syntax" => generate(Overwrite)?,
43 "format" => run_rustfmt(mode)?, 47 "format" => run_rustfmt(mode)?,
44 "format-hook" => install_format_hook()?, 48 "format-hook" => install_format_hook()?,
49 "fuzz-tests" => run_fuzzer()?,
45 _ => unreachable!(), 50 _ => unreachable!(),
46 } 51 }
47 Ok(()) 52 Ok(())