File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1294,7 +1294,15 @@ def banner
12941294 # to $0.
12951295 #
12961296 def program_name
1297- @program_name || File . basename ( $0, '.*' )
1297+ @program_name || strip_ext ( File . basename ( $0) )
1298+ end
1299+
1300+ private def strip_ext ( name ) # :nodoc:
1301+ exts = /#{
1302+ require "rbconfig"
1303+ Regexp . union ( RbConfig ::CONFIG [ "EXECUTABLE_EXTS" ] )
1304+ } \z /o
1305+ name . sub ( exts , "" )
12981306 end
12991307
13001308 # for experimental cascading :-)
Original file line number Diff line number Diff line change @@ -216,4 +216,16 @@ def stdout.tty?; true; end
216216 end
217217 end
218218 end
219+
220+ def test_program_name
221+ program = $0
222+ $0 = "rdbg3.5"
223+ assert_equal "rdbg3.5" , OptionParser . new . program_name
224+ RbConfig ::CONFIG [ "EXECUTABLE_EXTS" ] . split ( " " ) do |ext |
225+ $0 = "rdbg3.5" + ext
226+ assert_equal "rdbg3.5" , OptionParser . new . program_name
227+ end
228+ ensure
229+ $0 = program
230+ end
219231end
You can’t perform that action at this time.
0 commit comments