aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/meson.build
blob: 9db619c5dea348eb9d2d7be41d68b5ad9612e093 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# NOTE(Qyriad): This file is one big slab of boilerplate.
# Lix's current unit test organization is scattered and entagled.
# Each of the test-support libraries could theoretically be a somewhat self-contained
# subdir(), but literally nothing else can. Each of the tests have dependencies on other
# test support libraries, and so do their support libraries.
# Each of the tests have dependencies on their own andother test support libraries,
# and so do their support libraries, and they have entangled dependencies on Lix's mainline
# lib* targets as well.
# The only boilerplate reduction I really could do here is throw everything in big nested dictionaries
# and dynamically generate and refer to targets based on abstracted specs, but without user-defined
# functions, the result would be way less readable than just a bit of copypasta.
# It's only ~200 lines; better to just refactor the tests themselves which we'll want to do anyway.

default_test_env = {
  'ASAN_OPTIONS': 'detect_leaks=0:halt_on_error=1:abort_on_error=1:print_summary=1:dump_instruction_bytes=1',
  # Prevents loading global configuration file in /etc/nix/nix.conf in tests 😱
  'NIX_CONF_DIR': '/var/empty',
  # Prevent loading user configuration files in tests
  'NIX_USER_CONF_FILES': '',
}

libutil_test_support_sources = files(
  'libutil-support/tests/cli-literate-parser.cc',
  'libutil-support/tests/hash.cc',
  'libutil-support/tests/terminal-code-eater.cc',
  'libutil-support/tests/test-data.cc',
)
libutil_test_support = library(
  'lixutil-test-support',
  libutil_test_support_sources,
  dependencies : [
    liblixutil,
    # TODO(Qyriad): libutil tests really should not depend on libexpr...
    liblixexpr,
    rapidcheck,
    boehm,
  ],
  include_directories : include_directories('libutil-support', '../../src'),
)
liblixutil_test_support = declare_dependency(
  include_directories : include_directories('libutil-support'),
  link_with : libutil_test_support,
)

libutil_tests_sources = files(
  'libutil/async-collect.cc',
  'libutil/async-semaphore.cc',
  'libutil/canon-path.cc',
  'libutil/checked-arithmetic.cc',
  'libutil/chunked-vector.cc',
  'libutil/closure.cc',
  'libutil/compression.cc',
  'libutil/config.cc',
  'libutil/escape-string.cc',
  'libutil/generator.cc',
  'libutil/git.cc',
  'libutil/hash.cc',
  'libutil/hilite.cc',
  'libutil/json-utils.cc',
  'libutil/logging.cc',
  'libutil/lru-cache.cc',
  'libutil/paths-setting.cc',
  'libutil/pool.cc',
  'libutil/references.cc',
  'libutil/serialise.cc',
  'libutil/suggestions.cc',
  'libutil/tests.cc',
  'libutil/url.cc',
  'libutil/url-name.cc',
  'libutil/xml-writer.cc',
)

libutil_tester = executable(
  'liblixutil-tests',
  libutil_tests_sources,
  dependencies : [
    libasanoptions,
    rapidcheck,
    gtest,
    boehm,
    liblixutil,
    liblixexpr_mstatic,
    liblixutil_test_support,
    nlohmann_json,
    kj,
  ],
  cpp_pch : cpp_pch,
)

test(
  'libutil-unit-tests',
  libutil_tester,
  args : tests_args,
  env : default_test_env + {
    '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libutil/data',
  },
  suite : 'check',
  protocol : 'gtest',
  verbose : true,
)

libstore_test_support_sources = files(
  'libstore-support/tests/derived-path.cc',
  'libstore-support/tests/outputs-spec.cc',
  'libstore-support/tests/path.cc',
)

libstore_test_support = library(
  'lixstore-test-support',
  libstore_test_support_sources,
  dependencies : [
    liblixutil_test_support,
    liblixutil,
    liblixstore,
    rapidcheck,
    boehm,
  ],
  include_directories : include_directories(
    'libstore-support',
  ),
  cpp_pch : cpp_pch,
)
liblixstore_test_support = declare_dependency(
  include_directories : include_directories('libstore-support'),
  link_with : libstore_test_support,
)

