[gcc r17-1419] testsuite: get a predictable ordered array for comparison
Torbjorn Svensson
azoff@gcc.gnu.org
Mon Jun 8 10:42:11 GMT 2026
https://gcc.gnu.org/g:050c632327e4c499c66d4d258763a7b846a53134
commit r17-1419-g050c632327e4c499c66d4d258763a7b846a53134
Author: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Date: Tue Apr 7 14:32:46 2026 +0200
testsuite: get a predictable ordered array for comparison
Without this patch, errors like below can be seen in g++.log:
Traceback (most recent call last):
File "/build/gcc_src/gcc/testsuite/g++.dg/modules/test-p1689.py", line 220, in <module>
is_ok = validate_p1689(actual, expect)
...
File "/build/gcc_src/gcc/testsuite/g++.dg/modules/test-p1689.py", line 149, in compare_json
actual = set(actual)
TypeError: unhashable type: 'dict'
To avoid hashing dicts, transform the elements to string representation
prior to sorting the array and then transform back to objects after.
gcc/testsuite/ChangeLog:
* g++.dg/modules/test-p1689.py: Make arrays have predictable
order.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Diff:
---
gcc/testsuite/g++.dg/modules/test-p1689.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/gcc/testsuite/g++.dg/modules/test-p1689.py b/gcc/testsuite/g++.dg/modules/test-p1689.py
index 2f07cc361aaf..b9cb3ebfc323 100644
--- a/gcc/testsuite/g++.dg/modules/test-p1689.py
+++ b/gcc/testsuite/g++.dg/modules/test-p1689.py
@@ -131,6 +131,16 @@ def _inspect_ordering(arr):
return arr, req_ordering
+def _get_predictable_ordered_array(arr):
+ if not arr:
+ return arr
+
+ # Convert to list of string to get predictable order.
+ # Using set() here causes issue with complex arrays
+ arr = [json.dumps(x) for x in arr]
+ arr.sort()
+ return [json.loads(x) for x in arr]
+
def compare_json(path, actual, expect):
actual_type = type(actual)
@@ -146,8 +156,8 @@ def compare_json(path, actual, expect):
elif actual_type == list:
expect, req_ordering = _inspect_ordering(expect)
if not req_ordering:
- actual = set(actual)
- expect = set(expect)
+ actual = _get_predictable_ordered_array(actual)
+ expect = _get_predictable_ordered_array(expect)
is_ok = _compare_array(path, actual, expect)
elif actual_type == str:
is_ok = _compare_string(path, actual, expect)
More information about the Gcc-cvs
mailing list