From c75ce9b77f0d4cbcba0e13b2da4676acbaef4950 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 6 Apr 2021 11:47:39 -0400 Subject: [PATCH] test: introduce helpers for skips and for a valgrind block --- test/helper.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/helper.rb b/test/helper.rb index 4be9f82ac9..eed661705c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -127,7 +127,7 @@ def teardown def stress_memory_while(&block) # force the test to explicitly declare a skip - raise "JRuby doesn't do GC" if Nokogiri.jruby? + raise "memory stress tests shouldn't be run on JRuby" if Nokogiri.jruby? old_stress = GC.stress begin @@ -138,6 +138,23 @@ def stress_memory_while(&block) end end + def skip_unless_libxml2(msg="this test should only run with libxml2") + skip(msg) unless Nokogiri.uses_libxml? + end + + def skip_unless_jruby(msg="this test should only run with jruby") + skip(msg) unless Nokogiri.jruby? + end + + def refute_valgrind_errors + # force the test to explicitly declare a skip + raise "memory stress tests shouldn't be run on JRuby" if Nokogiri.jruby? + + yield.tap do + GC.start(full_mark: true) if GC_LEVEL == "minor" + end + end + def assert_indent(amount, doc, message = nil) nodes = [] doc.traverse do |node|