Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/wrong/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module Wrong

def self.load_config
Expand All @@ -25,7 +24,7 @@ class ConfigError < RuntimeError
end

def self.read_here_or_higher(file, dir = ".")
File.read "#{dir}/#{file}"
File.read get_file_path(file, dir)
rescue Errno::ENOENT, Errno::EACCES => e
# we may be in a chdir underneath where the file is, so move up one level and try again
parent = "#{dir}/..".gsub(/^(\.\/)*/, '')
Expand All @@ -35,6 +34,14 @@ def self.read_here_or_higher(file, dir = ".")
read_here_or_higher(file, parent)
end

def self.get_file_path(file, dir)
if File.file?(file)
file
else
"#{dir}/#{file}"
end
end

def initialize(string = nil)
self[:aliases] = {:assert => [:assert], :deny => [:deny]}
if string
Expand Down
14 changes: 14 additions & 0 deletions test/chunk_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
end
end

describe "#read_source_file" do
it "handles absolute file paths" do
chunk = Wrong::Chunk.new(nil, 0)
f = File.new "abs_file_path_test_file.tmp", "w"
abs_path = File.absolute_path(f.path)
assert(chunk.read_source_file(abs_path).is_a? String)
end
it "handles relative file paths" do
chunk = Wrong::Chunk.new(nil, 0)
rel_path = './chunk_test.rb'
assert(chunk.read_source_file(rel_path).is_a? String)
end
end

describe "line numbers" do
before do
@chunk = Wrong::Chunk.new("foo.rb", 10)
Expand Down