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
1294
1294
# to $0.
1295
1295
#
1296
1296
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 , "" )
1298
1306
end
1299
1307
1300
1308
# for experimental cascading :-)
Original file line number Diff line number Diff line change @@ -216,4 +216,16 @@ def stdout.tty?; true; end
216
216
end
217
217
end
218
218
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
219
231
end
You can’t perform that action at this time.
0 commit comments