Skip to content

Commit 371e243

Browse files
committed
add unit tests
1 parent 7e98584 commit 371e243

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

test/internal/xcschemes/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load(":info_constructors_tests.bzl", "info_constructors_test_suite")
33
load(":infos_from_json_tests.bzl", "infos_from_json_test_suite")
44
load(":write_schemes_tests.bzl", "write_schemes_test_suite")
5+
load(":xcschemes_base_tests.bzl", "xcschemes_base_test_suite")
56

67
info_constructors_test_suite(name = "info_constructors")
78

89
infos_from_json_test_suite(name = "infos_from_json")
910

1011
write_schemes_test_suite(name = "write_schemes")
1112

13+
xcschemes_base_test_suite(name = "xcschemes_base")
14+
1215
test_suite(name = "xcschemes")
1316

1417
bzl_library(
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""Tests for the `xcschemes` module."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
5+
# buildifier: disable=bzl-visibility
6+
load(
7+
"//xcodeproj/internal/xcschemes:xcschemes.bzl",
8+
"xcschemes",
9+
)
10+
11+
def _xcschemes_base_test_impl(ctx):
12+
env = unittest.begin(ctx)
13+
14+
# Arrange / Act
15+
16+
result = json.decode(ctx.attr.result)
17+
expected = json.decode(ctx.attr.expected)
18+
19+
# Assert
20+
21+
asserts.equals(
22+
env,
23+
expected,
24+
result,
25+
)
26+
27+
return unittest.end(env)
28+
29+
xcschemes_base_test = unittest.make(
30+
impl = _xcschemes_base_test_impl,
31+
# @unsorted-dict-items
32+
attrs = {
33+
# Inputs
34+
"result": attr.string(mandatory = True),
35+
36+
# Expected
37+
"expected": attr.string(mandatory = True),
38+
},
39+
)
40+
41+
def xcschemes_base_test_suite(name):
42+
"""Test suite for `xcschemes`.
43+
44+
Args:
45+
name: The base name to be used in things created by this macro. Also the
46+
name of the test suite.
47+
"""
48+
test_names = []
49+
50+
def _add_test(
51+
*,
52+
name,
53+
54+
# Inputs
55+
result,
56+
57+
# Expected
58+
expected):
59+
test_names.append(name)
60+
xcschemes_base_test(
61+
name = name,
62+
63+
# Inputs
64+
result = json.encode(result),
65+
66+
# Expected
67+
expected = json.encode(expected),
68+
)
69+
70+
# env_value
71+
72+
_add_test(
73+
name = "{}_env_value_default".format(name),
74+
75+
# Inputs
76+
result = xcschemes.env_value(value = "test value"),
77+
78+
# Expected
79+
expected = struct(
80+
enabled = "1",
81+
value = "test value",
82+
),
83+
)
84+
85+
_add_test(
86+
name = "{}_env_value_empty".format(name),
87+
88+
# Inputs
89+
result = xcschemes.env_value(value = ""),
90+
91+
# Expected
92+
expected = struct(
93+
enabled = "1",
94+
value = "",
95+
),
96+
)
97+
98+
# Test suite
99+
100+
native.test_suite(
101+
name = name,
102+
tests = test_names,
103+
)

0 commit comments

Comments
 (0)