Module: Minitest::Allow
- Defined in:
- lib/minitest/allow_plugin.rb
Constant Summary collapse
- VERSION =
"1.3.1"
Class Attribute Summary collapse
-
.run_only ⇒ Object
Returns the value of attribute run_only.
Instance Attribute Summary collapse
-
#allow ⇒ Object
Returns the value of attribute allow.
-
#allow_save ⇒ Object
Returns the value of attribute allow_save.
-
#allow_seen ⇒ Object
Returns the value of attribute allow_seen.
Instance Method Summary collapse
- #allow_results ⇒ Object
-
#filter_allow ⇒ Object
Test runs call record, we put everything ran in allow_seen.
- #passed? ⇒ Boolean
- #record(result) ⇒ Object
- #report_extra_allow ⇒ Object
- #write_allow ⇒ Object
Class Attribute Details
.run_only ⇒ Object
Returns the value of attribute run_only.
8 9 10 |
# File 'lib/minitest/allow_plugin.rb', line 8 def run_only @run_only end |
Instance Attribute Details
#allow ⇒ Object
Returns the value of attribute allow.
5 6 7 |
# File 'lib/minitest/allow_plugin.rb', line 5 def allow @allow end |
#allow_save ⇒ Object
Returns the value of attribute allow_save.
5 6 7 |
# File 'lib/minitest/allow_plugin.rb', line 5 def allow_save @allow_save end |
#allow_seen ⇒ Object
Returns the value of attribute allow_seen.
5 6 7 |
# File 'lib/minitest/allow_plugin.rb', line 5 def allow_seen @allow_seen end |
Instance Method Details
#allow_results ⇒ Object
16 17 18 19 20 |
# File 'lib/minitest/allow_plugin.rb', line 16 def allow_results self.reporters .grep(Minitest::StatisticsReporter) .map(&:results) end |
#filter_allow ⇒ Object
Test runs call record, we put everything ran in allow_seen. This means allow_seen has everything RAN, regardless of pass/fail We use this intersected with the allowed file to determine what to report on... if it wasn't seen, we don't say add/remove at all.
allow is all the stuff from the allow file. Test names and
regexps that excuse failures.
allow_results is an array of arrays of results: [[result, ...], ...]
When the run is done, we want to tell the user what tests to remove or add from the allowed list:
- If a test passed that is in the allowed list, it should be removed.
- If a test failed that is NOT in the allowed list, it should be added.
- If a test failed that is matched by a regexp, it's NAME should be removed if it is listed.
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 104 105 106 107 108 109 |
# File 'lib/minitest/allow_plugin.rb', line 50 def filter_allow # 1. split allow into strings and regexps allowed_REs, allowed_names = allow.partition { |a| Regexp === a } allowed_names = allowed_names.map { |x| [x, x] }.to_h # 2. remove items from allow_results whose full_name matches the strings # 3. remove items from allow_results whose message matches the regexps # 4. remove items from allow_results whose full_name matches the regexps? hit = {} allow_results = self.allow_results allow_results.each do |results| results.delete_if { |r| name = r.full_name by_name = allowed_names[name] by_regx = allowed_REs.find { |re| r.failure. =~ re || name =~ re } # this will add the name as bad unless hit by regexp as well # if hit by regex, then we want to report it as "good" so # the name gets removed from the allow list: # the same goes for when the test is listed as bad but is now skipped: hit[name] = true if by_name && !by_regx && !r.skipped? by_name || by_regx } end # 5. remove string and regexps that matched any of the above from allow self.allow -= hit.keys errored, failed = allow_results .flatten .reject(&:skipped?) .partition { |t| Minitest::UnexpectedError === t.failure } failed = failed.map(&:full_name) errors = Hash.new { |h,k| h[k] = [] } errored.each do |t| msg = t.failure..lines.first.chomp.gsub(/0x\h+/, "0xHHHH") errors[Regexp.new(Regexp.escape(msg))] << t.full_name end extra_bad = failed.uniq extra_bad << errors.transform_values(&:uniq) unless errors.empty? # 6. report new failures including regular expressions for errors unless extra_bad.empty? then io.puts io.puts "Bad tests that are NOT allowed:" Psych.dump extra_bad, io, line_width:-1 io.puts end end |
#passed? ⇒ Boolean
122 123 124 125 126 127 128 |
# File 'lib/minitest/allow_plugin.rb', line 122 def passed? write_allow if allow_save filter_allow if allow report_extra_allow if allow super # CompositeReporter#passed? end |
#record(result) ⇒ Object
11 12 13 14 |
# File 'lib/minitest/allow_plugin.rb', line 11 def record result allow_seen << result.full_name super end |
#report_extra_allow ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/minitest/allow_plugin.rb', line 111 def report_extra_allow good = allow & allow_seen unless good.empty? then io.puts io.puts "Excluded tests that now pass:" Psych.dump good, io, line_width:-1 io.puts end end |
#write_allow ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/minitest/allow_plugin.rb', line 22 def write_allow data = allow_results .flatten .map(&:full_name) .uniq .sort File.write allow_save, Psych.dump(data, line_width:-1) end |