Skip to content

Commit ca879ad

Browse files
committed
platform: Use sw_vers for VERSION_ID on macos
This corresponds with the value reported by "Apple > About This Mac".
1 parent 323c070 commit ca879ad

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/platform

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ _@go.platform_ostype() {
4242
case "$OSTYPE" in
4343
darwin*)
4444
_GO_PLATFORM_ID='macos'
45+
_GO_PLATFORM_VERSION_ID="$(sw_vers -productVersion)"
4546
;;
4647
freebsd*)
4748
_GO_PLATFORM_ID='freebsd'
@@ -57,7 +58,7 @@ _@go.platform_ostype() {
5758
;;
5859
esac
5960

60-
if command -v 'uname' >/dev/null; then
61+
if [[ -z "$_GO_PLATFORM_VERSION_ID" ]] && command -v 'uname' >/dev/null; then
6162
_GO_PLATFORM_VERSION_ID="$(uname -r)"
6263
fi
6364
}

tests/platform.bats

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ setup() {
1313
'done'
1414
export __GO_ETC_OS_RELEASE="$BATS_TEST_ROOTDIR/os-release"
1515

16+
stub_program_in_path 'sw_vers' \
17+
'if [[ "$*" == "-productVersion" ]]; then' \
18+
' printf "$TEST_MACOS_VERSION\n"' \
19+
'fi'
20+
1621
stub_program_in_path 'uname' \
1722
'if [[ "$*" == "-r" ]]; then' \
1823
' printf "$TEST_UNAME_VERSION\n"' \
@@ -25,7 +30,7 @@ setup() {
2530
}
2631

2732
teardown() {
28-
restore_programs_in_path 'git' 'uname'
33+
restore_programs_in_path 'git' 'uname' 'sw_vers'
2934
@go.remove_test_go_rootdir
3035
}
3136

@@ -57,12 +62,13 @@ teardown() {
5762
'_GO_PLATFORM_VERSION_ID="3.27"'
5863
}
5964

60-
@test "$SUITE: macos _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, uname -r" {
61-
OSTYPE='darwin16.3.0' TEST_UNAME_VERSION='17.0.0' run "$TEST_GO_SCRIPT"
65+
@test "$SUITE: macos _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, sw_vers" {
66+
OSTYPE='darwin16.3.0' TEST_UNAME_VERSION='17.0.0' \
67+
TEST_MACOS_VERSION='10.13' run "$TEST_GO_SCRIPT"
6268
assert_success
6369
assert_lines_equal \
6470
'_GO_PLATFORM_ID="macos"' \
65-
'_GO_PLATFORM_VERSION_ID="17.0.0"'
71+
'_GO_PLATFORM_VERSION_ID="10.13"'
6672
}
6773

6874
@test "$SUITE: freebsd _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, uname -r" {

0 commit comments

Comments
 (0)