Skip to content

Commit

Permalink
fix: eprint example id when failing to parse it
Browse files Browse the repository at this point in the history
closes #88
  • Loading branch information
mightyiam committed Feb 21, 2024
1 parent c9ea57a commit 202e8ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::example_id::ExampleId;
use crate::expression::ExpressionExample;
use crate::repl::example::ReplExample;
use crate::repl::example::NIX_REPL_LANG_TAG;
use anyhow::Context;
use itertools::Itertools;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -38,18 +39,21 @@ pub(crate) fn obtain(glob: &str) -> anyhow::Result<Vec<Example>> {
let line = ast.sourcepos.start.line;
let id = ExampleId::new(path, line);

match info.split_ascii_whitespace().next() {
let maybe_result = match info.split_ascii_whitespace().next() {
Some(NIX_REPL_LANG_TAG) => {
let repl_example =
ReplExample::try_new(id, literal.clone()).map(Example::Repl);
ReplExample::try_new(id.clone(), literal.clone()).map(Example::Repl);
Some(repl_example)
}
Some("nix") => {
let expression_example = ExpressionExample::new(id, literal.clone());
let expression_example =
ExpressionExample::new(id.clone(), literal.clone());
Some(Ok(Example::Expression(expression_example)))
}
_ => None,
}
};

maybe_result.map(|result| result.context(format!("{id}")))
} else {
None
}
Expand Down
12 changes: 8 additions & 4 deletions tests/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod util;

use assert_fs::prelude::FileWriteStr;
use indoc::{formatdoc, indoc};
use predicates::boolean::PredicateBooleanExt;
use util::with_eelco;

#[test]
Expand All @@ -15,10 +16,13 @@ fn fails_to_parse() {
"})
.unwrap();

eelco
.assert()
.failure()
.stderr("Error: expected prompt, found LFLine(\"nix-shnepl> nope\\n\")\n");
let file_path = file.path().to_str().unwrap();

eelco.assert().failure().stderr(
predicates::str::starts_with(format!("Error: {file_path}:1")).and(
predicates::str::contains("expected prompt, found LFLine(\"nix-shnepl> nope\\n\")"),
),
);
});
}

Expand Down

0 comments on commit 202e8ef

Please sign in to comment.