ruby-changes:49643
From: mame <ko1@a...>
Date: Wed, 10 Jan 2018 22:30:28 +0900 (JST)
Subject: [ruby-changes:49643] mame:r61759 (trunk): spec/ruby/library/etc/getlogin_spec.rb: Use `logname` as an expected result
mame 2018-01-10 22:30:22 +0900 (Wed, 10 Jan 2018) New Revision: 61759 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61759 Log: 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 Modified files: trunk/spec/ruby/library/etc/getlogin_spec.rb Index: spec/ruby/library/etc/getlogin_spec.rb =================================================================== --- spec/ruby/library/etc/getlogin_spec.rb (revision 61758) +++ spec/ruby/library/etc/getlogin_spec.rb (revision 61759) @@ -18,7 +18,12 @@ describe "Etc.getlogin" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/etc/getlogin_spec.rb#L18 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/