#!/usr/bin/env ruby =begin ======================================================================= # TORK 1 2012-02-13 18.0.1 ## NAME tork - Continuous testing tool for Ruby ## SYNOPSIS `tork` [*OPTION*]... [*CONFIG*]... ## DESCRIPTION This program is a simple command-line user interface for tork-driver(1). It loads the given *CONFIG* files (which are either paths to actual files or names of helper libraries in the tork/config/ namespace of Ruby's load path) and then waits for you to supply interactive commands on its stdin. You may press the ENTER key (supplying no command) to see a menu of accepted commands. ## OPTIONS `-h`, `--help` Show this help manual. ## SEE ALSO tork(1), tork-driver(1), tork-master(1), tork-herald(1) =end ========================================================================= $0 = File.basename(__FILE__) # for easier identification in ps(1) output require 'binman' BinMan.help require 'json' ENV['TORK_CONFIGS'] = JSON.dump(ARGV) #----------------------------------------------------------------------------- # backend #----------------------------------------------------------------------------- require 'tork/client' warn 'tork: Absorbing test execution overhead...' @driver = Tork::Client::Transceiver.new('tork-driver') do |event, *details| case event_sym = event.to_sym when :load then warn 'tork: Overhead absorbed. Ready for testing!' when :over then warn 'tork: Reabsorbing changed overhead files...' else test_file, line_numbers, log_file, worker_number, exit_status = details message = [event.upcase, [test_file, *line_numbers].join(':'), exit_status].compact.join(' ') color = case event_sym when :pass then "\e[34m%s\e[0m" # blue when :fail then "\e[31m%s\e[0m" # red end message = color % message if color and STDOUT.tty? message = [message, File.read(log_file), message] if event_sym == :fail puts message end end #----------------------------------------------------------------------------- # frontend #----------------------------------------------------------------------------- COMMANDS = { 't' => :run_all_test_files, 's' => :stop_running_test_files, 'p' => :rerun_passed_test_files, 'f' => :rerun_failed_test_files, 'o' => :reabsorb_overhead_files, 'q' => :quit, } begin while key = STDIN.gets if command = COMMANDS[key.strip] warn "tork: Sending #{command.to_s.inspect} command..." @driver.send [command] break if command == :quit else # invalid command COMMANDS.each do |k, cmd| warn "tork: Type #{k} then ENTER to #{cmd.to_s.tr('_', ' ')}." end end end rescue Interrupt # forced quit end Process.waitall