aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/fuzz/Cargo.toml8
-rw-r--r--crates/ra_syntax/fuzz/fuzz_targets/parser.rs6
-rw-r--r--crates/ra_syntax/src/fuzz.rs12
-rw-r--r--crates/ra_syntax/src/lib.rs9
-rw-r--r--crates/ra_syntax/tests/test.rs4
5 files changed, 23 insertions, 16 deletions
diff --git a/crates/ra_syntax/fuzz/Cargo.toml b/crates/ra_syntax/fuzz/Cargo.toml
index 4a255882e..c54d12813 100644
--- a/crates/ra_syntax/fuzz/Cargo.toml
+++ b/crates/ra_syntax/fuzz/Cargo.toml
@@ -4,14 +4,14 @@ name = "ra_syntax-fuzz"
4version = "0.0.1" 4version = "0.0.1"
5authors = ["rust-analyzer developers"] 5authors = ["rust-analyzer developers"]
6publish = false 6publish = false
7edition = "2018"
7 8
8[package.metadata] 9[package.metadata]
9cargo-fuzz = true 10cargo-fuzz = true
10 11
11[dependencies.ra_syntax] 12[dependencies]
12path = ".." 13ra_syntax = { path = ".." }
13[dependencies.libfuzzer-sys] 14libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
14git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
15 15
16# Prevent this from interfering with workspaces 16# Prevent this from interfering with workspaces
17[workspace] 17[workspace]
diff --git a/crates/ra_syntax/fuzz/fuzz_targets/parser.rs b/crates/ra_syntax/fuzz/fuzz_targets/parser.rs
index 4667d5579..76a8b08d0 100644
--- a/crates/ra_syntax/fuzz/fuzz_targets/parser.rs
+++ b/crates/ra_syntax/fuzz/fuzz_targets/parser.rs
@@ -1,9 +1,9 @@
1#![no_main] 1#![no_main]
2#[macro_use] extern crate libfuzzer_sys; 2use libfuzzer_sys::fuzz_target;
3extern crate ra_syntax; 3use ra_syntax::fuzz::check_parser;
4 4
5fuzz_target!(|data: &[u8]| { 5fuzz_target!(|data: &[u8]| {
6 if let Ok(text) = std::str::from_utf8(data) { 6 if let Ok(text) = std::str::from_utf8(data) {
7 ra_syntax::check_fuzz_invariants(text) 7 check_parser(text)
8 } 8 }
9}); 9});
diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs
new file mode 100644
index 000000000..03f453a6e
--- /dev/null
+++ b/crates/ra_syntax/src/fuzz.rs
@@ -0,0 +1,12 @@
1use crate::{SourceFile, validation, AstNode};
2
3fn check_file_invariants(file: &SourceFile) {
4 let root = file.syntax();
5 validation::validate_block_structure(root);
6 let _ = file.errors();
7}
8
9pub fn check_parser(text: &str) {
10 let file = SourceFile::parse(text);
11 check_file_invariants(&file);
12}
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs
index 7334d53ef..4f3020440 100644
--- a/crates/ra_syntax/src/lib.rs
+++ b/crates/ra_syntax/src/lib.rs
@@ -29,6 +29,8 @@ mod ptr;
29 29
30pub mod algo; 30pub mod algo;
31pub mod ast; 31pub mod ast;
32#[doc(hidden)]
33pub mod fuzz;
32 34
33pub use rowan::{SmolStr, TextRange, TextUnit}; 35pub use rowan::{SmolStr, TextRange, TextUnit};
34pub use ra_parser::SyntaxKind; 36pub use ra_parser::SyntaxKind;
@@ -83,13 +85,6 @@ impl SourceFile {
83 } 85 }
84} 86}
85 87
86pub fn check_fuzz_invariants(text: &str) {
87 let file = SourceFile::parse(text);
88 let root = file.syntax();
89 validation::validate_block_structure(root);
90 let _ = file.errors();
91}
92
93/// This test does not assert anything and instead just shows off the crate's 88/// This test does not assert anything and instead just shows off the crate's
94/// API. 89/// API.
95#[test] 90#[test]
diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs
index 458740c13..3de4a65af 100644
--- a/crates/ra_syntax/tests/test.rs
+++ b/crates/ra_syntax/tests/test.rs
@@ -8,7 +8,7 @@ use std::{
8}; 8};
9 9
10use test_utils::{project_dir, dir_tests, read_text, collect_tests}; 10use test_utils::{project_dir, dir_tests, read_text, collect_tests};
11use ra_syntax::{SourceFile, AstNode, check_fuzz_invariants}; 11use ra_syntax::{SourceFile, AstNode, fuzz};
12 12
13#[test] 13#[test]
14fn lexer_tests() { 14fn lexer_tests() {
@@ -47,7 +47,7 @@ fn parser_tests() {
47#[test] 47#[test]
48fn parser_fuzz_tests() { 48fn parser_fuzz_tests() {
49 for (_, text) in collect_tests(&test_data_dir(), &["parser/fuzz-failures"]) { 49 for (_, text) in collect_tests(&test_data_dir(), &["parser/fuzz-failures"]) {
50 check_fuzz_invariants(&text) 50 fuzz::check_parser(&text)
51 } 51 }
52} 52}
53 53