Skip to content

Commit 323c070

Browse files
committed
platform: Set _GO_PLATFORM_VERSION_ID via uname -r
This is in preparation for adding a new `goinfo` command to emit version and platform information, which will be useful in generating bug reports.
1 parent 64cddaf commit 323c070

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

lib/platform

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ _@go.platform_ostype() {
5656
_GO_PLATFORM_ID="$OSTYPE"
5757
;;
5858
esac
59+
60+
if command -v 'uname' >/dev/null; then
61+
_GO_PLATFORM_VERSION_ID="$(uname -r)"
62+
fi
5963
}
6064

6165
_@go.platform() {

tests/platform.bats

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@ setup() {
1212
' printf "%s=\"%s\"\n" "$var" "${!var}"' \
1313
'done'
1414
export __GO_ETC_OS_RELEASE="$BATS_TEST_ROOTDIR/os-release"
15+
16+
stub_program_in_path 'uname' \
17+
'if [[ "$*" == "-r" ]]; then' \
18+
' printf "$TEST_UNAME_VERSION\n"' \
19+
'fi'
20+
21+
stub_program_in_path 'git' \
22+
'if [[ "$*" == "--version" ]]; then' \
23+
' printf "git version %s\n" "$TEST_GIT_VERSION"' \
24+
'fi'
1525
}
1626

1727
teardown() {
28+
restore_programs_in_path 'git' 'uname'
1829
@go.remove_test_go_rootdir
1930
}
2031

@@ -38,29 +49,45 @@ teardown() {
3849
'_GO_PLATFORM_VERSION_ID="666"'
3950
}
4051

41-
@test "$SUITE: set _GO_PLATFORM_ID from OSTYPE" {
42-
OSTYPE='foobar' run "$TEST_GO_SCRIPT"
43-
assert_success '_GO_PLATFORM_ID="foobar"'
52+
@test "$SUITE: set _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, uname -r" {
53+
OSTYPE='foobar' TEST_UNAME_VERSION='3.27' run "$TEST_GO_SCRIPT"
54+
assert_success
55+
assert_lines_equal \
56+
'_GO_PLATFORM_ID="foobar"' \
57+
'_GO_PLATFORM_VERSION_ID="3.27"'
4458
}
4559

46-
@test "$SUITE: set _GO_PLATFORM_ID to macos from OSTYPE" {
47-
OSTYPE='darwin16' run "$TEST_GO_SCRIPT"
48-
assert_success '_GO_PLATFORM_ID="macos"'
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"
62+
assert_success
63+
assert_lines_equal \
64+
'_GO_PLATFORM_ID="macos"' \
65+
'_GO_PLATFORM_VERSION_ID="17.0.0"'
4966
}
5067

51-
@test "$SUITE: set _GO_PLATFORM_ID to freebsd from OSTYPE" {
52-
OSTYPE='freebsd11.0' run "$TEST_GO_SCRIPT"
53-
assert_success '_GO_PLATFORM_ID="freebsd"'
68+
@test "$SUITE: freebsd _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, uname -r" {
69+
OSTYPE='freebsd11.0' TEST_UNAME_VERSION='11.1-RELEASE-p1' \
70+
run "$TEST_GO_SCRIPT"
71+
assert_success
72+
assert_lines_equal \
73+
'_GO_PLATFORM_ID="freebsd"' \
74+
'_GO_PLATFORM_VERSION_ID="11.1-RELEASE-p1"'
5475
}
5576

56-
@test "$SUITE: set _GO_PLATFORM_ID to msys from OSTYPE" {
57-
stub_program_in_path 'git' 'printf "%s\n" "git version 2.13.0"'
58-
OSTYPE='msys' run "$TEST_GO_SCRIPT"
59-
assert_success '_GO_PLATFORM_ID="msys"'
77+
@test "$SUITE: msys _GO_PLATFORM_{ID,VERSION_ID} from OSTYPE, uname -r" {
78+
OSTYPE='msys' TEST_UNAME_VERSION='2.9.0(0.318/5/3)' \
79+
TEST_GIT_VERSION='2.14.2' run "$TEST_GO_SCRIPT"
80+
assert_success
81+
assert_lines_equal \
82+
'_GO_PLATFORM_ID="msys"' \
83+
'_GO_PLATFORM_VERSION_ID="2.9.0(0.318/5/3)"'
6084
}
6185

62-
@test "$SUITE: set _GO_PLATFORM_ID to msys-git from OSTYPE and git --version" {
63-
stub_program_in_path 'git' 'printf "%s\n" "git version 2.13.0.windows.1"'
64-
OSTYPE='msys' run "$TEST_GO_SCRIPT"
65-
assert_success '_GO_PLATFORM_ID="msys-git"'
86+
@test "$SUITE: msys-git _GO_PLATFORM_* from OSTYPE, git --version, uname -r" {
87+
OSTYPE='msys' TEST_UNAME_VERSION='2.8.0(0.310/5/3)' \
88+
TEST_GIT_VERSION='git version 2.13.0.windows.1' run "$TEST_GO_SCRIPT"
89+
assert_success
90+
assert_lines_equal \
91+
'_GO_PLATFORM_ID="msys-git"' \
92+
'_GO_PLATFORM_VERSION_ID="2.8.0(0.310/5/3)"'
6693
}

0 commit comments

Comments
 (0)