From 0a2cb7d1bda7b9b8f9a6d0b44b465da1c106f95f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 9 Apr 2021 18:06:57 +0200 Subject: [PATCH] tests: support skipping tests for certain build configurations --- rake.d/config.rb | 8 +++++--- tests/run.rb | 4 ++++ tests/test.d/controller.rb | 5 +++++ tests/test.d/simple_test.rb | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/rake.d/config.rb b/rake.d/config.rb index 3c2857646..1869e4eac 100644 --- a/rake.d/config.rb +++ b/rake.d/config.rb @@ -11,10 +11,12 @@ def read_config_file file_name end def read_build_config - fail "build-config not found: please run ./configure" unless File.exists?("build-config") + dir = File.dirname(__FILE__) + '/..' - config = read_config_file("build-config") - config = config.merge(read_config_file("build-config.local")) if File.exists?("build-config.local") + fail "build-config not found: please run ./configure" unless File.exists?("#{dir}/build-config") + + config = read_config_file("#{dir}/build-config") + config = config.merge(read_config_file("#{dir}/build-config.local")) if File.exists?("#{dir}/build-config.local") config end diff --git a/tests/run.rb b/tests/run.rb index 0a4a4bd8c..e66422c27 100755 --- a/tests/run.rb +++ b/tests/run.rb @@ -12,6 +12,8 @@ require_relative "test.d/results.rb" require_relative "test.d/test.rb" require_relative "test.d/simple_test.rb" require_relative "test.d/util.rb" +require_relative "../rake.d/config.rb" +require_relative "../rake.d/extensions.rb" begin require "thread" @@ -21,6 +23,8 @@ end def setup ENV[ /darwin/i.match(RUBY_PLATFORM) ? 'LANG' : 'LC_ALL' ] = 'en_US.UTF-8' ENV['PATH'] = "../src:" + ENV['PATH'] + + $config = read_build_config end def main diff --git a/tests/test.d/controller.rb b/tests/test.d/controller.rb index 10616b8fd..3933d1ba7 100644 --- a/tests/test.d/controller.rb +++ b/tests/test.d/controller.rb @@ -117,6 +117,11 @@ class Controller return end + if current_test.methods.include?(:skip?) and current_test.skip? + show_message "Skipping '#{class_name}': disabled" + return + end + show_message "Running '#{class_name}': #{current_test.description}" start = Time.now diff --git a/tests/test.d/simple_test.rb b/tests/test.d/simple_test.rb index 480265a89..3980ce7a6 100644 --- a/tests/test.d/simple_test.rb +++ b/tests/test.d/simple_test.rb @@ -34,6 +34,7 @@ class SimpleTest @commands = [] @tmp_num = 0 @tmp_num_mutex = Mutex.new + @skip = false @blocks = { :setup => [], :tests => [], @@ -41,6 +42,14 @@ class SimpleTest } end + def skip_if condition + @skip = true if condition + end + + def skip? + @skip + end + def commands @commands end