You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should build a derivation which tests the wrapper derivation as best you can.
148
155
149
-
If a command fails, it fails the test. If it builds the derivation successfully, it passes the test.
156
+
We provide a testing library `tlib` that provides an easy-to-use interface to write tests.
150
157
151
-
If the program gives options for running the program to check the generated configuration is correct, you should do that.
158
+
### Writing Tests for Wrappers
152
159
153
-
Sometimes it is not easily possible to run the program within a derivation, in those cases, searching the wrapper derivation and other generated files and their contents is also acceptable.
160
+
If you are writing tests for a wrapper module, it is important to pass the name
161
+
of the wrapper to the first argument of the `test` function like in the example
162
+
below (marked at `(*)`). By doing this, we can grab the specified `wrapper.meta.platforms` config
163
+
of the wrapper (if any) and ensure that the tests are only run on the required platforms.
154
164
155
-
Example:
156
165
157
166
```nix
158
167
{
159
168
pkgs,
160
-
runCommand,
161
169
self,
170
+
tlib,
171
+
...
162
172
}:
173
+
163
174
let
164
-
gitWrapped = self.wrappers.git.wrap {
165
-
inherit pkgs;
166
-
settings = {
167
-
user = {
168
-
name = "Test User";
169
-
email = "test@example.com";
175
+
inherit (tlib)
176
+
fileContains
177
+
isDirectory
178
+
isFile
179
+
notIsFile
180
+
areEqual
181
+
test
182
+
;
183
+
in
184
+
test { wrapper = "direnv"; } { # <-- Specify the name of the wrapper here (*)
185
+
186
+
"direnv wrapper should be created" =
187
+
let
188
+
wrapper = self.wrappers.direnv.wrap {
189
+
inherit pkgs;
190
+
nix-direnv.enable = true;
170
191
};
171
-
};
192
+
in
193
+
[
194
+
"[[ -d ${wrapper} ]]" # <-- a simple condition to be asserted
195
+
{
196
+
cond = "[[ -d ${wrapper} ]]";
197
+
msg = "No directory found for wrapper."; # <-- you can also specify a custom error message
198
+
}
199
+
(isDirectory wrapper) # <-- or use pre-defined helpers
200
+
];
201
+
202
+
"wrapper should output correct version" =
203
+
let
204
+
wrapper = self.wrappers.direnv.wrap {
205
+
inherit pkgs;
206
+
};
207
+
in
208
+
'' # <-- no need to provide a list if there is only one assertion
209
+
"${wrapper}/bin/direnv" --version |
210
+
grep -q "${wrapper.version}"
211
+
'';
212
+
213
+
"math-tests" = { # <-- tests can be arbitrarily grouped
0 commit comments