lib/tork/driver.rb in tork-17.1.0 vs lib/tork/driver.rb in tork-18.0.0

- old
+ new

@@ -1,132 +1,55 @@ require 'set' -require 'diff/lcs' require 'tork/client' -require 'tork/server' +require 'tork/engine' require 'tork/config' module Tork -module Driver +class Driver < Engine - extend Server - extend self + def initialize + super - def run_all_test_files - run_test_files Dir[*Config.all_test_file_globs] - end - - def stop_running_test_files - @master.send [:stop] - @running_test_files.clear - end - - def rerun_passed_test_files - run_test_files @passed_test_files - end - - def rerun_failed_test_files - run_test_files @failed_test_files - end - - def reabsorb_overhead_files - @master.quit if defined? @master - - @master = Client::Transceiver.new('tork-master') do |message| - event, file, line_numbers = message - - case event.to_sym - when :test - @waiting_test_files.delete file - @running_test_files.add file - - when :pass - @running_test_files.delete file - - # only whole test file runs qualify as pass - if line_numbers.empty? - @failed_test_files.delete file - @passed_test_files.add file - end - - when :fail - @running_test_files.delete file - @failed_test_files.add file - @passed_test_files.delete file - end - - @client.send message # propagate output downstream - Config.test_event_hooks.each {|hook| hook.call message } - end - - @master.send [:load, Config.overhead_load_paths, - Dir[*Config.overhead_file_globs]] - - rerun_running_test_files - end - - def loop - reabsorb_overhead_files - @herald = Client::Transceiver.new('tork-herald') do |changed_files| - warn "#{$0}(#{$$}): FILE BATCH #{changed_files.size}" if $DEBUG changed_files.each do |changed_file| - warn "#{$0}(#{$$}): FILE #{changed_file}" if $DEBUG - # find and run the tests that correspond to the changed file - Config.test_file_globbers.each do |regexp, globber| - if regexp =~ changed_file and globs = globber.call(changed_file, $~) - run_test_files Dir[*globs] + visited = Set.new + visitor = lambda do |source_file| + Config.test_file_globbers.each do |regexp, globber| + if regexp =~ source_file and globs = globber.call($~) + Dir[*globs].each do |test_file| + if visited.add? test_file + run_test_file test_file + visitor.call test_file + end + end + end end end + visitor.call changed_file # reabsorb text execution overhead if overhead files changed if Config.reabsorb_file_greps.any? {|r| r =~ changed_file } @client.send [:over, changed_file] - # NOTE: new thread because reabsorb_overhead_files will kill this one - Thread.new { reabsorb_overhead_files }.join + reabsorb_overhead_files end end end - super + reabsorb_overhead_files + end + def quit @herald.quit - @master.quit + super end -private - - @waiting_test_files = Set.new - @running_test_files = Set.new - @passed_test_files = Set.new - @failed_test_files = Set.new - - def rerun_running_test_files - run_test_files @running_test_files + def run_all_test_files + run_test_files Dir[*Config.all_test_file_globs] end - def run_test_files files - files.each {|f| run_test_file f } - end - - def run_test_file file - if File.exist? file and @waiting_test_files.add? file - @master.send [:test, file, find_changed_line_numbers(file)] - end - end - - @lines_by_file = {} - - def find_changed_line_numbers test_file - # cache the contents of the test file for diffing below - new_lines = File.readlines(test_file) - old_lines = @lines_by_file[test_file] || new_lines - @lines_by_file[test_file] = new_lines - - # find which line numbers have changed inside the test file - Diff::LCS.diff(old_lines, new_lines).flatten. - # +1 because line numbers start at 1, not 0 - map {|change| change.position + 1 }.uniq + def reabsorb_overhead_files + reabsorb_overhead Config.overhead_load_paths, Dir[*Config.overhead_file_globs] end end end