File: POP_BACK.cmake

package info (click to toggle)
cmake 4.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,336 kB
  • sloc: ansic: 403,896; cpp: 303,920; sh: 4,105; python: 3,583; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 111; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (77 lines) | stat: -rw-r--r-- 1,949 bytes parent folder | download
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
function(assert_expected_list_len list_var expected_size)
    list(LENGTH ${list_var} _size)
    if(NOT _size EQUAL ${expected_size})
        message(FATAL_ERROR "list size expected to be `${expected_size}`, got `${_size}` instead")
    endif()
endfunction()

# Pop from undefined list
list(POP_BACK test)
if(DEFINED test)
    message(FATAL_ERROR "`test` expected to be undefined")
endif()

# Pop from empty list
set(test)
list(POP_BACK test)
if(DEFINED test)
    message(FATAL_ERROR "`test` expected to be undefined")
endif()

# Default pop from 1-item list
list(APPEND test one)
list(POP_BACK test)
assert_expected_list_len(test 0)

# Pop from 1-item list to var
list(APPEND test one)
list(POP_BACK test one)
assert_expected_list_len(test 0)
if(NOT DEFINED one)
    message(FATAL_ERROR "`one` expected to be defined")
endif()
if(NOT one STREQUAL "one")
    message(FATAL_ERROR "`one` has unexpected value `${one}`")
endif()

unset(one)
unset(two)

# Pop from 1-item list to vars
list(APPEND test one)
list(POP_BACK test one two)
assert_expected_list_len(test 0)
if(NOT DEFINED one)
    message(FATAL_ERROR "`one` expected to be defined")
endif()
if(NOT one STREQUAL "one")
    message(FATAL_ERROR "`one` has unexpected value `${one}`")
endif()
if(DEFINED two)
    message(FATAL_ERROR "`two` expected to be undefined")
endif()

unset(one)
unset(two)

# Default pop from 2-item list
list(APPEND test one two)
list(POP_BACK test)
assert_expected_list_len(test 1)
if(NOT test STREQUAL "one")
    message(FATAL_ERROR "`test` has unexpected value `${test}`")
endif()

# Pop from 2-item list
list(APPEND test two)
list(POP_BACK test two)
assert_expected_list_len(test 1)
if(NOT DEFINED two)
    message(FATAL_ERROR "`two` expected to be defined")
endif()
if(NOT two STREQUAL "two")
    message(FATAL_ERROR "`two` has unexpected value `${two}`")
endif()
if(NOT test STREQUAL "one")
    message(FATAL_ERROR "`test` has unexpected value `${test}`")
endif()