document throws, run alejandra

This commit is contained in:
tristan 2024-01-02 11:13:47 +00:00
parent b800bb4695
commit aeb174ac65
9 changed files with 105 additions and 48 deletions

View file

@ -1,4 +1,4 @@
{ pkgs ? import <nixpkgs> { } }: {
{pkgs ? import <nixpkgs> {}}: {
run = import ./run.nix pkgs;
it = import ./it.nix;
import = import ./import.nix;

View file

@ -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;};
}

View file

@ -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;}
)

View file

@ -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);

View file

@ -7,4 +7,3 @@ pkgs.writeShellScriptBin "watch" ''
pkill ${pname}
done
''