Skip to content

Commit

Permalink
Fixup multiple crashes (#57)
Browse files Browse the repository at this point in the history
* Fixup crash if no --var param is passed

If no var is passed, the args.var will be set to None.
Trying to iterate on None throws the following exception:
    TypeError: 'NoneType' object is not iterable

The function now only processes the list if it's defined

* Fixup crash when filefilter contains empty lines

The RemoveOuterQuotes function did not check the line length,
resulting in the following error if an empty line is present:
    string index out of range

The function now only checks string that are at least 2 char long

* Fixup crash when filefilter contains comments

The _ProcessFilterLine function returned None when a comment was found
instead of the filter.
The caller replaces the filter with the function return value.
The next call then crashed with the following error:
    'NoneType' object has no attribute 'AddCppChecker'

The filter is now returned in this case as well

* Add an application test

This new test runs the app as the user would with a bit of configuration

* Review: invert GetCliKeyValueMap condition

* Review: rework test resources
  • Loading branch information
Farigh authored Dec 3, 2023
1 parent e989fec commit ca390e3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ jobs:
- name: Run NSIQCppStyle RULES tests
timeout-minutes: 5
run: PYTHONPATH=./:./rules python -m unittest discover -s rules -p "*.py"

- name: Run NSIQCppStyle App tests
timeout-minutes: 5
run: python nsiqcppstyle_exe.py -f nsiqunittest/rules/comment_and_empty_lines.txt --ci nsiqunittest/src/simple_main.cpp
6 changes: 5 additions & 1 deletion nsiqcppstyle_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _ProcessFilterLine(self, filter, raw_line):

if line.startswith("#") or len(line) == 0:
# Comment or empty line, just return
return None
return filter
if line.startswith("*"):
if len(line[1:].strip()) != 0:
filterName = line[1:].strip()
Expand Down Expand Up @@ -567,6 +567,9 @@ def AddVarMap(self, keyValuePairString, where):


def GetCliKeyValueMap(kvList):
if kvList == None:
return {}

varMap = {}
for kv in kvList:
kvPair = kv.split(":", 1)
Expand All @@ -575,6 +578,7 @@ def GetCliKeyValueMap(kvList):
f"Error!: No key found in {kv}. Please use KEY:VALUE style to provide key and value",
)
varMap[kvPair[0]] = kvPair[1]

return varMap


Expand Down
6 changes: 5 additions & 1 deletion nsiqcppstyle_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def CmpObjects(a, b):

def RemoveOuterQuotes(raw_string):
final_string = raw_string.strip()
if final_string[0] == final_string[-1] and final_string[0] in [SINGLE_QUOTE, DOUBLE_QUOTE]:
if (
len(final_string) >= 2
and final_string[0] == final_string[-1]
and final_string[0] in [SINGLE_QUOTE, DOUBLE_QUOTE]
):
final_string = final_string[1:-1].strip()
return final_string
11 changes: 11 additions & 0 deletions nsiqunittest/rules/comment_and_empty_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This filefilter is here to ensure that the app:
# - handles comments properly
# - handles empty lines correctly

~ RULE_3_1_A_do_not_start_filename_with_underbar
~ RULE_3_3_A_start_function_name_with_lowercase_unix
~ RULE_3_3_B_start_private_function_name_with_underbar
~ RULE_4_5_B_use_braces_even_for_one_statement
~ RULE_7_2_B_do_not_use_goto_statement
~ RULE_9_1_A_do_not_use_hardcorded_include_path
~ RULE_9_2_D_use_reentrant_function
4 changes: 4 additions & 0 deletions nsiqunittest/src/simple_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main(int argc, char* argv[])
{
return 1;
}

0 comments on commit ca390e3

Please sign in to comment.