2017-10-10 14:59:31 +00:00
|
|
|
# Copyright 2017 The Bazel Authors. All rights reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
"""Unit tests for selects.bzl."""
|
|
|
|
|
2018-08-24 19:00:13 +00:00
|
|
|
load("//lib:selects.bzl", "selects")
|
|
|
|
load("//lib:unittest.bzl", "asserts", "unittest")
|
2017-10-10 14:59:31 +00:00
|
|
|
|
|
|
|
def _with_or_test(ctx):
|
2018-06-12 17:09:57 +00:00
|
|
|
"""Unit tests for with_or."""
|
|
|
|
env = unittest.begin(ctx)
|
2017-10-10 14:59:31 +00:00
|
|
|
|
2018-09-28 13:09:18 +00:00
|
|
|
# We actually test on with_or_dict because Starlark can't get the
|
2018-06-12 17:09:57 +00:00
|
|
|
# dictionary from a select().
|
2017-10-10 14:59:31 +00:00
|
|
|
|
2018-06-12 17:09:57 +00:00
|
|
|
# Test select()-compatible input syntax.
|
2019-01-02 22:47:44 +00:00
|
|
|
input_dict = {"//conditions:default": ":d1", ":foo": ":d1"}
|
2018-06-12 17:09:57 +00:00
|
|
|
asserts.equals(env, input_dict, selects.with_or_dict(input_dict))
|
2017-10-10 14:59:31 +00:00
|
|
|
|
2018-06-12 17:09:57 +00:00
|
|
|
# Test OR syntax.
|
|
|
|
or_dict = {(":foo", ":bar"): ":d1"}
|
|
|
|
asserts.equals(
|
|
|
|
env,
|
2019-01-02 22:47:44 +00:00
|
|
|
{":bar": ":d1", ":foo": ":d1"},
|
2018-06-12 17:09:57 +00:00
|
|
|
selects.with_or_dict(or_dict),
|
|
|
|
)
|
2017-10-10 14:59:31 +00:00
|
|
|
|
2018-06-12 17:09:57 +00:00
|
|
|
# Test mixed syntax.
|
|
|
|
mixed_dict = {
|
|
|
|
"//conditions:default": ":d3",
|
2019-01-02 22:47:44 +00:00
|
|
|
(":bar", ":baz"): ":d2",
|
|
|
|
":foo": ":d1",
|
2018-06-12 17:09:57 +00:00
|
|
|
}
|
|
|
|
asserts.equals(
|
|
|
|
env,
|
|
|
|
{
|
2019-01-02 22:47:44 +00:00
|
|
|
"//conditions:default": ":d3",
|
2018-06-12 17:09:57 +00:00
|
|
|
":bar": ":d2",
|
|
|
|
":baz": ":d2",
|
2019-01-02 22:47:44 +00:00
|
|
|
":foo": ":d1",
|
2018-06-12 17:09:57 +00:00
|
|
|
},
|
|
|
|
selects.with_or_dict(mixed_dict),
|
|
|
|
)
|
2017-10-10 14:59:31 +00:00
|
|
|
|
2018-12-04 15:14:08 +00:00
|
|
|
return unittest.end(env)
|
2017-10-10 14:59:31 +00:00
|
|
|
|
|
|
|
with_or_test = unittest.make(_with_or_test)
|
|
|
|
|
|
|
|
def selects_test_suite():
|
2018-06-12 17:09:57 +00:00
|
|
|
"""Creates the test targets and test suite for selects.bzl tests."""
|
|
|
|
unittest.suite(
|
|
|
|
"selects_tests",
|
|
|
|
with_or_test,
|
|
|
|
)
|