From 1606a8e6777b8ea11ceea38708c9fbe46d3f5e7d Mon Sep 17 00:00:00 2001 From: bruntib Date: Thu, 1 Aug 2024 14:05:15 +0200 Subject: [PATCH] [fix] Support joker characters at annotation filter It is allowed now to use wildcards in the report annotation filter. For example, the reports generated by testcases starting with "TC-" can be queried by "TC-*". --- .../codechecker_server/api/report_server.py | 9 ++++++--- .../dynamic_results/test_dynamic_results.py | 17 +++++++++++++++-- ...check_0212cbc2c7194b7a5d431a18ff51bb1c.plist | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/web/server/codechecker_server/api/report_server.py b/web/server/codechecker_server/api/report_server.py index c98cbc71c0..f3e2a7a6b5 100644 --- a/web/server/codechecker_server/api/report_server.py +++ b/web/server/codechecker_server/api/report_server.py @@ -406,7 +406,8 @@ def process_report_filter( if keep_all_annotations: OR.append(or_( ReportAnnotations.key != key, - ReportAnnotations.value.in_(values))) + *[ReportAnnotations.value.ilike(conv(v)) + for v in values])) else: OR.append(and_( ReportAnnotations.key == key, @@ -2012,7 +2013,8 @@ def getRunResults(self, run_ids, limit, offset, sort_types, OR = [] for key, values in annotations.items(): - OR.append(annotation_cols[key].in_(values)) + OR.extend([annotation_cols[key].ilike(conv(v)) + for v in values]) sub_query = sub_query.having(or_(*OR)) sub_query = sort_results_query(sub_query, @@ -2125,7 +2127,8 @@ def getRunResults(self, run_ids, limit, offset, sort_types, OR = [] for key, values in annotations.items(): - OR.append(annotation_cols[key].in_(values)) + OR.extend([annotation_cols[key].ilike(conv(v)) + for v in values]) q = q.having(or_(*OR)) q = q.limit(limit).offset(offset) diff --git a/web/tests/functional/dynamic_results/test_dynamic_results.py b/web/tests/functional/dynamic_results/test_dynamic_results.py index 14519dd3a3..d3b7e3bafc 100644 --- a/web/tests/functional/dynamic_results/test_dynamic_results.py +++ b/web/tests/functional/dynamic_results/test_dynamic_results.py @@ -134,12 +134,25 @@ def test_filter_by_attribute(self): results = self._cc_client.getRunResults( None, 500, 0, None, testcase_filter, None, False) - self.assertEqual(len(results), 3) + self.assertEqual(len(results), 2) self.assertTrue(all(map( lambda report: report.annotations['testcase'] == 'TC-1', results))) + testcase_filter = ReportFilter(annotations=[Pair( + first='testcase', + second='TC-*')]) + + results = self._cc_client.getRunResults( + None, 500, 0, None, testcase_filter, None, False) + + self.assertEqual(len(results), 3) + + self.assertTrue(all(map( + lambda report: report.annotations['testcase'].startswith('TC-'), + results))) + def test_count_by_attribute(self): """ Test the report count functions with the usage of report annotations. @@ -156,4 +169,4 @@ def test_count_by_attribute(self): num = self._cc_client.getRunResultCount( None, testcase_filter, None) - self.assertEqual(num, 3) + self.assertEqual(num, 2) diff --git a/web/tests/projects/dynamic/main.c_cppcheck_0212cbc2c7194b7a5d431a18ff51bb1c.plist b/web/tests/projects/dynamic/main.c_cppcheck_0212cbc2c7194b7a5d431a18ff51bb1c.plist index a532d466b2..8bdabb75b9 100644 --- a/web/tests/projects/dynamic/main.c_cppcheck_0212cbc2c7194b7a5d431a18ff51bb1c.plist +++ b/web/tests/projects/dynamic/main.c_cppcheck_0212cbc2c7194b7a5d431a18ff51bb1c.plist @@ -20,7 +20,7 @@ testcase TS-1 testcase - TC-1 + TC-2 location