Skip to content

Commit

Permalink
Improve System::User specs on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Nov 5, 2024
1 parent 563d6d2 commit 1702430
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions spec/std/system/user_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ require "spec"
require "system/user"

{% if flag?(:win32) %}
{% name, id = `whoami /USER /FO TABLE /NH`.stringify.chomp.split(" ") %}
USER_NAME = {{ name }}
USER_ID = {{ id }}
{% parts = `whoami /USER /FO TABLE /NH`.stringify.chomp.split(" ") %}
USER_NAME = {{ parts[0..-2].join(" ") }}
USER_ID = {{ parts[-1] }}
{% else %}
USER_NAME = {{ `id -un`.stringify.chomp }}
USER_ID = {{ `id -u`.stringify.chomp }}
Expand All @@ -17,8 +17,7 @@ def normalized_username(username)
# on Windows, domain names are case-insensitive, so we unify the letter case
# from sources like `whoami`, `hostname`, or Win32 APIs
{% if flag?(:win32) %}
domain, _, user = username.partition('\\')
"#{domain.upcase}\\#{user}"
username.upcase
{% else %}
username
{% end %}
Expand Down

0 comments on commit 1702430

Please sign in to comment.