Skip to content

Commit b7b17c4

Browse files
committed
Start adding tests for bazel_platforms
1 parent 3d13ae8 commit b7b17c4

File tree

4 files changed

+100
-59
lines changed

4 files changed

+100
-59
lines changed

haskell/private/bazel_platforms.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# implementation for get_cpu_value in lib_cc_configure.bzl.
55
# https://github.com/bazelbuild/bazel/blob/e11506feaea7401c3d27f55b47183ef49bd1d5a8/tools/cpp/lib_cc_configure.bzl#L186
66

7-
# TODO(chuck): Add unit tests.
8-
97
def _get_os(os_cpu):
108
if os_cpu.find("darwin") >= 0:
119
return "osx"

rules_haskell_nix/shell.nix

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/haskell_tests/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load(":bazel_platforms_tests.bzl", "bazel_platforms_test_suite")
2+
3+
bazel_platforms_test_suite()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""Tests for `bazel_platforms` module."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
load("//haskell:private/bazel_platforms.bzl", "bazel_platforms")
5+
6+
def _get_os_test(ctx):
7+
env = unittest.begin(ctx)
8+
9+
tests = [
10+
struct(
11+
msg = "darwin (legacy MacOS on x86_64)",
12+
os_cpu = "darwin",
13+
exp = "osx",
14+
),
15+
struct(
16+
os_cpu = "darwin_x86_64",
17+
exp = "osx",
18+
),
19+
struct(
20+
os_cpu = "darwin_arm64",
21+
exp = "osx",
22+
),
23+
struct(
24+
os_cpu = "arm64_windows",
25+
exp = "windows",
26+
),
27+
struct(
28+
os_cpu = "x64_windows",
29+
exp = "windows",
30+
),
31+
struct(
32+
os_cpu = "freebsd",
33+
exp = "linux",
34+
),
35+
struct(
36+
os_cpu = "openbsd",
37+
exp = "linux",
38+
),
39+
]
40+
for t in tests:
41+
actual = bazel_platforms.get_os(t.os_cpu)
42+
msg = getattr(t, "msg", t.os_cpu)
43+
asserts.equals(env, t.exp, actual, msg)
44+
45+
return unittest.end(env)
46+
47+
get_os_test = unittest.make(_get_os_test)
48+
49+
def _get_cpu_test(ctx):
50+
env = unittest.begin(ctx)
51+
52+
tests = [
53+
struct(
54+
msg = "darwin (legacy MacOS on x86_64)",
55+
os_cpu = "darwin",
56+
exp = "x86_64",
57+
),
58+
struct(
59+
os_cpu = "darwin_x86_64",
60+
exp = "x86_64",
61+
),
62+
struct(
63+
os_cpu = "darwin_arm64",
64+
exp = "arm64",
65+
),
66+
struct(
67+
os_cpu = "arm64_windows",
68+
exp = "arm64",
69+
),
70+
struct(
71+
os_cpu = "x64_windows",
72+
exp = "x86_64",
73+
),
74+
struct(
75+
os_cpu = "freebsd",
76+
exp = "x86_64",
77+
),
78+
struct(
79+
os_cpu = "openbsd",
80+
exp = "x86_64",
81+
),
82+
]
83+
for t in tests:
84+
actual = bazel_platforms.get_cpu(t.os_cpu)
85+
msg = getattr(t, "msg", t.os_cpu)
86+
asserts.equals(env, t.exp, actual, msg)
87+
88+
return unittest.end(env)
89+
90+
get_cpu_test = unittest.make(_get_cpu_test)
91+
92+
def bazel_platforms_test_suite(name = "bazel_platforms_tests"):
93+
return unittest.suite(
94+
name,
95+
get_os_test,
96+
get_cpu_test,
97+
)

0 commit comments

Comments
 (0)