bin/smoke_runner.rb in steep-0.1.0.pre2 vs bin/smoke_runner.rb in steep-0.1.0

- old
+ new

@@ -12,12 +12,16 @@ OptionParser.new do |opts| opts.on("-v", "--verbose") do verbose = true end end.parse!(ARGV) -Expectation = Struct.new(:line, :message) +Expectation = Struct.new(:line, :message, :path, :starts) do + attr_accessor :prefix_test +end +allowed_paths = [] + failed = false ARGV.each do |arg| dir = Pathname(arg) puts "🏇 Running smoke test in #{dir}..." @@ -33,17 +37,29 @@ _, comments, _ = parser.tokenize(buffer) comments.each do |comment| src = comment.text.gsub(/\A#\s*/, '') + if src =~ /!expects\*(@(\+\d+))?/ + offset = $2&.to_i || 1 + message = src.gsub!(/\A!expects\*(@\+\d+)? +/, '') + line = comment.location.line + + expectations << Expectation.new(line+offset, message, file).tap {|e| e.prefix_test = true } + end + if src =~ /!expects(@(\+\d+))?/ offset = $2&.to_i || 1 message = src.gsub!(/\A!expects(@\+\d+)? +/, '') line = comment.location.line - expectations << Expectation.new(line+offset, message) + expectations << Expectation.new(line+offset, message, file) end + + if src =~ /ALLOW FAILURE/ + allowed_paths << file + end end rb_files << file end end @@ -56,18 +72,21 @@ driver = Steep::Drivers::Check.new(source_paths: rb_files, signature_dirs: [builtin, dir], stdout: stdout, stderr: stderr) + Rainbow.enabled = false driver.run rescue => exn puts "ERROR: #{exn.inspect}" exn.backtrace.each do |loc| puts " #{loc}" end failed = true + ensure + Rainbow.enabled = true end if verbose stdout.string.each_line do |line| puts "stdout> #{line.chomp}" @@ -80,25 +99,39 @@ lines = stdout.string.each_line.to_a.map(&:chomp) expectations.each do |expectation| deleted = lines.reject! do |string| - string =~ /:#{expectation.line}:\d+: #{Regexp.quote expectation.message}\Z/ + if expectation.prefix_test + string =~ /\A#{Regexp.escape(expectation.path.to_s)}:#{expectation.line}:\d+: #{Regexp.quote expectation.message}/ + else + string =~ /\A#{Regexp.escape(expectation.path.to_s)}:#{expectation.line}:\d+: #{Regexp.quote expectation.message} \(/ + end end unless deleted - puts Rainbow(" 💀 Expected error not found: #{expectation.line}:#{expectation.message}").red - failed = true + allowed = allowed_paths.any? {|path| path == expectation.path } + message = Rainbow(" 💀 Expected error not found: #{expectation.path}:#{expectation.line}:#{expectation.message}") + if allowed + puts message.yellow + else + puts message.red + failed = true + end end end unless lines.empty? lines.each do |line| - if line =~ /:\d+:\d+:/ - puts Rainbow(" 🤦‍♀️ Unexpected error found: #{line}").red - failed = true - else - puts Rainbow(" 🤦 Unexpected error found, but ignored: #{line}").yellow + if line =~ /\A([^:]+):\d+:\d+:/ + message = Rainbow(" 🤦‍♀️ Unexpected error found: #{line}") + + if allowed_paths.include?(Pathname($1)) + puts message.yellow + else + puts message.red + failed = true + end end end end end