document throws, run alejandra
This commit is contained in:
parent
b800bb4695
commit
aeb174ac65
|
@ -18,6 +18,10 @@ Make a test file:
|
|||
actual = 2 + 2;
|
||||
expected = 5;
|
||||
})
|
||||
(it "throws a party" {
|
||||
actual = throw "a party";
|
||||
throws = true;
|
||||
})
|
||||
]
|
||||
```
|
||||
|
||||
|
|
24
flake.lock
Normal file
24
flake.lock
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1703013332,
|
||||
"narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=",
|
||||
"path": "/nix/store/50bgi74d890mpkp90w1jwc5g0dw4dccr-source",
|
||||
"rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
18
flake.nix
18
flake.nix
|
@ -1,10 +1,16 @@
|
|||
{
|
||||
description = "A testing library for nix";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
testing = import ./testing/. { inherit pkgs; };
|
||||
in testing;
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
}: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
tix = import ./testing/. {inherit pkgs;};
|
||||
in
|
||||
tix
|
||||
// {
|
||||
packages.x86_64-linux.test = tix.run [./mytest.nix];
|
||||
};
|
||||
}
|
||||
|
|
14
mytest.nix
Normal file
14
mytest.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{it, ...}: [
|
||||
(it "can add numbers" {
|
||||
actual = 2 + 2;
|
||||
expected = 4;
|
||||
})
|
||||
(it "loves big brother" {
|
||||
actual = 2 + 2;
|
||||
expected = 5;
|
||||
})
|
||||
(it "won't throw a party" {
|
||||
actual = "a party";
|
||||
throws = true;
|
||||
})
|
||||
]
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs ? import <nixpkgs> { } }: {
|
||||
{pkgs ? import <nixpkgs> {}}: {
|
||||
run = import ./run.nix pkgs;
|
||||
it = import ./it.nix;
|
||||
import = import ./import.nix;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
path:
|
||||
let it = import ./it.nix;
|
||||
in builtins.trace ("testing " + builtins.baseNameOf path) {
|
||||
inherit path;
|
||||
results = (import path { inherit it; });
|
||||
}
|
||||
path: let
|
||||
it = import ./it.nix;
|
||||
in
|
||||
builtins.trace ("testing " + builtins.baseNameOf path) {
|
||||
inherit path;
|
||||
results = import path {inherit it;};
|
||||
}
|
||||
|
|
|
@ -1,41 +1,51 @@
|
|||
msg:
|
||||
{ actual, expected ? { }, asString ? false, asJSON ? false
|
||||
, removeDunders ? false, safeToPrint ? true, throws ? false }:
|
||||
let
|
||||
msg: {
|
||||
actual,
|
||||
expected ? {},
|
||||
asString ? false,
|
||||
asJSON ? false,
|
||||
removeDunders ? false,
|
||||
safeToPrint ? true,
|
||||
throws ? false,
|
||||
}: let
|
||||
preProcess = v:
|
||||
if removeDunders then
|
||||
undunder v
|
||||
else if asString then
|
||||
toString v
|
||||
else if asJSON then
|
||||
builtins.toJSON v
|
||||
else
|
||||
v;
|
||||
if removeDunders
|
||||
then undunder v
|
||||
else if asString
|
||||
then toString v
|
||||
else if asJSON
|
||||
then builtins.toJSON v
|
||||
else v;
|
||||
|
||||
a = preProcess actual;
|
||||
e = preProcess expected;
|
||||
|
||||
undunder = v:
|
||||
if builtins.isAttrs v then
|
||||
builtins.removeAttrs v [ "__toString" "__functor" ]
|
||||
else
|
||||
v;
|
||||
if builtins.isAttrs v
|
||||
then builtins.removeAttrs v ["__toString" "__functor"]
|
||||
else v;
|
||||
|
||||
out = (if safeToPrint then
|
||||
builtins.toJSON (undunder (if throws then
|
||||
(builtins.tryEval actual).value
|
||||
else {
|
||||
inherit actual expected;
|
||||
}))
|
||||
else
|
||||
''{"msg": "cannot be stringified ):"}'');
|
||||
out =
|
||||
if safeToPrint
|
||||
then
|
||||
builtins.toJSON (undunder (
|
||||
if throws
|
||||
then (builtins.tryEval actual).value
|
||||
else {
|
||||
inherit actual expected;
|
||||
}
|
||||
))
|
||||
else ''{"msg": "cannot be stringified ):"}'';
|
||||
|
||||
success =
|
||||
if throws then (builtins.tryEval actual).success == false else (a == e);
|
||||
|
||||
in {
|
||||
inherit success msg;
|
||||
} // (if success then
|
||||
{ }
|
||||
else
|
||||
builtins.trace "FAILED ${msg}" { inherit actual expected; })
|
||||
if throws
|
||||
then (builtins.tryEval actual).success == false
|
||||
else (a == e);
|
||||
in
|
||||
{
|
||||
inherit success msg;
|
||||
}
|
||||
// (
|
||||
if success
|
||||
then {}
|
||||
else builtins.trace "FAILED ${msg}" {inherit actual expected;}
|
||||
)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pkgs: files:
|
||||
let
|
||||
pkgs: files: let
|
||||
test = import ./import.nix;
|
||||
res = map test files;
|
||||
resFile = builtins.toFile "results" (builtins.toJSON res);
|
||||
|
|
|
@ -7,4 +7,3 @@ pkgs.writeShellScriptBin "watch" ''
|
|||
pkill ${pname}
|
||||
done
|
||||
''
|
||||
|
||||
|
|
Loading…
Reference in a new issue