-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject_tests.cmake
1238 lines (1075 loc) · 26.6 KB
/
project_tests.cmake
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
macro("project test: empty")
# With no files at all, maud will still configure a viable build
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: hello world")
write(
hello.cxx
[[
#include <iostream>
import executable;
int main() {
std::cout << "hello world!" << std::endl;
}
]]
)
run(COMMAND maud --log-level=VERBOSE)
run(COMMAND .build/Debug/hello)
assert([[OUT STREQUAL "hello world!\n"]])
endmacro()
macro("project test: auto included cmake modules")
set(crib "<CRIB>${TEST_NAME}</CRIB>")
file(WRITE cmake_modules/IncludeMe.cmake "")
write(
crib.cmake
"
# output a recognizable message to search for so we can verify this ran
message(STATUS [[${crib}]])
# unless explicit inclusion module directory was discovered, this will error
include(IncludeMe)
"
)
# ensure that explicit inclusion modules s won't be run un unless ss included
set(anticrib "<ANTICRIB>${TEST_NAME}</ANTICRIB>")
file(WRITE cmake_modules/DontIncludeMe.cmake "message(STATUS [[${anticrib}]])")
run(COMMAND maud --log-level=VERBOSE)
assert("OUT MATCHES [[${crib}]]")
assert("NOT OUT MATCHES [[${anticrib}]]")
endmacro()
macro("project test: auto add sources")
write(
foo.cxx
[[
export module foo;
export int foo() { return 0; }
]]
)
run(COMMAND maud --log-level=VERBOSE)
library_name(STATIC foo libfoo)
assert([[EXISTS ".build/Debug/${libfoo}"]])
write(
bar.cxx
[[
export module bar;
export int bar() { return 0; }
]]
)
run(COMMAND cmake --build .build --config Debug)
library_name(STATIC bar libbar)
assert([[EXISTS ".build/Debug/${libbar}"]])
write(
bar.cxx
[[
export module bar2; // NOTE altered module name
export int bar() { return 0; }
]]
)
run(COMMAND cmake --build .build --config Debug)
library_name(STATIC bar2 libbar2)
assert([[EXISTS ".build/Debug/${libbar2}"]])
endmacro()
macro("project test: auto primary interface")
write(
foo_a.cxx
[[
export module foo:a;
export int a() { return 'a'; }
]]
)
write(
foo_b.cxx
[[
export module foo:b;
export int b() { return 'b'; }
]]
)
write(
use.cxx
[[
import executable;
import foo;
int main() {
return a() + b();
}
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: std lib")
write(
std_.cxx
[[
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
[[
import executable;
import std_;
int main() {
std::vector<std::string> s;
return 0;
}
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: glob benchmark")
write(
benchmark.cmake
[[
_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
[===========[
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")
]===========]
)
run(COMMAND maud)
file(WRITE log "${OUT}")
endmacro()
macro("project test: unit testing")
write(
basics.cxx
[[
#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);
}
]]
)
run(COMMAND maud)
run(COMMAND ctest --test-dir .build --output-on-failure -C Debug)
file(GLOB built_executable .build/Debug/test_.basics*)
assert([[built_executable]])
# Assert that the test executable isn't installed
run(COMMAND cmake --install .build --prefix .usr --config Debug)
file(GLOB installed_executable .usr/bin/test_.basics*)
assert([[NOT installed_executable]])
endmacro()
macro("project test: disabled unit testing")
write(
inline_python.test.cxx
[[
#include <string>
import test_;
TEST_(inline_python) {
from __future__ import braces
def foo():
assert 1 == 0
}
]]
)
run(COMMAND maud -DBUILD_TESTING=OFF)
endmacro()
macro("project test: internal unit testing")
write(
foo.cxx
[[
export module foo:interface;
// not exported!
int foo_internal() { return 3; }
]]
)
write(
internal.test.cxx
[[
module foo:some_test;
import :interface;
import test_;
TEST_(can_access_internal) {
EXPECT_(foo_internal() == 3);
}
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: unit testing with custom main module")
write(
test_main.cxx
[[
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.test.cxx
[[
import test_;
TEST_(check_foo_is_999) {
EXPECT_(foo == 999);
}
]]
)
run(COMMAND maud --log-level=VERBOSE)
run(COMMAND ctest --test-dir .build --output-on-failure -C Debug)
endmacro()
macro("project test: non-gtest unit testing")
write(
correct_math.test.cxx
[[
import test_;
int main() {
expect_eq(1 + 2, 3);
}
]]
)
write(
gotcha_math.test.cxx
[[
import test_;
int main() {
expect_eq(1/2, 0.5);
}
]]
)
write(
.test_.cxx
[[
module;
#include <iostream>
export module test_;
export void expect_eq(auto const &l, auto const &r) {
if (l == r) return;
std::cerr << "failed: " << l << "==" << r << std::endl;
throw 1;
}
]]
)
write(
test_.cmake
[[
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 test_module TYPE CXX_MODULES
BASE_DIRS ${CMAKE_SOURCE_DIR} FILES .test_.cxx
)
endfunction()
]]
)
run(COMMAND maud --log-level=VERBOSE)
run(COMMAND ctest -R correct --test-dir .build --output-on-failure -C Debug)
run(FAILING COMMAND ctest -R gotcha --test-dir .build --output-on-failure -C Debug)
endmacro()
macro("project test: import installed")
write(
foo/foo.cxx
[[
export module foo;
export int foo() { return 0; }
]]
)
run(
COMMAND maud --log-level=VERBOSE
WORKING_DIRECTORY foo
)
run(COMMAND cmake --install foo/.build --config Debug --prefix .usr)
write(
use/use_foo.cxx
[[
import executable;
import foo;
int main() { return foo(); }
]]
)
run(
COMMAND maud --log-level=VERBOSE
WORKING_DIRECTORY use
)
endmacro()
macro("project test: util_ is not installed")
write(
util_.cxx
[[
export module util_;
export int zero() { return 0; }
]]
)
write(
noop.cxx
[[
import executable;
import util_;
int main() { return zero(); }
]]
)
run(COMMAND maud --log-level=VERBOSE)
run(COMMAND cmake --install .build --config Debug --prefix .usr)
file(GLOB installed_util .usr/lib/*util_.*)
assert([[NOT installed_util]])
run(COMMAND noop)
endmacro()
macro("project test: rendered in2 source")
write(
render_foo.cmake
[[
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
[[
export module bar;
export int INTS[] = {@
foreach(i RANGE 10)
render("${i},")
endforeach()
@};
export bool constexpr BOOL = @MAUD_DIR | if_else(1 0)@;
]]
)
run(COMMAND maud --log-level=VERBOSE)
library_name(STATIC foo libfoo)
library_name(STATIC bar libbar)
assert([[EXISTS ".build/Debug/${libfoo}"]])
assert([[EXISTS ".build/Debug/${libbar}"]])
endmacro()
macro("project test: c++17 project")
write(
src/src-y.cxx
[[
int main() {}
]]
)
write(
explicit_targets.cmake
[[
set(CMAKE_CXX_STANDARD 17)
glob(SRCS CONFIGURE_DEPENDS "src/.*[.]cxx$")
add_executable(hello ${SRCS})
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: c++23 project")
write(
fib.cxx
[[
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
[[
set(CMAKE_CXX_STANDARD 23)
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: use find_package")
write(
use_fmt.cxx
[[
#include <fmt/format.h>
import executable;
int main() {}
]]
)
write(
use_fmt.cmake
[[
find_package(fmt REQUIRED)
add_executable(use_fmt)
target_link_libraries(
use_fmt
PRIVATE
fmt::fmt-header-only
)
set(options "-DFMT_HEADER_ONLY=1")
get_target_property(i fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES)
foreach(d ${i})
string(APPEND options " ${CMAKE_INCLUDE_SYSTEM_FLAG_CXX} ${d}")
endforeach()
set_source_files_properties(
"${dir}/use_fmt.cxx"
PROPERTIES
MAUD_PREPROCESSING_SCAN_OPTIONS "${options}"
)
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: internal decl")
write(
foo_part.cxx
[[
export module foo:part;
// declared functions are defined in the implementation units below
export int foo();
export int foo_half();
export int foo_third();
// not exported, but usable within module foo
int foo_internal();
]]
)
write(
foo_impl.cxx
[[
module foo;
import :part;
int foo() { return foo_internal(); }
]]
)
write(
foo_half_impl.cxx
[[
module foo:half_impl;
import :part;
int foo_half() { return foo_internal() / 2; }
]]
)
write(
foo_third_impl.cxx
[[
module foo:third_impl;
// instead of importing partitions of foo's interface,
// implementation units may choose to just import the primary
import foo;
int foo_half() { return foo_internal() / 3; }
]]
)
write(
foo_internal_impl.cxx
[[
module foo;
// implementation units with no partition automatically import
// the full primary interface
int foo_internal() { return 6; }
]]
)
write(
foo_empty_impl.cxx
[[
module foo;
// any number of implementation units may be written for a module
]]
)
run(COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: options")
write(
options.cmake
[[
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
[[
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
]]
)
run(COMMAND maud --log-level=VERBOSE)
file(READ CMakeUserPresets.json presets)
json_destructure(preset_ "${presets}" configurePresets 0 cacheVariables)
assert([[preset_B STREQUAL "OFF"]])
assert([[preset_B4 STREQUAL "OFF"]])
assert([[preset_BUILD_SHARED_LIBS STREQUAL "OFF"]])
assert([[preset_BUILD_TESTING STREQUAL "ON"]])
assert([[preset_CMAKE_MESSAGE_LOG_LEVEL STREQUAL "VERBOSE"]])
assert([[preset_E STREQUAL "A"]])
assert([[preset_LEGACY_0 STREQUAL "OFF"]])
assert([[preset_LEGACY_1 STREQUAL "ON"]])
assert([[preset_MAUD_CXX_HEADER_EXTENSIONS STREQUAL "hxx hpp h hh h++"]])
assert([[preset_MAUD_CXX_SOURCE_EXCLUSION_PATTERN STREQUAL ""]])
assert([[
preset_MAUD_CXX_SOURCE_EXTENSIONS
STREQUAL
"cxx cxxm ixx mxx cpp cppm cc ccm c++ c++m"
]])
assert([[preset_SPHINX_BUILDERS STREQUAL "dirhtml"]])
endmacro()
macro("project test: detect option dependency cycle")
write(
options.cmake
[[
option(A "" REQUIRES B ON)
option(B "" REQUIRES A ON)
]]
)
run(FAILING COMMAND maud --log-level=VERBOSE)
endmacro()
macro("project test: option dependencies resolve correctly")
write(
options.cmake
[[
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
[[
#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);
]]
)
run(
COMMAND
maud
# Note that only -DA=ON and -DF=OFF will not be overridden
-DA=ON
-DB=OFF
-DE=yo
-DD=1
-DF=OFF
)
write(
options.cmake
[[
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)
]]
)
run(FAILING COMMAND maud -DFORCE_A=ON)
write(
options.cmake
[[
# Conflicting requirements:
option(A "" ON REQUIRES C ON)
option(B "" ON REQUIRES C OFF)
]]
)
run(FAILING COMMAND maud)
endmacro()
macro("project test: resolve undeclared options correctly")
write(
options.cmake
[[
option(A "A help" REQUIRES B ON ADD_COMPILE_DEFINITIONS)
option(B "B help" ADD_COMPILE_DEFINITIONS)
]]
)
write(
assertions.cxx
[[
import executable; int main() {}
static_assert(A and B);
]]
)
# we expect the requirements to override user flags:
run(COMMAND maud --log-level=VERBOSE -DA=ON -DB=OFF)
endmacro()
macro("project test: path option")
write(
options.cmake
[[
option(
P PATH "
Some path option
Some more description
"
)
option(Q FILEPATH "")
]]
)
write(foo/bar/baz/quux "")
run(
COMMAND
maud
--log-level=VERBOSE
--source-dir=../../..
-DP=../../..
-DQ=quux
WORKING_DIRECTORY foo/bar/baz
)
cmake_path(NATIVE_PATH MAUD_WORKING_DIR expected_P)
set(expected_Q "${MAUD_WORKING_DIR}/foo/bar/baz/quux")
cmake_path(NATIVE_PATH expected_Q expected_Q)
# Path options are always relative to the working directory of the cmake
# process so that `-DFOO=./foo<TAB>` won't break even if we're not in the source root
assert("OUT MATCHES [[ P = ${expected_P} ]]")
assert("OUT MATCHES [[ Q = ${expected_Q} ]]")
endmacro()
macro("project test: validate options")
write(
options.cmake
[[
option(B "")
]]
)
# BOOL options must be ON or OFF
run(COMMAND maud -DB=ON)
run(FAILING COMMAND maud -DB=NEITHER_ON_NOR_OFF)
write(
options.cmake
[[
option(
E
ENUM A B C ""
)
]]
)
# ENUM options must be one of their allowed values
run(COMMAND maud -DE=A)
run(FAILING COMMAND maud -DE=-999)
write(
options.cmake
[=[
option(
NONZERO
STRING ""
VALIDATE CODE [[
if(NONZERO EQUAL 0)
message(FATAL_ERROR "Was the name unclear?")
endif()
]]
)
]=]
)
# an explicit VALIDATE CODE block can enforce
# arbitrary conditions
run(COMMAND maud -DNONZERO=10)
run(FAILING COMMAND maud -DNONZERO=0)
endmacro()
macro("project test: documentation")
write(
options.cmake
[[
option(
SOME_DOC_OPTION
ENUM A B C "Some documentation option"
)
]]
)
write(
index.rst
[[
.. trike-put:: cpp:struct Foo
]]
)
write(
sphinx_configuration/conf.py
[[
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
[[
/// a simple foobar struct
struct Foo {
/// metasyntactic variable
int bar;