Skip to content

Commit ed5477b

Browse files
committed
Add assert reference documentation
Perhaps this doc needs to be improved with more concrete / useful examples. For now, this will have to do.
1 parent 427c00b commit ed5477b

File tree

1 file changed

+207
-1
lines changed

1 file changed

+207
-1
lines changed

docs/+current/modules/testing/cmake/-asserts.md

Lines changed: 207 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,210 @@ author: RSP Systems A/S
77

88
# Asserts
99

10-
_TODO: ..._
10+
[TOC]
11+
12+
## Failure Message
13+
14+
All assert functions support an optional `MESSAGE` argument, which is shown if the assertion failed.
15+
16+
```cmake
17+
assert_truthy(false MESSAGE "My fail msg...")
18+
```
19+
20+
## Existence
21+
22+
### `assert_defined()`
23+
24+
Assert key to be defined.
25+
26+
```cmake
27+
assert_defined(my_variable)
28+
```
29+
30+
See https://cmake.org/cmake/help/latest/command/if.html#defined.
31+
32+
### `assert_not_defined()`
33+
34+
The opposite of `assert_defined()`.
35+
36+
```cmake
37+
assert_not_defined(my_variable)
38+
```
39+
40+
## Boolean
41+
42+
### `assert_truthy()`
43+
44+
Assert key to be truthy.
45+
46+
```cmake
47+
assert_truthy(my_variable)
48+
```
49+
50+
See https://cmake.org/cmake/help/latest/command/if.html#basic-expressions.
51+
52+
### `assert_falsy()`
53+
54+
The opposite of `assert_truthy()`.
55+
56+
```cmake
57+
assert_falsy(my_variable)
58+
```
59+
60+
## Numbers
61+
62+
### `assert_equals()`
63+
64+
Assert numeric keys or values equal each other..
65+
66+
```cmake
67+
assert_equals(expected actual)
68+
```
69+
70+
See https://cmake.org/cmake/help/latest/command/if.html#equal.
71+
72+
### `assert_not_equals()`
73+
74+
The opposite of `assert_equals()`.
75+
76+
```cmake
77+
assert_not_equals(expected actual)
78+
```
79+
80+
### `assert_less_than()`
81+
82+
Assert numeric key or value is less than specified value.
83+
84+
```cmake
85+
assert_less_than(expected actual)
86+
```
87+
88+
See https://cmake.org/cmake/help/latest/command/if.html#less.
89+
90+
### `assert_less_than_or_equal()`
91+
92+
Assert numeric key or value is less than or equal to the specified value.
93+
94+
```cmake
95+
assert_less_than_or_equal(expected actual)
96+
```
97+
98+
See https://cmake.org/cmake/help/latest/command/if.html#less-equal.
99+
100+
### `assert_greater_than()`
101+
102+
Assert numeric key or value is greater than specified value.
103+
104+
```cmake
105+
assert_greater_than(expected actual)
106+
```
107+
108+
See https://cmake.org/cmake/help/latest/command/if.html#greater.
109+
110+
### `assert_greater_than_or_equal()`
111+
112+
Assert numeric key or value is greater than or equal to the specified value.
113+
114+
```cmake
115+
assert_greater_than_or_equal(expected actual)
116+
```
117+
118+
See https://cmake.org/cmake/help/latest/command/if.html#greater-equal.
119+
120+
## Strings
121+
122+
### `assert_string_equals()`
123+
124+
Assert string keys or values equal each other.
125+
126+
```cmake
127+
assert_string_equals(expected actual)
128+
```
129+
130+
See https://cmake.org/cmake/help/latest/command/if.html#strequal
131+
132+
### `assert_string_not_equals()`
133+
134+
Opposite of `assert_string_equals()`.
135+
136+
```cmake
137+
assert_string_not_equals(expected actual)
138+
```
139+
140+
### `assert_string_empty()`
141+
142+
Assert given string is empty.
143+
144+
```cmake
145+
assert_string_empty("${my_string}")
146+
```
147+
148+
See https://cmake.org/cmake/help/latest/command/string.html#length
149+
150+
### `assert_string_not_empty()`
151+
152+
Opposite of `assert_string_empty()`.
153+
154+
```cmake
155+
assert_string_not_empty("${my_string}")
156+
```
157+
158+
## Lists
159+
160+
### `assert_in_list()`
161+
162+
Assert key (value) to be in given list.
163+
164+
```cmake
165+
assert_in_list(item list)
166+
```
167+
168+
See https://cmake.org/cmake/help/latest/command/if.html#in-list.
169+
170+
### `assert_not_in_list()`
171+
172+
Opposite of `assert_in_list()`.
173+
174+
```cmake
175+
assert_not_in_list(item list)
176+
```
177+
178+
## Commands & Macros
179+
180+
### `assert_is_callable()`
181+
182+
Assert key to be a callable command or macro.
183+
184+
```cmake
185+
assert_is_callable("my_function")
186+
```
187+
188+
See https://cmake.org/cmake/help/latest/command/if.html#command.
189+
190+
### `assert_is_not_callable()`
191+
192+
Opposite of `assert_is_callable()`.
193+
194+
```cmake
195+
assert_is_not_callable("my_unknown_function")
196+
```
197+
198+
## Files & Paths
199+
200+
### `assert_file_exists()`
201+
202+
Assert file exists.
203+
204+
```cmake
205+
assert_file_exists("${my_file_path}")
206+
```
207+
208+
See https://cmake.org/cmake/help/latest/command/if.html#exists.
209+
210+
### `assert_file_not_exists()`
211+
212+
Opposite of `assert_file_exists()`.
213+
214+
```cmake
215+
assert_file_not_exists("${my_file_path}")
216+
```

0 commit comments

Comments
 (0)