@@ -102,14 +102,29 @@ function run_standard_tests_ex(string $handler, string $name, LockFlag $lock, bo
102102    echo  'Try to remove key 1 again ' , \PHP_EOL ;
103103    var_dump (dba_delete ("key1 " , $ db_writer ));
104104
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+ 
106115    $ key  = dba_firstkey ($ db_writer );
107116    $ total_keys  = 0 ;
108117    while  ($ key ) {
109-         echo   $ key,  ':  ' ,  dba_fetch ($ key , $ db_writer ),  \PHP_EOL ;
118+         $ output [] =  $ key .  ':  '  .  dba_fetch ($ key , $ db_writer ) .  \PHP_EOL ;
110119        $ key  = dba_nextkey ($ db_writer );
111120        $ total_keys ++;
112121    }
122+ 
123+     sort ($ output , SORT_STRING );
124+     foreach  ($ output  as  $ line ) {
125+         echo  $ line ;
126+     }
127+ 
113128    echo  'Total keys:  ' , $ total_keys , \PHP_EOL ;
114129    for  ($ i  = 1 ; $ i  < 6 ; $ i ++) {
115130        echo  "Key  $ i exists?  " , dba_exists ("key $ i " , $ db_writer ) ? 'Y '  : 'N ' , \PHP_EOL ;
0 commit comments