Skip to content

Commit 02d7909

Browse files
committed
Add test for requires_arguments()
1 parent 350eecf commit 02d7909

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include("rsp/testing")
2+
include("rsp/helpers")
3+
4+
define_test_case(
5+
"Requires Arguments Test"
6+
LABELS "requires;args;helpers"
7+
)
8+
9+
# -------------------------------------------------------------------------------------------------------------- #
10+
# Helpers
11+
# -------------------------------------------------------------------------------------------------------------- #
12+
13+
function(fn_with_required_args)
14+
set(options "") # N/A
15+
set(oneValueArgs NAME DESCRIPTION)
16+
set(multiValueArgs "") # N/A
17+
18+
cmake_parse_arguments(INPUT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
19+
requires_arguments(INPUT "NAME;DESCRIPTION")
20+
endfunction()
21+
22+
# -------------------------------------------------------------------------------------------------------------- #
23+
# Actual Tests
24+
# -------------------------------------------------------------------------------------------------------------- #
25+
26+
define_test("ensures required args are defined" "ensures_required_args_defined")
27+
function(ensures_required_args_defined)
28+
29+
# If invoking method does not cause a fatal error, test passes.
30+
fn_with_required_args(NAME "foo" DESCRIPTION "bar")
31+
32+
endfunction()
33+
34+
define_test("fails when required args are not defined" "fails_when_required_arg_not_defined" EXPECT_FAILURE)
35+
function(fails_when_required_arg_not_defined)
36+
37+
# This should cause a failure because DESCRIPTION is required
38+
fn_with_required_args(NAME "foo")
39+
40+
endfunction()

0 commit comments

Comments
 (0)