From 8cdccbbe73bdf8c7712c5d9d414afd8fdb139d98 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 29 May 2023 05:47:05 -0600 Subject: [PATCH] Extend test cases for 'condition-evals-to-constant' (#8721) Related to #7933. The original issue reported pylint as missing bugs in comparisons like: `if get_text() == "string A" or "string B":` In reality this is already covered by the message 'condition-evals-to-constant', however test cases with strings were missing, they have been added to self-document other cases this checker applies to and extend coverage. --- tests/functional/c/condition_evals_to_constant.py | 7 +++++++ tests/functional/c/condition_evals_to_constant.txt | 2 ++ 2 files changed, 9 insertions(+) diff --git a/tests/functional/c/condition_evals_to_constant.py b/tests/functional/c/condition_evals_to_constant.py index cfd0b00f4..6dfcc0e92 100644 --- a/tests/functional/c/condition_evals_to_constant.py +++ b/tests/functional/c/condition_evals_to_constant.py @@ -44,3 +44,10 @@ if True: # pylint: disable=using-constant-test CONSTANT or True bool(CONSTANT or OTHER) bool(func(CONSTANT or True)) + +# Strings also evaluate as True (they are constants) +if func("a") == "b" or "c": # [condition-evals-to-constant] + pass + +if 1 == func(2) or "fermi": # [condition-evals-to-constant] + pass diff --git a/tests/functional/c/condition_evals_to_constant.txt b/tests/functional/c/condition_evals_to_constant.txt index 13eaba89f..963771f53 100644 --- a/tests/functional/c/condition_evals_to_constant.txt +++ b/tests/functional/c/condition_evals_to_constant.txt @@ -13,3 +13,5 @@ condition-evals-to-constant:33:7:33:19::Boolean condition 'True or True' will al condition-evals-to-constant:34:7:34:21::Boolean condition 'False or False' will always evaluate to 'False':UNDEFINED condition-evals-to-constant:35:7:35:20::Boolean condition 'True and True' will always evaluate to 'True':UNDEFINED condition-evals-to-constant:36:7:36:22::Boolean condition 'False and False' will always evaluate to 'False':UNDEFINED +condition-evals-to-constant:49:3:49:26::Boolean condition 'func('a') == 'b' or 'c'' will always evaluate to ''c'':UNDEFINED +condition-evals-to-constant:52:3:52:26::Boolean condition '1 == func(2) or 'fermi'' will always evaluate to ''fermi'':UNDEFINED