diff --git a/bin/tork b/bin/tork index 59e60ff..869095f 100755 --- a/bin/tork +++ b/bin/tork @@ -46,7 +46,7 @@ This program can be controlled remotely by multiple tork-remote(1) instances. ## FILES *.tork/config.rb* - Optional Ruby script that is loaded inside the driver process on startup. + Optional Ruby script that is loaded inside this Tork process on startup. It can read and change the `ENV['TORK_CONFIGS']` environment variable. ## ENVIRONMENT @@ -54,21 +54,7 @@ This program can be controlled remotely by multiple tork-remote(1) instances. `TORK_CONFIGS` Colon-separated (:) list of either paths to directories that contain configuration files or names of the following configuration helpers. - If this variable is not set, then its value is assumed to be "default". - > `default` - > Loads the following configuration helpers (as appropriate) if your - > current working directory appears to utilize what they configure. - > See below for complete descriptions of these configuration helpers. - > - > * bundler - > * rails - > * devise - > * test - > * spec - > * cucumber - > * factory_girl - > > `dotlog` > Hides log files by prefixing their names with a period (dot). > @@ -129,6 +115,7 @@ tork-runner(1), tork-driver(1), tork-master(1) =end ========================================================================= +TORK_DOLLAR_ZERO = $0 $0 = File.basename(__FILE__) # for easier identification in ps(1) output require 'binman' diff --git a/bin/tork-driver b/bin/tork-driver index 1c16635..7eda1c5 100755 --- a/bin/tork-driver +++ b/bin/tork-driver @@ -51,7 +51,7 @@ to stdout. ## FILES *.tork/config.rb* - Optional Ruby script that is loaded inside the driver process on startup. + Optional Ruby script that is loaded inside this Tork process on startup. It can read and change the `ENV['TORK_CONFIGS']` environment variable. `.tork/driver.rb` diff --git a/bin/tork-engine b/bin/tork-engine index fd41a1b..eef001e 100755 --- a/bin/tork-engine +++ b/bin/tork-engine @@ -76,7 +76,7 @@ to stdout. ## FILES *.tork/config.rb* - Optional Ruby script that is loaded inside the driver process on startup. + Optional Ruby script that is loaded inside this Tork process on startup. It can read and change the `ENV['TORK_CONFIGS']` environment variable. *.tork/engine.rb* diff --git a/bin/tork-master b/bin/tork-master index 277a8ca..99f7a4a 100755 --- a/bin/tork-master +++ b/bin/tork-master @@ -66,7 +66,7 @@ to stdout. ## FILES *.tork/config.rb* - Optional Ruby script that is loaded inside the driver process on startup. + Optional Ruby script that is loaded inside this Tork process on startup. It can read and change the `ENV['TORK_CONFIGS']` environment variable. *.tork/master.rb* diff --git a/lib/tork/cliapp.rb b/lib/tork/cliapp.rb index de8ffc0..71109b8 100644 --- a/lib/tork/cliapp.rb +++ b/lib/tork/cliapp.rb @@ -18,6 +18,10 @@ def join client help client end + BACKTRACE_CENSOR = /\n\s+(?:from\s)?#{ + Regexp.union(File.expand_path('../../..', __FILE__), TORK_DOLLAR_ZERO) + }[^:]*:\d+:.+$/ + def recv client, message case client when @driver @@ -40,7 +44,12 @@ def recv client, message 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 + + if event_sym == :fail + # censor Tork internals from test failure backtraces + log = File.read(log_file).gsub(BACKTRACE_CENSOR, '') + message = [message, log, message] + end tell @clients, message, false end diff --git a/lib/tork/config.rb b/lib/tork/config.rb index 3cb17f8..96a3b7a 100644 --- a/lib/tork/config.rb +++ b/lib/tork/config.rb @@ -1,17 +1,17 @@ module Tork # Loads all Ruby scripts found having the given name in (1) the directories - # specified in the TORK_CONFIGS environment variable, (2) the subdirectories + # specified in the given $TORK_CONFIGS search path, (2) the subdirectories # of lib/tork/config/, and (3) the user's .tork/ directory; in that order. # # @return [Array] paths of Ruby scripts that were loaded # - def self.config name - dirs = ENV['TORK_CONFIGS'].strip.split(/:+/).reject(&:empty?).uniq. + def self.config name, search_path=ENV['TORK_CONFIGS'] + dirs = search_path.to_s.strip.split(/:+/).reject(&:empty?).uniq. map {|dir| [dir, __FILE__.sub(/\.rb$/, "/#{dir}")] }.flatten Dir["{#{dirs.join(',')},.tork}/#{name}.rb"].each {|script| load script } end end -ENV['TORK_CONFIGS'] ||= 'default'.freeze # ENV values come frozen by default -Tork.config :config +ENV['TORK_CONFIGS'] ||= String.new.freeze # ENV values come frozen by default +Tork.config :config, '*' diff --git a/lib/tork/config/bundler/config.rb b/lib/tork/config/bundler/config.rb new file mode 100644 index 0000000..2b9dfbc --- /dev/null +++ b/lib/tork/config/bundler/config.rb @@ -0,0 +1 @@ +ENV['TORK_CONFIGS'] += ':bundler' if Dir['Gemfile{,.lock}'].any? diff --git a/lib/tork/config/cucumber/config.rb b/lib/tork/config/cucumber/config.rb new file mode 100644 index 0000000..20117d3 --- /dev/null +++ b/lib/tork/config/cucumber/config.rb @@ -0,0 +1 @@ +ENV['TORK_CONFIGS'] += ':cucumber' if File.directory? 'features' diff --git a/lib/tork/config/default/config.rb b/lib/tork/config/default/config.rb deleted file mode 100644 index d0f7cb0..0000000 --- a/lib/tork/config/default/config.rb +++ /dev/null @@ -1,7 +0,0 @@ -ENV['TORK_CONFIGS'] += ':bundler' if Dir['Gemfile{,.lock}'].any? -ENV['TORK_CONFIGS'] += ':rails' if Dir['script/{rails,console}'].any? -ENV['TORK_CONFIGS'] += ':devise' if File.exist? 'config/initializers/devise.rb' -ENV['TORK_CONFIGS'] += ':test' if File.directory? 'test' -ENV['TORK_CONFIGS'] += ':spec' if File.directory? 'spec' -ENV['TORK_CONFIGS'] += ':cucumber' if File.directory? 'features' -ENV['TORK_CONFIGS'] += ':factory_girl' if Dir['{test,spec}/factories/'].any? diff --git a/lib/tork/config/devise/config.rb b/lib/tork/config/devise/config.rb new file mode 100644 index 0000000..1978d1f --- /dev/null +++ b/lib/tork/config/devise/config.rb @@ -0,0 +1 @@ +ENV['TORK_CONFIGS'] += ':devise' if File.exist? 'config/initializers/devise.rb' diff --git a/lib/tork/config/factory_girl/config.rb b/lib/tork/config/factory_girl/config.rb new file mode 100644 index 0000000..a3c897b --- /dev/null +++ b/lib/tork/config/factory_girl/config.rb @@ -0,0 +1 @@ +ENV['TORK_CONFIGS'] += ':factory_girl' if Dir['{test,spec}/factories/'].any? diff --git a/lib/tork/config/rails/config.rb b/lib/tork/config/rails/config.rb new file mode 100644 index 0000000..eef9621 --- /dev/null +++ b/lib/tork/config/rails/config.rb @@ -0,0 +1 @@ +ENV['TORK_CONFIGS'] += ':rails' if Dir['script/{rails,console}'].any? diff --git a/lib/tork/config/spec/config.rb b/lib/tork/config/spec/config.rb new file mode 100644 index 0000000..405c6af --- /dev/null +++ b/lib/tork/config/spec/config.rb @@ -0,0 +1,4 @@ +$tork_config_spec_glob = '**/{spec_*,*_spec}.rb' +$tork_config_spec_grep = %r{.*(\bspec_[^/]+|[^/]+_spec)\.rb$} + +ENV['TORK_CONFIGS'] += ':spec' if Dir['spec/', $tork_config_spec_glob].any? diff --git a/lib/tork/config/spec/driver.rb b/lib/tork/config/spec/driver.rb index 2f6ccc1..391467c 100644 --- a/lib/tork/config/spec/driver.rb +++ b/lib/tork/config/spec/driver.rb @@ -1,17 +1,13 @@ -Tork::Driver::REABSORB_FILE_GREPS.push 'spec/spec_helper.rb' +Tork::Driver::REABSORB_FILE_GREPS.push /\bspec_helper\.rb$/ -Tork::Driver::ALL_TEST_FILE_GLOBS.push 'spec/**/{spec_*,*_spec}.rb' +Tork::Driver::ALL_TEST_FILE_GLOBS.push $tork_config_spec_glob Tork::Driver::TEST_FILE_GLOBBERS.update( # source files that correspond to test files - %r{^lib/.*?([^/]+)\.rb$} => lambda do |matches| - target = matches[1] - "spec/**/{spec_#{target},#{target}_spec}.rb" + %r{([^/]+)\.rb$} => lambda do |matches| + $tork_config_spec_glob.gsub(/(?<=_)\*|\*(?=_)/, matches[1]) end, # the actual test files themselves - %r{^spec/.+\.rb$} => lambda do |matches| - target = matches[0] - target if File.basename(target) =~ /^spec_|_spec\./ - end + $tork_config_spec_grep => lambda {|matches| matches[0] } ) diff --git a/lib/tork/config/spec/master.rb b/lib/tork/config/spec/master.rb index c9651db..d76b3a6 100644 --- a/lib/tork/config/spec/master.rb +++ b/lib/tork/config/spec/master.rb @@ -1,4 +1,5 @@ $LOAD_PATH.unshift 'spec' unless $LOAD_PATH.include? 'spec' $LOAD_PATH.unshift 'lib' unless $LOAD_PATH.include? 'lib' require 'spec_helper' if File.exist? 'spec/spec_helper.rb' +require './spec_helper' if File.exist? 'spec_helper.rb' require 'rspec/autorun' if defined? RSpec diff --git a/lib/tork/config/spec/worker.rb b/lib/tork/config/spec/worker.rb index 032ea46..a9303c3 100644 --- a/lib/tork/config/spec/worker.rb +++ b/lib/tork/config/spec/worker.rb @@ -5,7 +5,7 @@ # ignore end -if $tork_test_file.start_with? 'spec/' and $tork_line_numbers.any? +if $tork_line_numbers.any? and $tork_test_file =~ $tork_config_spec_grep if rspec_version and rspec_version >= '3.0' ARGV.push [$tork_test_file, *$tork_line_numbers].join(':') else diff --git a/lib/tork/config/test/config.rb b/lib/tork/config/test/config.rb new file mode 100644 index 0000000..d9ea608 --- /dev/null +++ b/lib/tork/config/test/config.rb @@ -0,0 +1,10 @@ +# people generally prefix or suffix their test file names with these labels +# https://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing#Naming_Conventions +labels = %w[ test ts tc t ] +labels_glob = '{' + labels.join(',') + '}' +labels_grep = '(' + labels.join('|') + ')' + +$tork_config_test_glob = "**/{#{labels_glob}_*,*_#{labels_glob}}.rb" +$tork_config_test_grep = %r{.*(\b#{labels_grep}_[^/]+|[^/]+_#{labels_grep})\.rb$} + +ENV['TORK_CONFIGS'] += ':test' if Dir['test/', $tork_config_test_glob].any? diff --git a/lib/tork/config/test/driver.rb b/lib/tork/config/test/driver.rb index 1c8c940..63a9264 100644 --- a/lib/tork/config/test/driver.rb +++ b/lib/tork/config/test/driver.rb @@ -1,17 +1,13 @@ -Tork::Driver::REABSORB_FILE_GREPS.push 'test/test_helper.rb' +Tork::Driver::REABSORB_FILE_GREPS.push /\btest_helper\.rb$/ -Tork::Driver::ALL_TEST_FILE_GLOBS.push 'test/**/{test_*,*_test}.rb' +Tork::Driver::ALL_TEST_FILE_GLOBS.push $tork_config_test_glob Tork::Driver::TEST_FILE_GLOBBERS.update( # source files that correspond to test files - %r{^lib/.*?([^/]+)\.rb$} => lambda do |matches| - target = matches[1] - "test/**/{test_#{target},#{target}_test}.rb" + %r{([^/]+)\.rb$} => lambda do |matches| + $tork_config_test_glob.gsub(/(?<=_)\*|\*(?=_)/, matches[1]) end, # the actual test files themselves - %r{^test/.+\.rb$} => lambda do |matches| - target = matches[0] - target if File.basename(target) =~ /^test_|_test\./ - end + $tork_config_test_grep => lambda {|matches| matches[0] } ) diff --git a/lib/tork/config/test/master.rb b/lib/tork/config/test/master.rb index a79a9dc..cb7f9a6 100644 --- a/lib/tork/config/test/master.rb +++ b/lib/tork/config/test/master.rb @@ -1,4 +1,5 @@ $LOAD_PATH.unshift 'test' unless $LOAD_PATH.include? 'test' $LOAD_PATH.unshift 'lib' unless $LOAD_PATH.include? 'lib' require 'test_helper' if File.exist? 'test/test_helper.rb' +require './test_helper' if File.exist? 'test_helper.rb' require 'minitest/autorun' if defined? MiniTest diff --git a/lib/tork/config/test/worker.rb b/lib/tork/config/test/worker.rb index 2743879..56106e7 100644 --- a/lib/tork/config/test/worker.rb +++ b/lib/tork/config/test/worker.rb @@ -1,4 +1,4 @@ -if $tork_test_file.start_with? 'test/' and $tork_line_numbers.any? +if $tork_line_numbers.any? and $tork_test_file =~ $tork_config_test_grep test_file_lines = File.readlines($tork_test_file) test_names = $tork_line_numbers.map do |line| catch :found do