ruby-changes:61717
From: Yusuke <ko1@a...>
Date: Mon, 15 Jun 2020 13:57:50 +0900 (JST)
Subject: [ruby-changes:61717] 8f99bfa26d (master): tool/lib/minitest/unit.rb: Reproducible shuffle of test suites
https://git.ruby-lang.org/ruby.git/commit/?id=8f99bfa26d From 8f99bfa26d0bd99089f0f38af3666a89e8432265 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Mon, 15 Jun 2020 13:18:56 +0900 Subject: tool/lib/minitest/unit.rb: Reproducible shuffle of test suites ... based on CRC32 of names of the test suites. Formerly, `make test-all` randomized the order of the test suites by using `Array#shuffle`. It also shows `--seed N` to reproduce the order, but it was not reproducible when a suite set is different. This change sorts the suites by CRC32 hash of the suite names with a salt generated by the seed. diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb index 707dcfb..8c2a970 100644 --- a/tool/lib/minitest/unit.rb +++ b/tool/lib/minitest/unit.rb @@ -1407,7 +1407,18 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/tool/lib/minitest/unit.rb#L1407 suites = @@test_suites.keys case self.test_order when :random - suites.shuffle + # shuffle test suites based on CRC32 of their names + salt = "\n" + rand(1 << 32).to_s + crc_tbl = (0..255).map do |i| + (0..7).inject(i) {|c,| (c & 1 == 1) ? (0xEDB88320 ^ (c >> 1)) : (c >> 1) } + end + suites = suites.sort_by do |suite| + crc32 = 0xffffffff + (suite.name + salt).bytes do |data| + crc32 = crc_tbl[(crc32 ^ data) & 0xff] ^ (crc32 >> 8) + end + crc32 ^ 0xffffffff + end when :nosort suites else -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/