File: lint_tests.cmake

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (249 lines) | stat: -rw-r--r-- 5,522 bytes parent folder | download | duplicates (4)
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
# test: line-too-long
# expect: C0301@1
# The line is too long and exceeds the default 80 character column limit enforced cmake-lint

# test: trailing-whitespace
# expect: C0303
# This line has trailing whitespace   

# test: line-endings
# expect: C0327
# This line has the wrong line endings

# test: function-defn
# expect: C0111,C0103

function(BAD_FUNCTION_NAME badArgName good_arg_name)
  # Function names should be lower case
endfunction()

# test: macro-defn
# expect: C0112,C0103
#
macro(bad_macro_name badArgName good_arg_name)
  # Macro names should be upper case
endmacro()

# test: local-disable
# expect: C0103@8
if(FOOBAR)
  foreach(loopvar a b c d)
    # cmake-lint: disable=C0103
    foreach(LOOPVAR2 a b c d)
      # pass
    endforeach()
  endforeach()
  foreach(LOOPVAR3 a b c d)
    # pass
  endforeach()
endif()

# test: tabpolicy-spaces
# expect: C0306
if(TRUE)
	message("Hello world")
endif()

# test: under-indentation
# expect: C0307
if(TRUE)
 message("Hello world")
endif()

# test: over-indentation
# expect: C0307
if(TRUE)
   message("Hello world")
endif()


# test: oneline-disable
# expect:
set(gtest_force_shared_crt ON # cmake-lint: disable=C0103
    CACHE BOOL "See googletest/googletest/CMakeLists.txt")

# test: missing-required
# expect: E1120,E1120
set(VARNAME varvalue CACHE STRING)

# test: duplicate-kwarg
# expect: E1122
cmake_minimum_required_version(VERSION 2.8.11 VERSION 3.16)

# test: valid-duplicate-kwarg
# expect:
install(
  DIRECTORY foo bar/
  DESTINATION some/path
  PATTERN "CVS" EXCLUDE
  PATTERN "scripts/*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
                                  GROUP_EXECUTE GROUP_READ)


# test: add-custom-command-missing-required-positional
# expect: E1120
add_custom_command()

# test: add-custom-command-hidden-descriminator
# expect: C0114
set(_form TARGET PRE_BUILD)
add_custom_command(
  ${form}
  COMMAND echo "hello"
  COMMENT "echo hello")

# test: add-custom-command-invalid-descriminator
# expect: E1126
add_custom_command(
  TARGRET PRE_BUILD
  COMMAND echo "hello"
  COMMENT "echo hello")

# test: add-custom-command-missing-required-kwarg
# expect: C0113,E1125
add_custom_command(OUTPUT foo)

# test: file-missing-required
# expect: E1120
file()

# test: file-hidden-descriminator
# expect: C0114
set(_form TOUCH)
file(${form} foo.py)

# test: file-invalid-descriminator
# expect: E1126
file(TOUCHE foo.py)

# test: break-not-in-loop
# expect: E0103
break()

# test: continue-not-in-loop
# expect: E0103
continue()

# test: fundef-contains-custom-parser
# expect: C0201
# foo: docstring
function(foo)
  foreach(arg ${ARGN})
    if(arg STREQUAL "FOO")
      # parse FOO
    elseif(arg STREQUAL "BAR")
      # parse BAR
    elseif(arg MATCHES "BAZ.*")
      # parse BAZ
    endif()
  endforeach()
endfunction()

# test: multiple-statements-single-line
# expect: C0321
set(_foo "hello") set(_bar "goodbye")

# test: too-much-spacing-between-statements
# expect: C0305
set(_foo "hello")


set(_bar "goodbye")

# test: invalid-argument-name
# expect: E0109
# foo: docstring
function(foo "arg-name")
  # pass
endfunction()

# test: duplicate-argument-name
# expect: E0108
# foo: docstring
function(foo arg arg)
  # pass
endfunction()

# test: argname-differs-only-by-case
# expect: C0202
# foo: docstring
function(foo arg ARG)
  # pass
endfunction()

# test: unreachable-code
# expect: W0101
return()
message("This code is unreachable")

# test: refactor-fun
# expect: R0913,R0911,R0912,R0915
# cmake-lint: disable=E0109,C0321
# foo:docstring, too many arguments
function(foo a0 a1 a2 a3 a4 a5)

  # Too many branches, too many returns
  if(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  elseif(blah) return()
  else() return()
  endif()

  # too many statements
  message(foo) message(foo) message(foo) message(foo) message(foo) message(foo)
  message(foo) message(foo) message(foo) message(foo) message(foo) message(foo)
  message(foo) message(foo) message(foo) message(foo) message(foo) message(foo)
  message(foo) message(foo) message(foo) message(foo) message(foo) message(foo)
  message(foo) message(foo) message(foo) message(foo) message(foo) message(foo)
endfunction()

# test: invalid-varnames
# expect: C0103@3,C0103@6,C0103@9,C0103@10,C0103@12
# cmake-lint: disable=C0111
# cache (global) variables should be upper snake
set(MyGlobalVar CACHE STRING "my var")
# internal variables are treated as private and should be upper snake with an
# underscore prefix
set(MY_INTERNAL_VAR CACHE INTERNAL "my var")
# directory-scope variables should be upper-snake (public) or lower-snake with
# underscore prefix
set(_INVALID_PRIVATE_NAME "foo")
set(invalid_public_name "foo")
function(foo)
  set(INVALID_LOCAL_NAME "foo")
endfunction()

# test: set-wrong-case
# expect: W0105
set(CMAKE_Cxx_STANDARD "11")

# test: list-wrong-case
# expect: W0105
list(APPEND CMAKE_Cxx_STANDARD "11")

# test: uses-var-wrong-case
# expect: W0105
message("Using C++ standard ${CMAKE_Cxx_STANDARD}")

# test: almost-varref
# expect: W0106,W0106,W0106
message("$CMAKE_INSTALL_PREFIX}")
message("{CMAKE_INSTALL_PREFIX}")
message("${CMAKE_INSTALL_PREFIX")

# test: missing-final-newline
# expect: C0304
# This file is missing a final newline