libstore_tests_sources = files(
  'libstore/common-protocol.cc',
  'libstore/derivation.cc',
  'libstore/derived-path.cc',
  'libstore/downstream-placeholder.cc',
  'libstore/filetransfer.cc',
  'libstore/machines.cc',
  'libstore/nar-info-disk-cache.cc',
  'libstore/outputs-spec.cc',
  'libstore/path.cc',
  'libstore/references.cc',
  'libstore/serve-protocol.cc',
  'libstore/worker-protocol.cc',
)

libstore_tester = executable(
  'liblixstore-tests',
  libstore_tests_sources,
  dependencies : [
    libasanoptions,
    liblixstore_test_support,
    liblixutil_test_support,
    liblixstore_mstatic,
    liblixutil,
    rapidcheck,
    gtest,
    nlohmann_json,
  ],
  cpp_pch : cpp_pch,
)

test(
  'libstore-unit-tests',
  libstore_tester,
  args : tests_args,
  env : default_test_env + {
    '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libstore/data',
  },
  suite : 'check',
  protocol : 'gtest',
  verbose : true,
)

libexpr_test_support_sources = files(
  'libexpr-support/tests/value/context.cc',
)

libexpr_test_support = library(
  'lixexpr-test-support',
  libexpr_test_support_sources,
  dependencies : [
    liblixstore_test_support,
    liblixstore,
    liblixutil,
    liblixexpr,
    rapidcheck,
  ],
  include_directories : include_directories(
    'libexpr-support',
  ),
  cpp_pch : cpp_pch,
)
liblixexpr_test_support = declare_dependency(
  include_directories : include_directories('libexpr-support'),
  link_with : libexpr_test_support,
)

libexpr_tests_sources = files(
  'libexpr/derived-path.cc',
  'libexpr/error_traces.cc',
  'libexpr/flakeref.cc',
  'libexpr/json.cc',
  'libexpr/primops.cc',
  'libexpr/search-path.cc',
  'libexpr/trivial.cc',
  'libexpr/expr-print.cc',
  'libexpr/value/context.cc',
  'libexpr/value/print.cc',
)

libexpr_tester = executable(
  'liblixexpr-tests',
  libexpr_tests_sources,
  dependencies : [
    libasanoptions,
    liblixexpr_test_support,
    liblixstore_test_support,
    liblixstore_mstatic,
    liblixutil,
    liblixexpr_mstatic,
    liblixfetchers_mstatic,
    rapidcheck,
    boehm,
    gtest,
    nlohmann_json,
  ],
  cpp_pch : cpp_pch,
)

test(
  'libexpr-unit-tests',
  libexpr_tester,
  args : tests_args,
  env : default_test_env + {
    '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libexpr/data',
  },
  suite : 'check',
  protocol : 'gtest',
  verbose : true,
)

libcmd_tester = executable(
  'liblixcmd-tests',
  files('libcmd/args.cc'),
  dependencies : [
    libasanoptions,
    liblixcmd,
    liblixutil,
    liblixmain,
    liblixexpr_mstatic,
    liblixstore_mstatic,
    gtest,
    boost,
  ],
  cpp_pch : cpp_pch,
)

test(
  'libcmd-unit-tests',
  libcmd_tester,
  args : tests_args,
  env : default_test_env + {
    # No special meaning here, it's just a file laying around that is unlikely to go anywhere
    # any time soon.
    '_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'src/legacy/buildenv.nix',
    # Use a temporary home directory for the unit tests.
    # Otherwise, /homeless-shelter is created in the single-user sandbox, and functional tests will fail.
    # TODO(alois31): handle TMPDIR properly (meson can't, and setting HOME in the test is too late)…
    'HOME': '/tmp/nix-test/libcmd-unit-tests',
  },
  suite : 'check',
  protocol : 'gtest',
)

libmain_tests_sources = files(
  'libmain/crash.cc',
  'libmain/progress-bar.cc',
)

libmain_tester = executable(
  'liblixmain-tests',
  libmain_tests_sources,
  dependencies : [
    liblixmain,
    liblixexpr,
    liblixutil,
    liblixstore,
    gtest,
    boost,
  ],
  cpp_pch : cpp_pch,
)

test(
  'libmain-unit-tests',
  libmain_tester,
  args : tests_args,
  env : default_test_env,
  suite : 'check',
  protocol : 'gtest',
)