Skip to content

Commit 68fc63e

Browse files
committed
chore: Update Schemathesis stdout parser
1 parent 516eecd commit 68fc63e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

postprocessing/src/fuzzers/schemathesis.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub(crate) enum Status {
4949
Success,
5050
/// Schemathesis found some failures.
5151
Failure,
52+
Skip,
5253
/// Internal Schemathesis error.
5354
Error,
5455
}
@@ -198,6 +199,10 @@ struct StdoutEntry<'a> {
198199
failures: HashMap<&'static str, u16>,
199200
}
200201

202+
const HTTP_METHODS: &[&str] = &[
203+
"GET ", "PUT ", "POST ", "DELETE ", "OPTIONS ", "HEAD ", "PATCH ", "TRACE ",
204+
];
205+
201206
pub(crate) fn get_deduplicated_results(directory: &Path, out_directory: &PathBuf) {
202207
let path = directory.join("stdout.txt");
203208
let content = read_to_string(path).expect("Failed to read stdout.txt");
@@ -206,9 +211,13 @@ pub(crate) fn get_deduplicated_results(directory: &Path, out_directory: &PathBuf
206211
}
207212
let mut lines = content
208213
.lines()
214+
.skip_while(|line| line.trim() != "FAILURES")
209215
.filter_map(|l| {
210216
let trimmed = l.trim();
211-
if trimmed.ends_with("[P]") || trimmed.ends_with("[N]") || STDOUT_FAILURE_RE.is_match(l)
217+
if HTTP_METHODS
218+
.iter()
219+
.any(|method| trimmed.starts_with(method))
220+
|| STDOUT_FAILURE_RE.is_match(l)
212221
{
213222
Some(trimmed)
214223
} else {
@@ -221,7 +230,11 @@ pub(crate) fn get_deduplicated_results(directory: &Path, out_directory: &PathBuf
221230
let mut ser = serde_json::Serializer::new(output_file);
222231
let mut seq = ser.serialize_seq(None).unwrap();
223232
while let Some(line) = lines.next() {
224-
if line.ends_with("[P]") || line.ends_with("[N]") {
233+
let trimmed = line.trim();
234+
if HTTP_METHODS
235+
.iter()
236+
.any(|method| trimmed.starts_with(method))
237+
{
225238
// New endpoint
226239
let mut parts = line.split_ascii_whitespace();
227240
let method = parts.next().unwrap();
@@ -251,10 +264,10 @@ pub(crate) fn get_deduplicated_results(directory: &Path, out_directory: &PathBuf
251264
} else if UNEXPECTED_CONTENT_TYPE.captures(next).is_some() {
252265
seq.serialize_element(&TestCase::content_type_conformance(method, path))
253266
.unwrap();
254-
} else if next.contains("Response is missing the `Content-Type` header") {
267+
} else if next.contains("response is missing the `Content-Type` header") {
255268
seq.serialize_element(&TestCase::missing_content_type(method, path))
256269
.unwrap();
257-
} else if next.contains("Malformed media type") {
270+
} else if next.contains("malformed media type") {
258271
seq.serialize_element(&TestCase::malformed_media_type(method, path))
259272
.unwrap();
260273
} else {

0 commit comments

Comments
 (0)