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