Issue #14144 has been updated by keithrbennett (Keith Bennett).


Thanks for that recognition. I've also put it on Stack Overflow at https://stackoverflow.com/questions/47584283/file-pointing-to-the-wrong-file-in-ruby-2-4-1-under-rvm/47584284#47584284 for that same reason.

----------------------------------------
Bug #14144: __FILE__ displays wrong value for executables when run from project root w/Ruby 2.4.1
https://bugs.ruby-lang.org/issues/14144#change-68130

* Author: keithrbennett (Keith Bennett)
* Status: Third Party's Issue
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This problem can be illustrated by using the attached tar file, or the Github repo at https://github.com/keithrbennett/underscore_file_test.

When Ruby version == 2.4.1
  and
current directory is the project root of this project
  and
the gem is built and installed
  and
the executable is run from the gem without preceding it with 'ruby'
  and
the executable is run without specifying a directory
(i.e. as 'underscore_file_test', not 'bin/underscore_file_test')

Then (FILE below should be FILE surrounded by double underscores)

```ruby
__FILE__ => $PROJECT_ROOT/exe/underscore_file_test
```
instead of pointing to a directory in the GEM_PATH, something like:

```ruby
__FILE__ => /Users/kbennett/.rvm/gems/ruby-2.4.1/bin/underscore_file_test
```

This error occurred with Ruby 2.4.1 but not:

* ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-darwin15.6.0]
* ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
* ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
* jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [darwin-x86_64]

My development machine was a MacBookPro running MacOs Sierra. `uname -a` output is:

* Darwin MacBook-Pro-KB-13.local 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct  4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64


## Steps to Reproduce:

* Download or git clone the Github project tree, or the attached tarball.
* Change directory to the project root.
* Run: `clear; gem build *gemspec && gem install *gem && underscore_file_test`
* Note the directory component of the output.

If you cd somewhere else, the output will be correct,
i.e. will be located in a GEM_PATH directory.

If you run the command from the project root using a different Ruby,
it may work. I have not tested this on versions _later than_ 2.4.1.


---Files--------------------------------
underscore_file_test.tar.gz (29.7 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>