sconover / wrong

Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail.
MIT License
434 stars 31 forks source link

Wrong::Config.read_here_or_higher can't handle absolute paths #16

Open shviller opened 12 years ago

shviller commented 12 years ago

read_here_or_higher doesn't expect its first argument to be an absolute path, which, on Windows, leads to inability to retrieve an assertion's source if it is located in a file other than the program's entry point.

The easiest way to reproduce is to create a file containing the following:

require 'wrong' include Wrong::Assert assert{false}

and then require it from irb. On Windows, instead of "Expected false (Wrong::Assert::AssertionFailedError)" you get "[couldn't retrieve source code due to #<Errno::EINVAL: Invalid argument - ./c:/absolute/path/to/your/file.rb>]"

alexch commented 12 years ago

To clarify, this is apparently only a problem on Windows. Can you also let us know what version of Ruby you're using?

On Sat, Jan 7, 2012 at 12:18 PM, shviller reply@reply.github.com wrote:

read_here_or_higher doesn't expect its first argument to be an absolute path, which, on Windows, leads to inability to retrieve an assertion's source if it is located in a file other than the program's entry point.

The easiest way to reproduce is to create a file containing the following:

 require 'wrong'  include Wrong::Assert  assert{false}

and then require it from irb. On Windows, instead of "Expected false (Wrong::Assert::AssertionFailedError)" you get "[couldn't retrieve source code due to #<Errno::EINVAL: Invalid argument - ./c:/absolute/path/to/your/file.rb>]"


Reply to this email directly or view it on GitHub: https://github.com/sconover/wrong/issues/16

Alex Chaffee - alex@stinky.com http://alexchaffee.com http://twitter.com/alexch

shviller commented 12 years ago

Yes, this doesn't cause a problem on Linux (weren't able to test it on a Mac). I've tested using Ruby 1.9.2p180 on Windows (Win7 32bit) and Ruby 1.9.2p0 on Linux (Debian 6.0.3 64bit).

muellerj commented 11 years ago

I can confirm the problem on Windows. The path seems to be prepended with an unneccessary ./, such that instead of C:/Users/muellerj/Sandbox/unitgolfstage/wrongtest.rb, the parser searches for ./C:/Users/muellerj/Sandbox/unitgolfstage/wrongtest.rb:

C:\Users\muellerj\Sandbox\unitgolfstage>cat wrongtest.rb
require 'wrong'
include Wrong::Assert
assert{false}
C:\Users\muellerj\Sandbox\unitgolfstage>irb
irb(main):001:0> require './wrongtest.rb'
RuntimeError: Failed at C:/Users/muellerj/Sandbox/unitgolfstage/wrongtest.rb:3 [couldn't retrieve so
urce code due to #<Errno::EINVAL: Invalid argument - ./C:/Users/muellerj/Sandbox/unitgolfstage/wrong
test.rb>]
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/chunk.rb:134:in `rescue in co
de'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/chunk.rb:130:in `code'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/failure_message.rb:51:in `bas
ic'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/failure_message.rb:57:in `ful
l'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/assert.rb:82:in `aver'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/wrong-0.6.3/lib/wrong/assert.rb:35:in `assert'
        from C:/Users/muellerj/Sandbox/unitgolfstage/wrongtest.rb:3:in `<top (required)>'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from (irb):1
        from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):002:0>
muellerj commented 11 years ago

Update: The following quick-and-dirty fix can be used to get things going temporarily:

if RUBY_PLATFORM.downcase =~ /(win|w)32$/
  class Wrong::Config
    def self.read_here_or_higher(file, dir = ".")
      File.read(file)
    end
  end
end