Skip to content

Commit

Permalink
feat: support skipping examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyiam committed Feb 21, 2024
1 parent 00fe399 commit 14d03a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ At the moment, expressions and assignments queries are supported.
A line that follows an expression query will be used as an assertion.
Blank lines matter. Even trailing ones.

Examples can be skipped by including the word `skip` in the info string.

The name eelco is in homage to the original author of Nix, Eelco Dolstra.
8 changes: 5 additions & 3 deletions src/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ pub(crate) fn obtain(glob: &str) -> anyhow::Result<Vec<Example>> {
let comrak::nodes::NodeCodeBlock { info, literal, .. } = code_block;
let line = ast.sourcepos.start.line;
let id = ExampleId::new(path, line);
let mut info_words = info.split_ascii_whitespace();

let maybe_result = match info.split_ascii_whitespace().next() {
Some(NIX_REPL_LANG_TAG) => {
let maybe_result = match (info_words.next(), info_words.contains(&"skip")) {
(_, true) => None,
(Some(NIX_REPL_LANG_TAG), _) => {
let repl_example =
ReplExample::try_new(id.clone(), literal.clone()).map(Example::Repl);
Some(repl_example)
}
Some("nix") => {
(Some("nix"), _) => {
let expression_example =
ExpressionExample::new(id.clone(), literal.clone());
Some(Ok(Example::Expression(expression_example)))
Expand Down
20 changes: 20 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ fn all_examples_tested() {
);
});
}

#[test]
fn skip() {
with_eelco(|file, eelco| {
file.write_str(indoc! {"
```nix skip
assert false; null
```
```nix foo skip
assert false; null
```
```nix
null
```
"})
.unwrap();

eelco.assert().success();
})
}

0 comments on commit 14d03a3

Please sign in to comment.