-
Notifications
You must be signed in to change notification settings - Fork 2
/
project.test.yaml
771 lines (683 loc) · 18.3 KB
/
project.test.yaml
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
empty:
# With no files at all, maud will still configure a viable build
- maud --log-level=VERBOSE
hello world:
- write: hello.cxx
contents: |
#include <iostream>
import executable;
int main() {
std::cout << "hello world!" << std::endl;
}
- cmake -E echo ----------
- maud --quiet
auto add sources:
- write: foo.cxx
contents: |
export module foo;
export int foo() { return 0; }
- maud --log-level=VERBOSE
- write: bar.cxx
contents: |
export module bar;
export int bar() { return 0; }
- cmake --build .build --config Debug
- exists: .build/Debug/libbar.a
- write: bar.cxx
contents: |
export module bar2;
export int bar() { return 0; }
- cmake --build .build --config Debug
- exists: .build/Debug/libbar2.a
std lib:
- write: std_.cxx
contents: |
module;
#include <string>
#include <vector>
// Technically not reserved since it doesn't match ^std[0-9]*$
export module std_;
namespace std {
export using std::string;
export using std::vector;
}
- write: bar.cxx
contents: |
import executable;
import std_;
int main() {
std::vector<std::string> s;
return 0;
}
- maud --log-level=VERBOSE
glob benchmark:
- write: benchmark.cmake
contents: |
_maud_set(N 7)
_maud_set(F 8)
if($ENV{MAUD_APPROX_LLVM_PROJECT})
_maud_set(F 19)
endif()
find_program(FD NAMES fd)
find_program(GIT NAMES git)
set(files)
foreach(i RANGE ${F})
foreach(j RANGE ${F})
foreach(k RANGE ${F})
foreach(l RANGE ${F})
list(APPEND files "${i}/${j}/${k}/${l}")
endforeach()
endforeach()
endforeach()
endforeach()
_maud_set(files ${files})
add_custom_target(
benchmark ALL
COMMAND
"${CMAKE_COMMAND}"
-P "${MAUD_DIR}/eval.cmake"
-- "include(Time)"
COMMAND_EXPAND_LISTS
VERBATIM
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
- write: cmake_modules/Time.cmake
contents: |
message(STATUS "\n\nBENCHMARK")
function(time code)
set(sum 0)
set(min 9999999999)
cmake_language(
EVAL CODE
"
foreach(i RANGE ${N})
string(TIMESTAMP before [[%s%f]])
${code}
string(TIMESTAMP d [[%s%f]])
math_assign(d - \${before})
math_assign(sum + \${d})
if(min GREATER d)
set(min \${d})
endif()
endforeach()
"
)
math(EXPR mean "${sum} / (${N} + 1)")
string(REGEX REPLACE "(...)$" ".\\1" mean ${mean})
math(EXPR min "${min}")
string(REGEX REPLACE "(...)$" ".\\1" min ${min})
set(delta_ms "( mean=${mean}\tmin=${min}\t) " PARENT_SCOPE)
endfunction()
time([[
foreach(f ${files})
file(WRITE "${f}" "")
endforeach()
]])
message(STATUS "\tWriting: ${delta_ms}ms")
time([[
foreach(f ${files})
if("${f}" IS_NEWER_THAN "${f}")
endif()
endforeach()
]])
message(STATUS "\tNew checking: ${delta_ms}ms")
time([[
file(
GLOB_RECURSE _
LIST_DIRECTORIES true
RELATIVE "${CMAKE_SOURCE_DIR}"
"*"
)
list(FILTER _ EXCLUDE REGEX "(^|/)\\.")
]])
message(STATUS "\tGlobbing: ${delta_ms}ms")
if(FD)
time([[
execute_process(
COMMAND cmake -E chdir "${CMAKE_SOURCE_DIR}" "${FD}" -I
OUTPUT_VARIABLE _
)
string(STRIP "${_}" _)
string(REGEX REPLACE "/?\n" ";" _ "${_}")
]])
else()
set(delta_ms fd-NOTFOUND)
endif()
message(STATUS "\tGlobbing(fd): ${delta_ms}ms")
if(GIT)
time([[
execute_process(
COMMAND "${GIT}" -C "${CMAKE_SOURCE_DIR}"
ls-files --exclude-standard --ignored --others
OUTPUT_VARIABLE _
)
string(STRIP "${_}" _)
string(REGEX REPLACE "/?\n" ";" _ "${_}")
]])
else()
set(delta_ms git-NOTFOUND)
endif()
message(STATUS "\tGlobbing(git): ${delta_ms}ms")
time([[
list(FILTER files INCLUDE REGEX ".*")
list(FILTER files EXCLUDE REGEX "(^|/)\\.")
]])
message(STATUS "\tFiltering: ${delta_ms}ms")
time([[
_maud_load_cache("${CMAKE_BINARY_DIR}")
]])
message(STATUS "\tLoading the cache: ${delta_ms}ms")
list(LENGTH files count)
math(EXPR N "${N} + 1")
message(STATUS "\n ${N} iterations with ${count} files")
- maud
unit testing:
- write: basics.cxx
contents: |
#include <string>
import test_;
TEST_(DISABLED_failing) {
EXPECT_(false);
}
TEST_(basic) {
int three = 3, five = 5;
EXPECT_(three != five);
EXPECT_(67 > five);
EXPECT_(three);
EXPECT_(not std::false_type{});
int a = 999, b = 88888;
EXPECT_(a != b);
int *ptr = &three;
if (not EXPECT_(ptr != nullptr)) return;
EXPECT_(*ptr == three);
EXPECT_("hello world" >>= HasSubstr("llo"));
}
Matcher IsEven{
.match = [](auto n, auto &) { return n % 2 == 0; },
.description = [](auto &os, bool negated) {
os << (negated ? "isn't" : "is") << " even";
},
};
TEST_(custom_matcher) {
int i = 3;
EXPECT_(i >>= Not(IsEven));
}
TEST_(parameterized, {111, 234}) {
EXPECT_(parameter == parameter);
}
TEST_(typed, std::tuple{0, std::string("")}) {
EXPECT_(parameter + parameter == parameter);
}
- maud
- ctest --test-dir .build --output-on-failure -C Debug
# Assert that the test executable exists but isn't installed
- cmake --install .build --prefix ../usr --config Debug
- exists: .build/Debug/test_.basics
- does not exist: ../usr/bin/test_.basics
disabling unit testing:
- write: inline_python.test.cxx
contents: |
import test_;
TEST_(inline_python) {
def foo():
assert 1 == 0
}
- maud -DBUILD_TESTING=OFF
internal unit testing:
- write: foo.cxx
contents: |
export module foo:interface;
// not exported!
int foo_internal() { return 3; }
- write: internal.test.cxx
contents: |
module foo:some_test;
import :interface;
import test_;
TEST_(can_access_internal) {
EXPECT_(foo_internal() == 3);
}
- maud --log-level=VERBOSE
unit testing main:
- write: test_main.cxx
contents: |
module;
#include <gtest/gtest.h>
export module test_:main;
export int foo;
int main(int argc, char* argv[]) {
foo = 999;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
- write: foo.cxx
contents: |
import test_;
TEST_(check_foo_is_999) {
EXPECT_(foo == 999);
}
- maud --log-level=VERBOSE
- ctest --test-dir .build --output-on-failure -C Debug
custom unit testing:
- write: one_equals_three.test.cxx
contents: |
import test_;
int main() {
expect_eq(1, 3);
}
- write: .test_.cxx
contents: |
module;
#include <iostream>
export module test_;
export void expect_eq(auto const &l, auto const &r) {
if (l != r) std::cerr << "failed: " << l << "==" << r << std::endl;
}
- write: test.cmake
contents: |
function(maud_add_test source_file out_target_name)
cmake_path(GET source_file STEM name)
set(${out_target_name} "test_.${name}" PARENT_SCOPE)
add_executable(test_.${name})
add_test(NAME test_.${name} COMMAND $<TARGET_FILE:test_.${name}>)
target_sources(
test_.${name}
PRIVATE FILE_SET module_providers TYPE CXX_MODULES
BASE_DIRS ${CMAKE_SOURCE_DIR} FILES .test_.cxx
)
endfunction()
- maud --log-level=VERBOSE
import installed:
- write: foo/foo.cxx
contents: |
export module foo;
export int foo() { return 0; }
- command: maud --log-level=VERBOSE
working directory: foo
- cmake --install foo/.build --prefix ../usr --config Debug
- write: use/use.cxx
contents: |
import executable;
import foo;
int main() { return foo(); }
- command: maud --log-level=VERBOSE
working directory: use
DISABLED_import installed with options:
- write: fmt_42/fmt_42.cxx
contents: |
module;
#include <fmt/format.h>
export module fmt_42;
export std::string fmt_42() { return fmt::format("{}", 42); }
- write: fmt_42/fmt_42.cmake
contents: |
find_package(fmt REQUIRED)
add_library(fmt_42)
target_link_libraries(fmt_42 INTERFACE fmt::fmt)
get_target_property(d fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
set(options " ${CMAKE_INCLUDE_SYSTEM_FLAG_CXX} ${d} ")
set_source_files_properties(
"${dir}/fmt_42.cxx"
PROPERTIES
MAUD_PREPROCESSING_SCAN_OPTIONS "${options}"
)
- command: maud --log-level=VERBOSE
working directory: fmt_42
- cmake --install fmt_42/.build --prefix ../usr --config Debug
- write: use/use.cxx
contents: |
import executable;
import fmt_42;
int main() { return fmt_42().size(); }
- command: maud --log-level=VERBOSE
working directory: use
# This fails because the installed export doesn't include a
# call to find_package(fmt):
#
# CMake Error at /home/ben/maud/tools/.build/_maud/test_projects/usr/lib/cmake/fmt_42.maud-config.cmake:60 (set_target_properties):
# The link interface of target "fmt_42" contains:
#
# fmt::fmt
auto primary interface:
- write: foo_a.cxx
contents: |
export module foo:a;
export int a() { return 0; }
- write: foo_b.cxx
contents: |
export module foo:b;
import :a;
export int b() { return 0; }
- write: use.cxx
contents: |
import executable;
import foo;
int main() { return a() + b(); }
- maud --log-level=VERBOSE
rendered in2 source:
- write: render_foo.cmake
contents: |
file(
WRITE "${MAUD_DIR}/rendered/foo.cxx"
[[
export module foo;
import bar;
static_assert(BOOL);
static_assert(sizeof(INTS) == sizeof(int) * 11);
]]
)
- write: bar.cxx.in2
contents: |
export module bar;
export int INTS[] = {@
foreach(i RANGE 10)
render("${i},")
endforeach()
@};
export bool constexpr BOOL = @MAUD_DIR | if_else(1 0)@;
- maud
- exists: .build/Debug/libfoo.a
- exists: .build/Debug/libbar.a
use find_package:
- write: use_json_fmt.cxx
contents: |
#include <fmt/format.h>
#include <nlohmann/json.hpp>
import executable;
int main() {}
- write: use_json_fmt.cmake
contents: |
find_package(nlohmann_json REQUIRED)
find_package(fmt REQUIRED)
add_executable(use_json_fmt)
target_link_libraries(
use_json_fmt
PRIVATE
nlohmann_json::nlohmann_json
fmt::fmt-header-only
)
set(options "-DFMT_HEADER_ONLY=1")
foreach(target fmt::fmt-header-only nlohmann_json::nlohmann_json)
get_target_property(i ${target} INTERFACE_INCLUDE_DIRECTORIES)
foreach(d ${i})
string(APPEND options " ${CMAKE_INCLUDE_SYSTEM_FLAG_CXX} ${d}")
endforeach()
endforeach()
set_source_files_properties(
"${dir}/use_json_fmt.cxx"
PROPERTIES
MAUD_PREPROCESSING_SCAN_OPTIONS "${options}"
)
- maud
c++17 project:
- write: src/src-y.cxx
contents: |
int main() {}
- write: explicit_targets.cmake
contents: |
set(CMAKE_CXX_STANDARD 17)
glob(SRCS CONFIGURE_DEPENDS "src/.*[.]cxx$")
add_executable(hello ${SRCS})
- maud --log-level=VERBOSE
- exists: .build/Debug/hello
c++23 project:
- write: fib.cxx
contents: |
export module fib;
auto fib = [](this auto const &self, int i) {
if (i <= 1) return i;
return self(i - 1) + self(i - 2);
};
- write: cxx23.cmake
contents: |
set(CMAKE_CXX_STANDARD 23)
- maud --log-level=VERBOSE
- exists: .build/Debug/libfib.a
internal decl:
- write: foo_primary.cxx
contents: |
export module foo;
export import :part;
- write: foo_part.cxx
contents: |
export module foo:part;
export int foo();
export int foo_half();
int foo_internal(); // not exported, but usable within module foo
- write: foo_impl.cxx
contents: |
module foo;
import :part;
int foo() { return foo_internal(); }
- write: foo_half_impl.cxx
contents: |
module foo:half_impl;
import :part;
int foo_half() { return foo_internal() / 2; }
- write: foo_internal_impl.cxx
contents: |
module foo;
int foo_internal() { return 3; }
- maud
internal decl no parts:
- write: foo_primary.cxx
contents: |
export module foo;
export int foo();
int foo_internal(); // not exported, but usable within module foo
- write: foo_impl.cxx
contents: |
module foo;
int foo() { return foo_internal(); }
- write: foo_internal_impl.cxx
contents: |
module foo;
int foo_internal() { return 3; }
- maud
internal decl faux parts:
- write: foo_primary.cxx
contents: |
export module foo;
export int foo();
int foo_internal(); // not exported, but usable within module foo
- write: foo_impl.cxx
contents: |
module foo:impl;
import foo; // it's not an error for partitions to import the primary
int foo() { return foo_internal(); }
- write: foo_internal_impl.cxx
contents: |
module foo:internal;
import foo;
int foo_internal() { return 3; } // partitions can define
- maud
util_ is not installed:
- write: util_.cxx
contents: |
export module util_;
export int zero() { return 0; }
- write: foo.cxx
contents: |
import executable;
import util_;
int main() { return zero(); }
- maud --log-level=VERBOSE
- cmake --install .build --prefix ../usr --config Debug
- exists: .build/Debug/foo
- does not exist: .build/Debug/libutil_.a
options:
- write: options.cmake
contents: |
option(LEGACY_0 "legacy signature, default off" ADD_COMPILE_DEFINITIONS)
option(LEGACY_1 "legacy signature, default on" ON ADD_COMPILE_DEFINITIONS)
option(
B
BOOL "
Bool option
Some help text
"
ADD_COMPILE_DEFINITIONS
)
option(
B4
BOOL "HIDDEN"
)
option(
E
ENUM A B C ""
ADD_COMPILE_DEFINITIONS
)
- write: assertions.cxx
contents: |
import executable; int main() {}
static_assert(not LEGACY_0);
static_assert(LEGACY_1);
static_assert(not B);
#if defined(B4)
#error "should be disabled"
#endif
- maud --log-level=VERBOSE
- json: CMakeUserPresets.json
expect:
path: [configurePresets, 0, cacheVariables]
like:
cacheVariables:
B: OFF
B4: OFF
BUILD_SHARED_LIBS: OFF
BUILD_TESTING: ON
CMAKE_MESSAGE_LOG_LEVEL: VERBOSE
E: A
LEGACY_0: OFF
LEGACY_1: ON
MAUD_CXX_HEADER_EXTENSIONS: hxx hpp h hh h++
MAUD_CXX_SOURCE_EXCLUSION_PATTERN: ""
MAUD_CXX_SOURCE_EXTENSIONS: cxx cxxm ixx mxx cpp cppm cc ccm c++ c++m
SPHINX_BUILDERS: dirhtml
detect option dependency cycle:
- write: options.cmake
contents: |
option(A "" REQUIRES B ON)
option(B "" REQUIRES A ON)
- failing command: maud --log-level=VERBOSE
option dependencies resolve correctly:
- write: options.cmake
contents: |
option(A "" REQUIRES B ON F OFF ADD_COMPILE_DEFINITIONS)
option(B "" REQUIRES C ON ADD_COMPILE_DEFINITIONS)
option(C "" REQUIRES D 3 ADD_COMPILE_DEFINITIONS)
option(
D ENUM 0 1 2 3 ""
REQUIRES
IF 1 E "one"
IF 2 E "two"
IF 3 E "three"
ADD_COMPILE_DEFINITIONS
)
option(E STRING "" ADD_COMPILE_DEFINITIONS)
option(F "" ADD_COMPILE_DEFINITIONS)
- write: assertions.cxx
contents: |
#include <string_view>
import executable; int main() {}
using std::operator""sv;
static_assert(A and B and C);
static_assert(D_3);
static_assert(E == "three"sv);
- # Note that only -DA=ON and -DF=OFF will not be overridden
command: maud --log-level=VERBOSE -DA=ON -DB=OFF -DE=yo -DD=1 -DF=OFF
- write: options.cmake
contents: |
option(A "A help")
# If A were not already resolved, it could've been mutated here. However,
# since it was already resolved it cannot be constrained to a new value.
option(FORCE_A "" REQUIRES A ON)
- failing command: maud --log-level=VERBOSE -DFORCE_A=ON
- write: options.cmake
contents: |
option(A "" ON REQUIRES C ON)
option(B "" ON REQUIRES C OFF)
- failing command: maud --log-level=VERBOSE -DFORCE_A=ON
resolve undeclared options correctly:
- write: options.cmake
contents: |
option(A "A help" REQUIRES B ON ADD_COMPILE_DEFINITIONS)
option(B "B help" ADD_COMPILE_DEFINITIONS)
- write: assertions.cxx
contents: |
import executable; int main() {}
static_assert(A and B);
- maud --log-level=VERBOSE -DA=ON -DB=OFF
path option:
- write: options.cmake
contents: |
option(
P PATH "
Some path option
Some more description
"
ADD_COMPILE_DEFINITIONS
)
- write: assertions.cxx
contents: |
#include <string_view>
import executable; int main() {}
static_assert(P == std::string_view{__FILE__});
- # Note that only -DA=ON will not be overridden
command: maud --log-level=VERBOSE -DP=./assertions.cxx
validate bool option:
- write: options.cmake
contents: |
option(B "")
- failing command: maud --log-level=VERBOSE -DB=NEITHER_ON_NOR_OFF
validate enum option:
- write: options.cmake
contents: |
option(
E
ENUM A B C ""
)
- command: maud --log-level=VERBOSE -DE=A
- failing command: maud --log-level=VERBOSE -DE=D
validate string option with explicit code block:
- write: options.cmake
contents: |
option(
NONZERO
STRING ""
VALIDATE CODE [[
if(NONZERO EQUAL 0)
message(FATAL_ERROR "Was the name unclear?")
endif()
]]
)
- failing command: maud --log-level=VERBOSE -DNONZERO=0
documentation:
- write: index.rst
contents: |
.. trike-put:: cpp:struct Foo
- write: options.cmake
contents: |
option(
SOME_DOC_OPTION
ENUM A B C "Some documentation option"
)
- write: sphinx_configuration/conf.py
contents: |
from maud.cache import SOME_DOC_OPTION, BUILD_TESTING, CMAKE_SOURCE_DIR
extensions = ['maud', 'trike']
assert SOME_DOC_OPTION == 'B'
assert type(BUILD_TESTING) == bool
exclude_patterns = ["CMAKE_SOURCE_DIR", "Thumbs.db", ".DS_Store"]
trike_files = list(CMAKE_SOURCE_DIR.glob("*.hxx"))
- write: s.hxx
contents: |
/// a simple foobar struct
struct Foo {
/// metasyntactic variable
int bar;
/// metasyntactic variable
int baz;
};
- maud --log-level=VERBOSE -DSOME_DOC_OPTION=B
# TODO abolish exist etc; just provide an inline cmake command for asserting whatever