@@ -102,14 +102,29 @@ function run_standard_tests_ex(string $handler, string $name, LockFlag $lock, bo
102
102
echo 'Try to remove key 1 again ' , \PHP_EOL ;
103
103
var_dump (dba_delete ("key1 " , $ db_writer ));
104
104
105
- // Fetch data
105
+ // Fetch and sort data. We sort to guarantee that the output is
106
+ // consistent across invocations and architectures. When iterating
107
+ // with firstkey() and nextkey(), several engines (GDBM, LMDB,
108
+ // QDBM) make no promise about the iteration order. Others (TCADB,
109
+ // DBM) explicitly state that the order is arbitrary. With GDBM at
110
+ // least, the order appears platform-dependent -- we have a report
111
+ // in Github issue 14786. GDBM's own test suite sorts this output,
112
+ // suggesting that sorting is a reasonable workaround for the issue.
113
+ $ output = [];
114
+
106
115
$ key = dba_firstkey ($ db_writer );
107
116
$ total_keys = 0 ;
108
117
while ($ key ) {
109
- echo $ key, ': ' , dba_fetch ($ key , $ db_writer ), \PHP_EOL ;
118
+ $ output [] = $ key . ': ' . dba_fetch ($ key , $ db_writer ) . \PHP_EOL ;
110
119
$ key = dba_nextkey ($ db_writer );
111
120
$ total_keys ++;
112
121
}
122
+
123
+ sort ($ output , SORT_STRING );
124
+ foreach ($ output as $ line ) {
125
+ echo $ line ;
126
+ }
127
+
113
128
echo 'Total keys: ' , $ total_keys , \PHP_EOL ;
114
129
for ($ i = 1 ; $ i < 6 ; $ i ++) {
115
130
echo "Key $ i exists? " , dba_exists ("key $ i " , $ db_writer ) ? 'Y ' : 'N ' , \PHP_EOL ;
0 commit comments