Skip to content

Commit

Permalink
feat: no restriction on what expression examples eval into
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyiam committed Feb 22, 2024
1 parent 3d9bb73 commit e458ca0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ Expression examples look like this:

````md
```nix
assert 1 + 1 == 2; null
let n = 1 + 1; in assert n == 2; n
```
````

They are nix expressions inside of fenced code blocks.
The first word in their info string is `nix`.
The expression is passed to Nix for evaluation as `nix eval --expr <EXPRESSION>`.
For future compatibility, to be considered passing,
it must successfully evaluate into `null`.
It is expected of the author to demonstrate and prove their points
using assertions.

Expand Down
14 changes: 0 additions & 14 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub(crate) mod expression_state;
pub(crate) mod repl_state;

use anyhow::bail;
use indoc::formatdoc;

use crate::{
example_id::ExampleId,
Expand Down Expand Up @@ -269,19 +268,6 @@ impl State {
bail!("{example_id}\n{stderr}")
}

if expression_output.stdout != b"null\n" {
let stdout = String::from_utf8_lossy(&expression_output.stdout);
let stdout = stdout.trim_end();

let message = formatdoc! {"
{example_id}
evaluated into non-null
note: examples must evaluate into null
value: {stdout}"};

bail!("{message}");
}

self.examples.remove(&example_id)?;

Ok(vec![self.eprintln(Self::fmt_pass(&example_id))])
Expand Down
33 changes: 8 additions & 25 deletions tests/expression.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod util;

use assert_fs::fixture::FileWriteStr;
use indoc::{formatdoc, indoc};
use indoc::indoc;
use predicates::{
prelude::PredicateBooleanExt,
str::{contains, starts_with},
Expand All @@ -27,42 +27,25 @@ fn assertion_fail() {
}

#[test]
fn fail_non_null() {
fn pass() {
with_eelco(|file, eelco| {
file.write_str(indoc! {"
```nix
0
null
```
"})
.unwrap();

let file_path = file.path().to_str().unwrap();

eelco.assert().failure().stderr(formatdoc! {"
Error: {file_path}:1
evaluated into non-null
note: examples must evaluate into null
value: 0
"});
});
}
#[test]
fn pass() {
with_eelco(|file, eelco| {
file.write_str(indoc! {"
```nix
null
0
```
"})
.unwrap();

let file_path = file.path().to_str().unwrap();

eelco
.assert()
.success()
.stderr(format!("PASS: {file_path}:1\n"));
eelco.assert().success().stderr(
predicates::str::contains(format!("PASS: {file_path}:1\n"))
.and(predicates::str::contains(format!("PASS: {file_path}:5\n"))),
);
});
}

Expand Down

0 comments on commit e458ca0

Please sign in to comment.