This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.test.nix
109 lines (98 loc) · 2.85 KB
/
default.test.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
let
lib = import ./default.nix;
root = ./.;
files = [
./src/default.test.nix
./src/attrs/default.test.nix
./src/bools/default.test.nix
./src/dag/default.test.nix
./src/errors/default.test.nix
./src/fp/default.test.nix
./src/generators/default.test.nix
./src/importers/default.test.nix
./src/lists/default.test.nix
./src/math/default.test.nix
./src/modules/default.test.nix
./src/numbers/default.test.nix
./src/options/default.test.nix
./src/packages/default.test.nix
./src/paths/default.test.nix
./src/points/default.test.nix
./src/strings/default.test.nix
./src/types/default.test.nix
./src/versions/default.test.nix
];
resolve = file: let
imported = import file;
value =
if builtins.isFunction imported
then imported {inherit lib;}
else imported;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in {
inherit file value;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
namespace = getNamespace file;
};
resolved = builtins.map resolve files;
getNamespace = path: let
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
parts = lib.strings.split "/" relative;
in
if builtins.length parts > 2
then builtins.elemAt parts 2
else relative;
results = let
getTests = file: prefix: suite: let
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [name]) value) suite;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in
if builtins.isAttrs suite
then builtins.concatLists nested
else [
{
inherit prefix file;
name = builtins.concatStringsSep " > " prefix;
value = suite;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
}
];
base =
builtins.map (entry: getTests entry.file [entry.namespace] entry.value) resolved;
in
builtins.concatLists base;
successes = builtins.filter (test: test.value) results;
failures = builtins.filter (test: !test.value) results;
total = "${builtins.toString (builtins.length successes)} / ${builtins.toString (builtins.length results)}";
in
if failures == []
then let
message =
lib.strings.concatMapSep "\n"
(test: "✅ ${test.name}")
successes;
in ''
SUCCESS (${total})
${message}
''
else let
successMessage =
lib.strings.concatMapSep "\n"
(test: "✅ ${test.name}")
successes;
failureMessage =
lib.strings.concatMapSep "\n\n"
(test:
"❎ ${test.name}\n"
+ " -> ${test.relative}")
failures;
in ''
FAILURE (${total})
${failureMessage}
''