#!/usr/bin/env ruby =begin TORK 1 2012-01-25 15.1.0 ============================================================================== 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` Display this help manual using man(1). SEE ALSO ------------------------------------------------------------------------------ tork(1), tork-driver(1), tork-master(1), tork-herald(1) =end ========================================================================= $0 = File.basename(__FILE__) # for easier indentification 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 |line| evstr, *details = JSON.load(line) event = evstr.to_sym case event when :load then warn 'tork: Overhead absorbed. Ready for testing!' when :over then warn 'tork: Reabsorbing changed overhead files...' else test_file, test_names, *details = details message = [evstr.upcase, test_file, test_names.inspect, details].join(' ') color = case event 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(test_file + '.log'), message] if event == :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.chomp if command = COMMANDS[key] 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