Commit 4340f937 authored by Albert Salim's avatar Albert Salim

Merge ee_impact and non_ee_impact

parent 2a6de5df
...@@ -12,18 +12,17 @@ module Tooling ...@@ -12,18 +12,17 @@ module Tooling
end end
def test_files def test_files
matchers = [ee_matcher, foss_matcher] impacted_tests = ee_impact | non_ee_impact
matchers.inject(Set.new) do |result, matcher| impacted_tests.impact(@file)
test_files = matcher.match(@file)
result | test_files
end.to_a
end end
private private
attr_reader :file, :foss_test_only, :result attr_reader :file, :foss_test_only, :result
class TestFileMatcher class ImpactedTestFile
attr_reader :pattern_matchers
def initialize def initialize
@pattern_matchers = {} @pattern_matchers = {}
...@@ -34,34 +33,45 @@ module Tooling ...@@ -34,34 +33,45 @@ module Tooling
@pattern_matchers[pattern] = block @pattern_matchers[pattern] = block
end end
def match(file) def impact(file)
@pattern_matchers.each_with_object(Set.new) do |(pattern, test_matcher), result| @pattern_matchers.each_with_object(Set.new) do |(pattern, block), result|
if (match = pattern.match(file)) if (match = pattern.match(file))
result << test_matcher.call(match) result << block.call(match)
end
end.to_a
end
def |(other)
self.class.new do |combined_matcher|
self.pattern_matchers.each do |pattern, block|
combined_matcher.associate(pattern, &block)
end
other.pattern_matchers.each do |pattern, block|
combined_matcher.associate(pattern, &block)
end end
end end
end end
end end
def ee_matcher def ee_impact
TestFileMatcher.new do |matcher| ImpactedTestFile.new do |impact|
unless foss_test_only unless foss_test_only
matcher.associate(%r{^#{EE_PREFIX}app/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}_spec.rb" } impact.associate(%r{^#{EE_PREFIX}app/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}_spec.rb" }
matcher.associate(%r{^#{EE_PREFIX}app/(.*/)ee/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}#{match[2]}_spec.rb" } impact.associate(%r{^#{EE_PREFIX}app/(.*/)ee/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}#{match[2]}_spec.rb" }
matcher.associate(%r{^#{EE_PREFIX}lib/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/lib/#{match[1]}_spec.rb" } impact.associate(%r{^#{EE_PREFIX}lib/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/lib/#{match[1]}_spec.rb" }
matcher.associate(%r{^#{EE_PREFIX}spec/(.+)_spec.rb$}) { |match| match[0] } impact.associate(%r{^#{EE_PREFIX}spec/(.+)_spec.rb$}) { |match| match[0] }
end end
matcher.associate(%r{^#{EE_PREFIX}(?!spec)(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}_spec.rb" } impact.associate(%r{^#{EE_PREFIX}(?!spec)(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}_spec.rb" }
matcher.associate(%r{^#{EE_PREFIX}spec/(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}.rb" } impact.associate(%r{^#{EE_PREFIX}spec/(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}.rb" }
end end
end end
def foss_matcher def non_ee_impact
TestFileMatcher.new do |matcher| ImpactedTestFile.new do |impact|
matcher.associate(%r{^app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" } impact.associate(%r{^app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" }
matcher.associate(%r{^(tooling/)?lib/(.+)\.rb$}) { |match| "spec/#{match[1]}lib/#{match[2]}_spec.rb" } impact.associate(%r{^(tooling/)?lib/(.+)\.rb$}) { |match| "spec/#{match[1]}lib/#{match[2]}_spec.rb" }
matcher.associate(%r{^spec/(.+)_spec.rb$}) { |match| match[0] } impact.associate(%r{^spec/(.+)_spec.rb$}) { |match| match[0] }
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment