generate_test_code.py: add check for numerical format

Do not allow values starting with a 0 because they can be either
accidentally octal or accidentally decimal. Hex values are not
affected by this change.

Signed-off-by: Valerio Setti <[email protected]>
This commit is contained in:
Valerio Setti
2024-10-09 10:21:10 +02:00
parent b6dc14c3c8
commit a6e9c083a1
+6
View File
@@ -209,6 +209,10 @@ CONDITION_VALUE_REGEX = r'[\d|\w|\(][\s_\(\)0-9a-zA-Z\+\-\*\/]*'
CONDITION_REGEX = r'({})(?:\s*({})\s*({}))?$'.format(C_IDENTIFIER_REGEX,
CONDITION_OPERATOR_REGEX,
CONDITION_VALUE_REGEX)
# Match numerical values that start with a 0 because they can be accidentally
# octal or accidentally decimal. Hexadecimal values starting with '0x' are
# valid of course.
INVALID_NUMBER_FORMAT_REGEX = r'(0[0-9]+)'
TEST_FUNCTION_VALIDATION_REGEX = r'\s*void\s+(?P<func_name>\w+)\s*\('
FUNCTION_ARG_LIST_END_REGEX = r'.*\)'
EXIT_LABEL_REGEX = r'^exit:'
@@ -407,6 +411,8 @@ def validate_dependency(dependency):
:return: input dependency stripped of leading & trailing white spaces.
"""
dependency = dependency.strip()
if re.match(INVALID_NUMBER_FORMAT_REGEX, dependency, re.I):
raise GeneratorInputError('Invalid numerical format %s' % dependency)
if not re.match(CONDITION_REGEX, dependency, re.I):
raise GeneratorInputError('Invalid dependency %s' % dependency)
return dependency