Skip to content

Commit

Permalink
add test for code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
josephholsten committed Aug 16, 2010
1 parent b58825b commit 31bdf65
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/test_quality.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env ruby -w
libdir = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)

require "test/unit"

class TestQuality < Test::Unit::TestCase
def test_can_still_be_built
Dir.chdir(root) do
`gem build rets4r.gemspec`
assert_equal 0, $?
end
end

def test_has_no_malformed_whitespace
error_messages = []
Dir.chdir(root) do
File.read("MANIFEST").split("\n").each do |filename|
error_messages << check_for_tab_characters(filename)
error_messages << check_for_extra_spaces(filename)
end
end
assert_well_formed error_messages.compact
end

def assert_well_formed(actual)
assert actual.empty?, actual.join("\n")
end

def check_for_tab_characters(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
failing_lines << number + 1 if line =~ /\t/
end

unless failing_lines.empty?
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
end
end

def check_for_extra_spaces(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
next if line =~ /^\s+#.*\s+\n$/
failing_lines << number + 1 if line =~ /\s+\n$/
end

unless failing_lines.empty?
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
end
end

def root
File.expand_path("../..", __FILE__)
end
end

0 comments on commit 31bdf65

Please sign in to comment.