1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
##
# Test plugin for hoe.
#
# === Tasks Provided:
#
# audit:: Run ZenTest against the package.
# default:: Run the default task(s).
# multi:: Run the test suite using multiruby.
# test:: Run the test suite.
# test_deps:: Show which test files fail when run alone.
module Hoe::Test
##
# Configuration for the supported test frameworks for test task.
SUPPORTED_TEST_FRAMEWORKS = {
:minitest => "minitest/autorun",
:none => nil,
}
Hoe::DEFAULT_CONFIG["multiruby_skip"] = []
##
# Optional: Array of incompatible versions for multiruby filtering.
# Used as a regex.
#
# Can be defined both in .hoerc and in your hoe spec. Both will be
# used.
attr_accessor :multiruby_skip
##
# Optional: What test library to require [default: :minitest]
attr_accessor :testlib
##
# Optional: Additional ruby to run before the test framework is loaded.
attr_accessor :test_prelude
##
# The test task created for this plugin.
attr_accessor :test_task
##
# Initialize variables for plugin.
def initialize_test
self.multiruby_skip ||= []
self.testlib ||= :minitest
self.test_prelude ||= nil
self.test_task = nil
end
##
# Define tasks for plugin.
def define_test_tasks
default_tasks = []
task :test
if File.directory? "test" then
case testlib
when :minitest then
require "minitest/test_task" # in minitest 5.16+
test_prelude = self.test_prelude
self.test_task = Minitest::TestTask.create :test do |t|
t.test_prelude = test_prelude
t.libs.prepend Hoe.include_dirs.uniq
end
when :none then
# do nothing
else
warn "Unsupported? Moving to Minitest::TestTask. Let me know if you use this!"
end
desc "Run the test suite using multiruby."
task :multi do
skip = with_config do |config, _|
config["multiruby_skip"] + self.multiruby_skip
end
ENV["EXCLUDED_VERSIONS"] = skip.join(":")
system "multiruby -S rake"
end
default_tasks << :test
end
desc "Run the default task(s)."
task :default => default_tasks
desc "Run ZenTest against the package."
task :audit do
libs = %w[lib test ext].join(File::PATH_SEPARATOR)
sh "zentest -I=#{libs} #{spec.files.grep(/^(lib|test)/).join(" ")}"
end
end
end
|