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