Skip to content

Commit

Permalink
Add fallback for hostname if uname isn't available. (ruby#12655)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jan 28, 2025
1 parent baf22a0 commit d3abee7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion spec/ruby/library/socket/socket/gethostname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
require_relative '../fixtures/classes'

describe "Socket.gethostname" do
def system_hostname
# Most platforms implement this POSIX standard:
`uname -n`.strip
rescue
# Only really required for Windows without MSYS/MinGW/Cygwin etc:
`hostname`.strip
end

it "returns the host name" do
Socket.gethostname.should == `uname -n`.strip
Socket.gethostname.should == system_hostname
end
end

0 comments on commit d3abee7

Please sign in to comment.