#!/usr/bin/env ruby =begin TESTR 1 "2012-01-09" "14.1.2" ============================= NAME ---- testr - Continuous testing tool for Ruby SYNOPSIS -------- `testr` [*OPTION*]... DESCRIPTION ----------- This program is a simple command-line user interface for testr-driver(1). It demonstrates how the components of TestR work together and also serves as an example of how you can create your own TestR user interface. When run, it presents you with a menu of single-character commands that you can enter, loads the test execution overhead into testr-master(1), and finally notifies you when the master is ready to run test files. It also launches testr-herald(1) alongside testr-master(1). When the herald reports a modified file that belongs to the test execution overhead, this program notifies you accordingly and then replaces the current master with a new one that will absorb the modified test execution overhead into itself. OPTIONS ------- `-h`, `--help` Display this help manual using man(1). SEE ALSO -------- testr(1), testr-driver(1), testr-master(1), testr-herald(1) =end ========================================================================= $0 = File.basename(__FILE__) require 'binman' BinMan.help require 'json' require 'testr/client' @driver = TestR::Client::Transceiver.new('testr-driver') do |line| evstr, *details = JSON.load(line) event = evstr.to_sym case event when :load then warn 'testr: Overhead absorbed. Ready for testing!' when :over then warn 'testr: 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 COMMANDS = { 'r' => :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, } def COMMANDS.show each do |key, cmd| warn "testr: Type #{key} then ENTER to #{cmd.to_s.tr('_', ' ')}." end end COMMANDS.show # instruct newbies while key = STDIN.gets.chomp if command = COMMANDS[key] if command == :quit @driver.quit break else @driver.send [command] end else COMMANDS.show end end Process.waitall