1with builtins;
2let
3 /*
4 underTest = {
5 x = {
6 a = 1;
7 b = "2";
8 };
9 };
10
11 tests = [
12 (root: false)
13 {
14 x = [
15 (set: true)
16 {
17 a = (a: a > 1);
18 b = (b: b == "3");
19 }
20 ];
21 }
22 ];
23
24 results = run "Examples" underTest tests;
25 */
26
27 passed = desc: {
28 result = "pass";
29 description = desc;
30 };
31
32 failed = desc: {
33 result = "failed";
34 description = desc;
35 };
36
37 prefixName = name: res: {
38 inherit (res) result;
39 description = "${name}: ${res.description}";
40 };
41
42 run =
43 name: under: tests:
44 if isList tests then
45 (concatLists (map (run name under) tests))
46 else if isAttrs tests then
47 (concatLists (
48 map (
49 subName:
50 run (name + "." + subName) (if hasAttr subName under then getAttr subName under else "<MISSING!>") (
51 getAttr subName tests
52 )
53 ) (attrNames tests)
54 ))
55 else if isFunction tests then
56 let
57 res = tests under;
58 in
59 if isBool res then
60 [
61 (prefixName name (if tests under then passed "passed" else failed "failed"))
62 ]
63 else
64 [ (prefixName name res) ]
65 else
66 [
67 failed
68 (name ": not a function, list or set")
69 ];
70in
71{
72 inherit run passed failed;
73}