Skip to content

Commit 2a6a4fd

Browse files
committed
Inline parse_comments method
1 parent a415574 commit 2a6a4fd

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/lib.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,12 @@ fn parse_and_test_file(
374374
mut config: Config,
375375
file_contents: Vec<u8>,
376376
) -> Result<Vec<TestRun>, Errored> {
377-
let comments = parse_comments(
377+
let comments = Comments::parse(
378378
&file_contents,
379379
config.comment_defaults.clone(),
380380
status.path(),
381-
)?;
381+
)
382+
.map_err(|errors| Errored::new(errors, "parse comments"))?;
382383
const EMPTY: &[String] = &[String::new()];
383384
// Run the test for all revisions
384385
let revisions = comments.revisions.as_deref().unwrap_or(EMPTY);
@@ -416,22 +417,6 @@ fn parse_and_test_file(
416417
.collect())
417418
}
418419

419-
fn parse_comments(
420-
file_contents: &[u8],
421-
comments: Comments,
422-
file: &Path,
423-
) -> Result<Comments, Errored> {
424-
match Comments::parse(file_contents, comments, file) {
425-
Ok(comments) => Ok(comments),
426-
Err(errors) => Err(Errored {
427-
command: Command::new("parse comments"),
428-
errors,
429-
stderr: vec![],
430-
stdout: vec![],
431-
}),
432-
}
433-
}
434-
435420
fn build_command(
436421
path: &Path,
437422
config: &Config,
@@ -488,7 +473,8 @@ fn build_aux(
488473
stderr: err.to_string().into_bytes(),
489474
stdout: vec![],
490475
})?;
491-
let comments = parse_comments(&file_contents, config.comment_defaults.clone(), aux_file)?;
476+
let comments = Comments::parse(&file_contents, config.comment_defaults.clone(), aux_file)
477+
.map_err(|errors| Errored::new(errors, "parse aux comments"))?;
492478
assert_eq!(
493479
comments.revisions, None,
494480
"aux builds cannot specify revisions"

src/test_result.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ pub struct Errored {
2828
pub(crate) stdout: Vec<u8>,
2929
}
3030

31+
impl Errored {
32+
/// If no command was executed for this error, use a message instead.
33+
pub fn new(errors: Vec<Error>, message: &str) -> Self {
34+
Self {
35+
errors,
36+
stderr: vec![],
37+
stdout: vec![],
38+
command: Command::new(message),
39+
}
40+
}
41+
}
42+
3143
pub(crate) struct TestRun {
3244
pub(crate) result: TestResult,
3345
pub(crate) status: Box<dyn TestStatus>,

0 commit comments

Comments
 (0)