From 5d0103f9731f54285fe716137697cea7c0cfd3ab Mon Sep 17 00:00:00 2001 From: mame Date: Wed, 10 Jan 2018 13:30:22 +0000 Subject: [PATCH] spec/ruby/library/etc/getlogin_spec.rb: Use `logname` as an expected result It had used `id -un`, but it is not always equal to `Etc.getlogin`. `id` returns the current user of the process, and `Etc.getlogin` returns the user name logged in on the controlling terminal of the process. This change uses `logname` by default. `id` remains as a fallback since there seem to be some platforms where `logname` is not available: https://github.com/ruby/spec/commit/49576b417ca3704cfb8271d2545c06c076c10cbc git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/library/etc/getlogin_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/ruby/library/etc/getlogin_spec.rb b/spec/ruby/library/etc/getlogin_spec.rb index 43e654bda6..f5da1039f5 100644 --- a/spec/ruby/library/etc/getlogin_spec.rb +++ b/spec/ruby/library/etc/getlogin_spec.rb @@ -18,7 +18,12 @@ describe "Etc.getlogin" do else # Etc.getlogin returns the same result of logname(2) # if it returns non NULL - Etc.getlogin.should == `id -un`.chomp + if system("which logname", out: File::NULL, err: File::NULL) + Etc.getlogin.should == `logname`.chomp + else + # fallback to `id` command since `logname` is not available + Etc.getlogin.should == `id -un`.chomp + end end else # Etc.getlogin may return nil if the login name is not set