Skip to content

Commit

Permalink
addons/namingng.py: Add tests for include guards, config file validat…
Browse files Browse the repository at this point in the history
…ion. (#5815)

Include guard naming can be validated against various patterns:
- prefixes/suffixes (`_FILE_H`, `PROJECT_FILE_H`, `FILE_H_`)
- basename/full path (`FILE_H`, `SUB_DIR_INC_FILE_H`)
- upper- or lowercase (`FILE_H`, `file_h`)
- any combination of the above (`project_sub_dir_inc_file_h_`)

A regexp can be specified to match header filenames. The example matches
any filename not starting with / and ending with `.h`, intended to match
C header files while exluding system files.

The test is not limited to naming only; validity and presence of include
guards can also be tested by setting `"required":true` in the config
file.

Enabling this feature requires adding the key `"include_guard"` to the
namingng config file used.

The namingng unit test is extended to test various features of the
include guard test.

Also, config handling is improved, adding (superficial) validation and a
unit test.
  • Loading branch information
mvds00 authored Jan 2, 2024
1 parent d9d23d9 commit 98b9244
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 34 deletions.
9 changes: 9 additions & 0 deletions addons/namingng.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"],
"RE_PRIVATE_MEMBER_VARIABLE": null,
"RE_FUNCTIONNAME": ["[a-z0-9A-Z]*\\Z"],
"include_guard": {
"input": "path",
"prefix": "",
"suffix": "",
"case": "upper",
"max_linenr": 5,
"RE_HEADERFILE": "[^/].*\\.h\\Z",
"required": true
},
"var_prefixes": {"uint32_t": "ui32",
"int*": "intp"},
"function_prefixes": {"uint16_t": "ui16",
Expand Down
Loading

0 comments on commit 98b9244

Please sign in to comment.