|
| 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