diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /autotest | |
parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'autotest')
-rw-r--r-- | autotest/discover.rb | 4 | ||||
-rw-r--r-- | autotest/puppet_rspec.rb | 84 | ||||
-rw-r--r-- | autotest/rspec.rb | 108 | ||||
-rw-r--r-- | autotest/watcher.rb | 158 |
4 files changed, 177 insertions, 177 deletions
diff --git a/autotest/discover.rb b/autotest/discover.rb index 528f6cc10..0ac563724 100644 --- a/autotest/discover.rb +++ b/autotest/discover.rb @@ -1,9 +1,9 @@ require 'autotest' Autotest.add_discovery do - "rspec" + "rspec" end Autotest.add_discovery do - "puppet" + "puppet" end diff --git a/autotest/puppet_rspec.rb b/autotest/puppet_rspec.rb index 1504d453d..eda9cb534 100644 --- a/autotest/puppet_rspec.rb +++ b/autotest/puppet_rspec.rb @@ -2,50 +2,50 @@ require 'autotest' require 'autotest/rspec' Autotest.add_hook :initialize do |at| - at.clear_mappings - - # the libraries under lib/puppet - at.add_mapping(%r{^lib/puppet/(.*)\.rb$}) { |filename, m| - at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb! - } - - # the actual spec files themselves - at.add_mapping(%r{^spec/(unit|integration)/.*\.rb$}) { |filename, _| - filename - } - - # force a complete re-run for all of these: - - # main puppet lib - at.add_mapping(%r{^lib/puppet\.rb$}) { |filename, _| - at.files_matching %r{spec/(unit|integration)/.*\.rb} - } - - # the spec_helper - at.add_mapping(%r{^spec/spec_helper\.rb$}) { |filename, _| - at.files_matching %r{spec/(unit|integration)/.*\.rb} - } - - # the puppet test libraries - at.add_mapping(%r{^test/lib/puppettest/.*}) { |filename, _| - at.files_matching %r{spec/(unit|integration)/.*\.rb} - } - - # the puppet spec libraries - at.add_mapping(%r{^spec/lib/spec.*}) { |filename, _| - at.files_matching %r{spec/(unit|integration)/.*\.rb} - } - - # the monkey patches for rspec - at.add_mapping(%r{^spec/lib/monkey_patches/.*}) { |filename, _| - at.files_matching %r{spec/(unit|integration)/.*\.rb} - } + at.clear_mappings + + # the libraries under lib/puppet + at.add_mapping(%r{^lib/puppet/(.*)\.rb$}) { |filename, m| + at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb! + } + + # the actual spec files themselves + at.add_mapping(%r{^spec/(unit|integration)/.*\.rb$}) { |filename, _| + filename + } + + # force a complete re-run for all of these: + + # main puppet lib + at.add_mapping(%r{^lib/puppet\.rb$}) { |filename, _| + at.files_matching %r{spec/(unit|integration)/.*\.rb} + } + + # the spec_helper + at.add_mapping(%r{^spec/spec_helper\.rb$}) { |filename, _| + at.files_matching %r{spec/(unit|integration)/.*\.rb} + } + + # the puppet test libraries + at.add_mapping(%r{^test/lib/puppettest/.*}) { |filename, _| + at.files_matching %r{spec/(unit|integration)/.*\.rb} + } + + # the puppet spec libraries + at.add_mapping(%r{^spec/lib/spec.*}) { |filename, _| + at.files_matching %r{spec/(unit|integration)/.*\.rb} + } + + # the monkey patches for rspec + at.add_mapping(%r{^spec/lib/monkey_patches/.*}) { |filename, _| + at.files_matching %r{spec/(unit|integration)/.*\.rb} + } end # a place for overrides when necessary. class Autotest::PuppetRspec < Autotest::Rspec - def spec_commands - ENV["AUTOTEST"] = "true" - ENV["PATH"].split(File::PATH_SEPARATOR).collect { |dir| File.join(dir, "spec") } - end + def spec_commands + ENV["AUTOTEST"] = "true" + ENV["PATH"].split(File::PATH_SEPARATOR).collect { |dir| File.join(dir, "spec") } + end end diff --git a/autotest/rspec.rb b/autotest/rspec.rb index 0c6334d56..f97e9668f 100644 --- a/autotest/rspec.rb +++ b/autotest/rspec.rb @@ -1,74 +1,74 @@ require 'autotest' Autotest.add_hook :initialize do |at| - at.clear_mappings - # watch out: Ruby bug (1.8.6): - # %r{/} != /\// - at.add_mapping(%r{^spec/.*\.rb$}) { |filename, _| - filename - } - at.add_mapping(%r{^lib/(.*)\.rb$}) { |_, m| - ["spec/#{m[1]}_spec.rb"] - } - at.add_mapping(%r{^spec/(spec_helper|shared/.*)\.rb$}) { - at.files_matching %r{^spec/.*_spec\.rb$} - } + at.clear_mappings + # watch out: Ruby bug (1.8.6): + # %r{/} != /\// + at.add_mapping(%r{^spec/.*\.rb$}) { |filename, _| + filename + } + at.add_mapping(%r{^lib/(.*)\.rb$}) { |_, m| + ["spec/#{m[1]}_spec.rb"] + } + at.add_mapping(%r{^spec/(spec_helper|shared/.*)\.rb$}) { + at.files_matching %r{^spec/.*_spec\.rb$} + } end class RspecCommandError < StandardError; end class Autotest::Rspec < Autotest - def initialize - super + def initialize + super - self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m - self.completed_re = /\Z/ # FIX: some sort of summary line at the end? - end + self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m + self.completed_re = /\Z/ # FIX: some sort of summary line at the end? + end - def consolidate_failures(failed) - filters = Hash.new { |h,k| h[k] = [] } - failed.each do |spec, failed_trace| - if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } - filters[f] << spec - break - end - end - filters + def consolidate_failures(failed) + filters = Hash.new { |h,k| h[k] = [] } + failed.each do |spec, failed_trace| + if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } + filters[f] << spec + break + end end + filters + end - def make_test_cmd(files_to_test) - "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" - end + def make_test_cmd(files_to_test) + "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}" + end - def add_options_if_present - File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : "" - end + def add_options_if_present + File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : "" + end - # Finds the proper spec command to use. Precendence is set in the - # lazily-evaluated method spec_commands. Alias + Override that in - # ~/.autotest to provide a different spec command then the default - # paths provided. - def spec_command(separator=File::ALT_SEPARATOR) - unless defined?(@spec_command) - @spec_command = spec_commands.find { |cmd| File.exists? cmd } + # Finds the proper spec command to use. Precendence is set in the + # lazily-evaluated method spec_commands. Alias + Override that in + # ~/.autotest to provide a different spec command then the default + # paths provided. + def spec_command(separator=File::ALT_SEPARATOR) + unless defined?(@spec_command) + @spec_command = spec_commands.find { |cmd| File.exists? cmd } - raise RspecCommandError, "No spec command could be found!" unless @spec_command + raise RspecCommandError, "No spec command could be found!" unless @spec_command - @spec_command.gsub! File::SEPARATOR, separator if separator - end - @spec_command + @spec_command.gsub! File::SEPARATOR, separator if separator end + @spec_command + end - # Autotest will look for spec commands in the following - # locations, in this order: - # - # * bin/spec - # * default spec bin/loader installed in Rubygems - def spec_commands - [ - File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')), - File.join(Config::CONFIG['bindir'], 'spec') - ] - end + # Autotest will look for spec commands in the following + # locations, in this order: + # + # * bin/spec + # * default spec bin/loader installed in Rubygems + def spec_commands + [ + File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')), + File.join(Config::CONFIG['bindir'], 'spec') + ] + end end diff --git a/autotest/watcher.rb b/autotest/watcher.rb index 99a7d1bb7..9f89a448c 100644 --- a/autotest/watcher.rb +++ b/autotest/watcher.rb @@ -2,137 +2,137 @@ ENV["WATCHR"] = "1" ENV['AUTOTEST'] = 'true' def run_comp(cmd) - puts cmd - results = [] - old_sync = $stdout.sync - $stdout.sync = true - line = [] - begin - open("| #{cmd}", "r") do |f| - until f.eof? do - c = f.getc - putc c - line << c - if c == ?\n - results << if RUBY_VERSION >= "1.9" then - line.join - else - line.pack "c*" - end - line.clear - end - end + puts cmd + results = [] + old_sync = $stdout.sync + $stdout.sync = true + line = [] + begin + open("| #{cmd}", "r") do |f| + until f.eof? do + c = f.getc + putc c + line << c + if c == ?\n + results << if RUBY_VERSION >= "1.9" then + line.join + else + line.pack "c*" + end + line.clear end - ensure - $stdout.sync = old_sync + end end - results.join + ensure + $stdout.sync = old_sync + end + results.join end def clear - #system("clear") + #system("clear") end def growl(message, status) - # Strip the color codes - message.gsub!(/\[\d+m/, '') - - growlnotify = `which growlnotify`.chomp - return if growlnotify.empty? - title = "Watchr Test Results" - image = status == :pass ? "autotest/images/pass.png" : "autotest/images/fail.png" - options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" - system %(#{growlnotify} #{options} &) + # Strip the color codes + message.gsub!(/\[\d+m/, '') + + growlnotify = `which growlnotify`.chomp + return if growlnotify.empty? + title = "Watchr Test Results" + image = status == :pass ? "autotest/images/pass.png" : "autotest/images/fail.png" + options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" + system %(#{growlnotify} #{options} &) end def file2specs(file) - %w{spec/unit spec/integration}.collect { |d| - file.sub('lib/puppet', d) - }.find_all { |f| - File.exist?(f) - } + %w{spec/unit spec/integration}.collect { |d| + file.sub('lib/puppet', d) + }.find_all { |f| + File.exist?(f) + } end def file2test(file) - result = file.sub('lib/puppet', 'test') - return nil unless File.exist?(result) - result + result = file.sub('lib/puppet', 'test') + return nil unless File.exist?(result) + result end def run_spec(command) - clear - result = run_comp(command).split("\n").last - status = result.include?('0 failures') ? :pass : :fail - growl result, status + clear + result = run_comp(command).split("\n").last + status = result.include?('0 failures') ? :pass : :fail + growl result, status end def run_test(command) - clear - result = run_comp(command).split("\n").last - status = result.include?('0 failures, 0 errors') ? :pass : :fail - growl result.split("\n").last rescue nil + clear + result = run_comp(command).split("\n").last + status = result.include?('0 failures, 0 errors') ? :pass : :fail + growl result.split("\n").last rescue nil end def run_test_file(file) - run_test(%Q(#{file})) + run_test(%Q(#{file})) end def run_spec_files(files) - files = Array(files) - return if files.empty? - opts = File.readlines('spec/spec.opts').collect { |l| l.chomp }.join(" ") - run_spec("spec #{files.join(' ')}") + files = Array(files) + return if files.empty? + opts = File.readlines('spec/spec.opts').collect { |l| l.chomp }.join(" ") + run_spec("spec #{files.join(' ')}") end def run_all_tests - run_test("rake unit") + run_test("rake unit") end def run_all_specs - run_test("rake spec") + run_test("rake spec") end def run_suite - run_all_tests - run_all_specs + run_all_tests + run_all_specs end watch('spec/spec_helper.rb') { run_all_specs } watch(%r{^spec/(unit|integration)/.*\.rb$}) { |md| run_spec_files(md[0]) } watch(%r{^lib/puppet/(.*)\.rb$}) { |md| - run_spec_files(file2specs(md[0])) - if t = file2test(md[0]) - run_test_file(t) - end + run_spec_files(file2specs(md[0])) + if t = file2test(md[0]) + run_test_file(t) + end } watch(%r{^spec/lib/spec.*}) { |md| run_all_specs } watch(%r{^spec/lib/monkey_patches/.*}) { |md| run_all_specs } watch(%r{test/.+\.rb}) { |md| - if md[0] =~ /\/lib\// - run_all_tests - else - run_test_file(md[0]) - end + if md[0] =~ /\/lib\// + run_all_tests + else + run_test_file(md[0]) + end } # Ctrl-\ Signal.trap 'QUIT' do - puts " --- Running all tests ---\n\n" - run_suite + puts " --- Running all tests ---\n\n" + run_suite end @interrupted = false # Ctrl-C Signal.trap 'INT' do - if @interrupted - @wants_to_quit = true - abort("\n") - else - puts "Interrupt a second time to quit; wait for rerun of tests" - @interrupted = true - Kernel.sleep 1.5 - # raise Interrupt, nil # let the run loop catch it - run_suite - end + if @interrupted + @wants_to_quit = true + abort("\n") + else + puts "Interrupt a second time to quit; wait for rerun of tests" + @interrupted = true + Kernel.sleep 1.5 + # raise Interrupt, nil # let the run loop catch it + run_suite + end end |