Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value not must be null #98

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading