cd5466
From 96684439e96aa92e10376b5be45f006772028295 Mon Sep 17 00:00:00 2001
cd5466
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
cd5466
Date: Thu, 21 Oct 2021 13:02:38 +0200
cd5466
Subject: [PATCH] Properly exclude test cases.
cd5466
cd5466
Lets consider the following scenario:
cd5466
cd5466
~~~
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):001:0> p suite
cd5466
OpenSSL::TestEC
cd5466
=> OpenSSL::TestEC
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):002:0> p all_test_methods
cd5466
["test_ECPrivateKey", "test_ECPrivateKey_encrypted", "test_PUBKEY", "test_check_key", "test_derive_key", "test_dh_compute_key", "test_dsa_sign_asn1_FIPS186_3", "test_ec_group", "test_ec_key", "test_ec_point", "test_ec_point_add", "test_ec_point_mul", "test_generate", "test_marshal", "test_sign_verify", "test_sign_verify_raw"]
cd5466
=>
cd5466
["test_ECPrivateKey",
cd5466
 "test_ECPrivateKey_encrypted",
cd5466
 "test_PUBKEY",
cd5466
 "test_check_key",
cd5466
 "test_derive_key",
cd5466
 "test_dh_compute_key",
cd5466
 "test_dsa_sign_asn1_FIPS186_3",
cd5466
 "test_ec_group",
cd5466
 "test_ec_key",
cd5466
 "test_ec_point",
cd5466
 "test_ec_point_add",
cd5466
 "test_ec_point_mul",
cd5466
 "test_generate",
cd5466
 "test_marshal",
cd5466
 "test_sign_verify",
cd5466
 "test_sign_verify_raw"]
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):003:0> p filter
cd5466
/\A(?=.*)(?!.*(?-mix:(?-mix:memory_leak)|(?-mix:OpenSSL::TestEC.test_check_key)))/
cd5466
=> /\A(?=.*)(?!.*(?-mix:(?-mix:memory_leak)|(?-mix:OpenSSL::TestEC.test_check_key)))/
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):004:0> method = "test_check_key"
cd5466
=> "test_check_key"
cd5466
~~~
cd5466
cd5466
The intention here is to exclude the `test_check_key` test case.
cd5466
Unfortunately this does not work as expected, because the negative filter
cd5466
is never checked:
cd5466
cd5466
~~~
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):005:0> filter === method
cd5466
=> true
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):006:0> filter === "#{suite}##{method}"
cd5466
=> false
cd5466
cd5466
irb(#<Test::Unit::AutoRunner::Runner:0x0000560f68afc3c8>):007:0> filter === method || filter === "#{suite}##{method}"
cd5466
=> true
cd5466
~~~
cd5466
cd5466
Therefore always filter against the fully qualified method name
cd5466
`#{suite}##{method}`, which should provide the expected result.
cd5466
cd5466
However, if plain string filter is used, keep checking also only the
cd5466
method name.
cd5466
cd5466
This resolves [Bug #16936].
cd5466
---
cd5466
 tool/lib/minitest/unit.rb | 12 +++++++++---
cd5466
 1 file changed, 9 insertions(+), 3 deletions(-)
cd5466
cd5466
diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb
cd5466
index c58a609bfa..d5af6cb906 100644
cd5466
--- a/tool/lib/minitest/unit.rb
cd5466
+++ b/tool/lib/minitest/unit.rb
cd5466
@@ -956,9 +956,15 @@ def _run_suite suite, type
cd5466
 
cd5466
       all_test_methods = suite.send "#{type}_methods"
cd5466
 
cd5466
-      filtered_test_methods = all_test_methods.find_all { |m|
cd5466
-        filter === m || filter === "#{suite}##{m}"
cd5466
-      }
cd5466
+      filtered_test_methods = if Regexp === filter
cd5466
+        all_test_methods.find_all { |m|
cd5466
+          filter === "#{suite}##{m}"
cd5466
+        }
cd5466
+      else
cd5466
+        all_test_methods.find_all {|m|
cd5466
+          filter === m || filter === "#{suite}##{m}"
cd5466
+        }
cd5466
+      end
cd5466
 
cd5466
       leakchecker = LeakChecker.new
cd5466
 
cd5466
-- 
cd5466
2.32.0
cd5466