Reformat .bzl files with buildifier and add format check.
Buildifier 0.12.0 includes initial support for reformatting .bzl files. - Reformat all the bzl files. - Expand the travis check to check the .bzl files also.
This commit is contained in:
parent
a5431b7bab
commit
e5203c0f5d
|
@ -26,9 +26,14 @@ fi
|
|||
# Asked to do a buildifier run.
|
||||
if [[ -n "${BUILDIFER:-}" ]]; then
|
||||
# bazelbuild/buildtools/issues/220 - diff doesn't include the file that needs updating
|
||||
if ! find . -name BUILD -print | xargs buildifier -d > /dev/null 2>&1 ; then
|
||||
echo "ERROR: BUILD file formatting issue(s)"
|
||||
find . -name BUILD -print -exec buildifier -v -d {} \;
|
||||
if ! find . \( -name BUILD -o -name "*.bzl" \) -print | xargs buildifier -d > /dev/null 2>&1 ; then
|
||||
echo "ERROR: BUILD/.bzl file formatting issue(s):"
|
||||
echo ""
|
||||
find . \( -name BUILD -o -name "*.bzl" \) -print -exec buildifier -v -d {} \;
|
||||
echo ""
|
||||
echo "Please download the latest buildifier"
|
||||
echo " https://github.com/bazelbuild/buildtools/releases"
|
||||
echo "and run it over the changed BUILD/.bzl files."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
25
lib.bzl
25
lib.bzl
|
@ -14,22 +14,21 @@
|
|||
|
||||
"""Index from which multiple modules can be loaded."""
|
||||
|
||||
load("//lib:collections.bzl", _collections="collections")
|
||||
load("//lib:dicts.bzl", _dicts="dicts")
|
||||
load("//lib:new_sets.bzl", _new_sets="sets")
|
||||
load("//lib:partial.bzl", _partial="partial")
|
||||
load("//lib:paths.bzl", _paths="paths")
|
||||
load("//lib:selects.bzl", _selects="selects")
|
||||
load("//lib:sets.bzl", _sets="sets")
|
||||
load("//lib:shell.bzl", _shell="shell")
|
||||
load("//lib:structs.bzl", _structs="structs")
|
||||
load("//lib:types.bzl", _types="types")
|
||||
load("//lib:versions.bzl", _versions="versions")
|
||||
load("//lib:collections.bzl", _collections = "collections")
|
||||
load("//lib:dicts.bzl", _dicts = "dicts")
|
||||
load("//lib:new_sets.bzl", _new_sets = "sets")
|
||||
load("//lib:partial.bzl", _partial = "partial")
|
||||
load("//lib:paths.bzl", _paths = "paths")
|
||||
load("//lib:selects.bzl", _selects = "selects")
|
||||
load("//lib:sets.bzl", _sets = "sets")
|
||||
load("//lib:shell.bzl", _shell = "shell")
|
||||
load("//lib:structs.bzl", _structs = "structs")
|
||||
load("//lib:types.bzl", _types = "types")
|
||||
load("//lib:versions.bzl", _versions = "versions")
|
||||
|
||||
# The unittest module is treated differently to give more convenient names to
|
||||
# the assert functions, while keeping them in the same .bzl file.
|
||||
load("//lib:unittest.bzl", _asserts="asserts", _unittest="unittest")
|
||||
|
||||
load("//lib:unittest.bzl", _asserts = "asserts", _unittest = "unittest")
|
||||
|
||||
collections = _collections
|
||||
dicts = _dicts
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
"""Skylib module containing functions that operate on collections."""
|
||||
|
||||
|
||||
def _after_each(separator, iterable):
|
||||
"""Inserts `separator` after each item in `iterable`.
|
||||
|
||||
|
@ -32,7 +31,6 @@ def _after_each(separator, iterable):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def _before_each(separator, iterable):
|
||||
"""Inserts `separator` before each item in `iterable`.
|
||||
|
||||
|
@ -50,7 +48,6 @@ def _before_each(separator, iterable):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def _uniq(iterable):
|
||||
"""Returns a list of unique elements in `iterable`.
|
||||
|
||||
|
@ -65,9 +62,8 @@ def _uniq(iterable):
|
|||
unique_elements = {element: None for element in iterable}
|
||||
return unique_elements.keys()
|
||||
|
||||
|
||||
collections = struct(
|
||||
after_each=_after_each,
|
||||
before_each=_before_each,
|
||||
uniq=_uniq,
|
||||
after_each = _after_each,
|
||||
before_each = _before_each,
|
||||
uniq = _uniq,
|
||||
)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
"""Skylib module containing functions that operate on dictionaries."""
|
||||
|
||||
|
||||
def _add(*dictionaries):
|
||||
"""Returns a new `dict` that has all the entries of the given dictionaries.
|
||||
|
||||
|
@ -37,7 +36,6 @@ def _add(*dictionaries):
|
|||
result.update(d)
|
||||
return result
|
||||
|
||||
|
||||
dicts = struct(
|
||||
add=_add,
|
||||
add = _add,
|
||||
)
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
|
||||
load(":dicts.bzl", "dicts")
|
||||
|
||||
|
||||
def _make(elements=None):
|
||||
def _make(elements = None):
|
||||
"""Creates a new set.
|
||||
|
||||
All elements must be hashable.
|
||||
|
@ -37,7 +36,6 @@ def _make(elements=None):
|
|||
elements = elements if elements else []
|
||||
return struct(_values = {e: None for e in elements})
|
||||
|
||||
|
||||
def _copy(s):
|
||||
"""Creates a new set from another set.
|
||||
|
||||
|
@ -49,7 +47,6 @@ def _copy(s):
|
|||
"""
|
||||
return struct(_values = dict(s._values))
|
||||
|
||||
|
||||
def _to_list(s):
|
||||
"""Creates a list from the values in the set.
|
||||
|
||||
|
@ -61,7 +58,6 @@ def _to_list(s):
|
|||
"""
|
||||
return s._values.keys()
|
||||
|
||||
|
||||
def _insert(s, e):
|
||||
"""Inserts an element into the set.
|
||||
|
||||
|
@ -77,7 +73,6 @@ def _insert(s, e):
|
|||
s._values[e] = None
|
||||
return s
|
||||
|
||||
|
||||
def _remove(s, e):
|
||||
"""Removes an element from the set.
|
||||
|
||||
|
@ -93,7 +88,6 @@ def _remove(s, e):
|
|||
s._values.pop(e)
|
||||
return s
|
||||
|
||||
|
||||
def _contains(a, e):
|
||||
"""Checks for the existence of an element in a set.
|
||||
|
||||
|
@ -106,7 +100,6 @@ def _contains(a, e):
|
|||
"""
|
||||
return e in a._values
|
||||
|
||||
|
||||
def _get_shorter_and_longer(a, b):
|
||||
"""Returns two sets in the order of shortest and longest.
|
||||
|
||||
|
@ -121,7 +114,6 @@ def _get_shorter_and_longer(a, b):
|
|||
return a, b
|
||||
return b, a
|
||||
|
||||
|
||||
def _is_equal(a, b):
|
||||
"""Returns whether two sets are equal.
|
||||
|
||||
|
@ -134,7 +126,6 @@ def _is_equal(a, b):
|
|||
"""
|
||||
return a._values == b._values
|
||||
|
||||
|
||||
def _is_subset(a, b):
|
||||
"""Returns whether `a` is a subset of `b`.
|
||||
|
||||
|
@ -150,7 +141,6 @@ def _is_subset(a, b):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _disjoint(a, b):
|
||||
"""Returns whether two sets are disjoint.
|
||||
|
||||
|
@ -169,7 +159,6 @@ def _disjoint(a, b):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _intersection(a, b):
|
||||
"""Returns the intersection of two sets.
|
||||
|
||||
|
@ -183,7 +172,6 @@ def _intersection(a, b):
|
|||
shorter, longer = _get_shorter_and_longer(a, b)
|
||||
return struct(_values = {e: None for e in shorter._values.keys() if e in longer._values})
|
||||
|
||||
|
||||
def _union(*args):
|
||||
"""Returns the union of several sets.
|
||||
|
||||
|
@ -195,7 +183,6 @@ def _union(*args):
|
|||
"""
|
||||
return struct(_values = dicts.add(*[s._values for s in args]))
|
||||
|
||||
|
||||
def _difference(a, b):
|
||||
"""Returns the elements in `a` that are not in `b`.
|
||||
|
||||
|
@ -208,7 +195,6 @@ def _difference(a, b):
|
|||
"""
|
||||
return struct(_values = {e: None for e in a._values.keys() if e not in b._values})
|
||||
|
||||
|
||||
def _length(s):
|
||||
"""Returns the number of elements in a set.
|
||||
|
||||
|
@ -231,7 +217,6 @@ def _repr(s):
|
|||
"""
|
||||
return repr(s._values.keys())
|
||||
|
||||
|
||||
sets = struct(
|
||||
make = _make,
|
||||
copy = _copy,
|
||||
|
|
|
@ -122,9 +122,9 @@ def _make(func, *args, **kwargs):
|
|||
Returns:
|
||||
A new `partial` that can be called using `call`
|
||||
"""
|
||||
return struct(function=func, args=args, kwargs=kwargs)
|
||||
return struct(function = func, args = args, kwargs = kwargs)
|
||||
|
||||
partial = struct(
|
||||
make=_make,
|
||||
call=_call,
|
||||
make = _make,
|
||||
call = _call,
|
||||
)
|
||||
|
|
|
@ -19,7 +19,6 @@ path separators (forward slash, "/"); they do not handle Windows-style paths
|
|||
with backslash separators or drive letters.
|
||||
"""
|
||||
|
||||
|
||||
def _basename(p):
|
||||
"""Returns the basename (i.e., the file portion) of a path.
|
||||
|
||||
|
@ -36,7 +35,6 @@ def _basename(p):
|
|||
"""
|
||||
return p.rpartition("/")[-1]
|
||||
|
||||
|
||||
def _dirname(p):
|
||||
"""Returns the dirname of a path.
|
||||
|
||||
|
@ -58,7 +56,6 @@ def _dirname(p):
|
|||
# os.path.dirname does.
|
||||
return prefix.rstrip("/")
|
||||
|
||||
|
||||
def _is_absolute(path):
|
||||
"""Returns `True` if `path` is an absolute path.
|
||||
|
||||
|
@ -68,8 +65,7 @@ def _is_absolute(path):
|
|||
Returns:
|
||||
`True` if `path` is an absolute path.
|
||||
"""
|
||||
return path.startswith("/") or (len(path)>2 and path[1] == ":")
|
||||
|
||||
return path.startswith("/") or (len(path) > 2 and path[1] == ":")
|
||||
|
||||
def _join(path, *others):
|
||||
"""Joins one or more path components intelligently.
|
||||
|
@ -101,7 +97,6 @@ def _join(path, *others):
|
|||
|
||||
return result
|
||||
|
||||
|
||||
def _normalize(path):
|
||||
"""Normalizes a path, eliminating double slashes and other redundant segments.
|
||||
|
||||
|
@ -158,7 +153,6 @@ def _normalize(path):
|
|||
|
||||
return path or "."
|
||||
|
||||
|
||||
def _relativize(path, start):
|
||||
"""Returns the portion of `path` that is relative to `start`.
|
||||
|
||||
|
@ -195,7 +189,6 @@ def _relativize(path, start):
|
|||
result_segments = segments[-length:]
|
||||
return "/".join(result_segments)
|
||||
|
||||
|
||||
def _replace_extension(p, new_extension):
|
||||
"""Replaces the extension of the file at the end of a path.
|
||||
|
||||
|
@ -211,7 +204,6 @@ def _replace_extension(p, new_extension):
|
|||
"""
|
||||
return _split_extension(p)[0] + new_extension
|
||||
|
||||
|
||||
def _split_extension(p):
|
||||
"""Splits the path `p` into a tuple containing the root and extension.
|
||||
|
||||
|
@ -238,14 +230,13 @@ def _split_extension(p):
|
|||
dot_distance_from_end = len(b) - last_dot_in_basename
|
||||
return (p[:-dot_distance_from_end], p[-dot_distance_from_end:])
|
||||
|
||||
|
||||
paths = struct(
|
||||
basename=_basename,
|
||||
dirname=_dirname,
|
||||
is_absolute=_is_absolute,
|
||||
join=_join,
|
||||
normalize=_normalize,
|
||||
relativize=_relativize,
|
||||
replace_extension=_replace_extension,
|
||||
split_extension=_split_extension,
|
||||
basename = _basename,
|
||||
dirname = _dirname,
|
||||
is_absolute = _is_absolute,
|
||||
join = _join,
|
||||
normalize = _normalize,
|
||||
relativize = _relativize,
|
||||
replace_extension = _replace_extension,
|
||||
split_extension = _split_extension,
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
"""Skylib module containing convenience interfaces for select()."""
|
||||
|
||||
def _with_or(input_dict, no_match_error=''):
|
||||
def _with_or(input_dict, no_match_error = ""):
|
||||
"""Drop-in replacement for `select()` that supports ORed keys.
|
||||
|
||||
Args:
|
||||
|
@ -49,8 +49,7 @@ def _with_or(input_dict, no_match_error=''):
|
|||
"//configs:three": [":dep2or3"],
|
||||
```
|
||||
"""
|
||||
return select(_with_or_dict(input_dict), no_match_error=no_match_error)
|
||||
|
||||
return select(_with_or_dict(input_dict), no_match_error = no_match_error)
|
||||
|
||||
def _with_or_dict(input_dict):
|
||||
"""Variation of `with_or` that returns the dict of the `select()`.
|
||||
|
@ -77,8 +76,7 @@ def _with_or_dict(input_dict):
|
|||
output_dict[key] = value
|
||||
return output_dict
|
||||
|
||||
|
||||
selects = struct(
|
||||
with_or=_with_or,
|
||||
with_or_dict=_with_or_dict
|
||||
with_or = _with_or,
|
||||
with_or_dict = _with_or_dict,
|
||||
)
|
||||
|
|
12
lib/sets.bzl
12
lib/sets.bzl
|
@ -26,7 +26,6 @@ duplicate elements are ignored). Functions that return new sets always return
|
|||
them as the `set` type, regardless of the types of the inputs.
|
||||
"""
|
||||
|
||||
|
||||
def _precondition_only_sets_or_lists(*args):
|
||||
"""Verifies that all arguments are either sets or lists.
|
||||
|
||||
|
@ -37,11 +36,10 @@ def _precondition_only_sets_or_lists(*args):
|
|||
"""
|
||||
for a in args:
|
||||
t = type(a)
|
||||
if t not in("depset", "list"):
|
||||
if t not in ("depset", "list"):
|
||||
fail("Expected arguments to be depset or list, but found type %s: %r" %
|
||||
(t, a))
|
||||
|
||||
|
||||
def _is_equal(a, b):
|
||||
"""Returns whether two sets are equal.
|
||||
|
||||
|
@ -55,7 +53,6 @@ def _is_equal(a, b):
|
|||
_precondition_only_sets_or_lists(a, b)
|
||||
return sorted(depset(a)) == sorted(depset(b))
|
||||
|
||||
|
||||
def _is_subset(a, b):
|
||||
"""Returns whether `a` is a subset of `b`.
|
||||
|
||||
|
@ -72,7 +69,6 @@ def _is_subset(a, b):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _disjoint(a, b):
|
||||
"""Returns whether two sets are disjoint.
|
||||
|
||||
|
@ -91,7 +87,6 @@ def _disjoint(a, b):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _intersection(a, b):
|
||||
"""Returns the intersection of two sets.
|
||||
|
||||
|
@ -105,7 +100,6 @@ def _intersection(a, b):
|
|||
_precondition_only_sets_or_lists(a, b)
|
||||
return depset([e for e in a if e in b])
|
||||
|
||||
|
||||
def _union(*args):
|
||||
"""Returns the union of several sets.
|
||||
|
||||
|
@ -117,8 +111,7 @@ def _union(*args):
|
|||
"""
|
||||
_precondition_only_sets_or_lists(*args)
|
||||
args_deps = [depset(x) if type(x) == type([]) else x for x in args]
|
||||
return depset(transitive=args_deps)
|
||||
|
||||
return depset(transitive = args_deps)
|
||||
|
||||
def _difference(a, b):
|
||||
"""Returns the elements in `a` that are not in `b`.
|
||||
|
@ -133,7 +126,6 @@ def _difference(a, b):
|
|||
_precondition_only_sets_or_lists(a, b)
|
||||
return depset([e for e in a if e not in b])
|
||||
|
||||
|
||||
sets = struct(
|
||||
difference = _difference,
|
||||
disjoint = _disjoint,
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
"""Skylib module containing shell utility functions."""
|
||||
|
||||
|
||||
def _array_literal(iterable):
|
||||
"""Creates a string from a sequence that can be used as a shell array.
|
||||
|
||||
|
@ -35,7 +34,6 @@ def _array_literal(iterable):
|
|||
"""
|
||||
return "(" + " ".join([_quote(str(i)) for i in iterable]) + ")"
|
||||
|
||||
|
||||
def _quote(s):
|
||||
"""Quotes the given string for use in a shell command.
|
||||
|
||||
|
@ -50,8 +48,7 @@ def _quote(s):
|
|||
"""
|
||||
return "'" + s.replace("'", "'\\''") + "'"
|
||||
|
||||
|
||||
shell = struct(
|
||||
array_literal=_array_literal,
|
||||
quote=_quote,
|
||||
array_literal = _array_literal,
|
||||
quote = _quote,
|
||||
)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
"""Skylib module containing functions that operate on structs."""
|
||||
|
||||
|
||||
def _to_dict(s):
|
||||
"""Converts a `struct` to a `dict`.
|
||||
|
||||
|
@ -31,7 +30,6 @@ def _to_dict(s):
|
|||
attributes.remove("to_proto")
|
||||
return {key: getattr(s, key) for key in attributes}
|
||||
|
||||
|
||||
structs = struct(
|
||||
to_dict=_to_dict,
|
||||
to_dict = _to_dict,
|
||||
)
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
# limitations under the License.
|
||||
"""Skylib module containing functions checking types."""
|
||||
|
||||
|
||||
# create instance singletons to avoid unnecessary allocations
|
||||
_a_bool = True
|
||||
_a_dict = {}
|
||||
|
@ -22,11 +21,9 @@ _a_string = ""
|
|||
_a_tuple = ()
|
||||
_an_int = 1
|
||||
|
||||
|
||||
def _a_function():
|
||||
pass
|
||||
|
||||
|
||||
def _is_list(v):
|
||||
"""Returns True if v is an instance of a list.
|
||||
|
||||
|
@ -38,7 +35,6 @@ def _is_list(v):
|
|||
"""
|
||||
return type(v) == type(_a_list)
|
||||
|
||||
|
||||
def _is_string(v):
|
||||
"""Returns True if v is an instance of a string.
|
||||
|
||||
|
@ -50,7 +46,6 @@ def _is_string(v):
|
|||
"""
|
||||
return type(v) == type(_a_string)
|
||||
|
||||
|
||||
def _is_bool(v):
|
||||
"""Returns True if v is an instance of a bool.
|
||||
|
||||
|
@ -62,7 +57,6 @@ def _is_bool(v):
|
|||
"""
|
||||
return type(v) == type(_a_bool)
|
||||
|
||||
|
||||
def _is_none(v):
|
||||
"""Returns True if v has the type of None.
|
||||
|
||||
|
@ -74,7 +68,6 @@ def _is_none(v):
|
|||
"""
|
||||
return type(v) == type(None)
|
||||
|
||||
|
||||
def _is_int(v):
|
||||
"""Returns True if v is an instance of a signed integer.
|
||||
|
||||
|
@ -86,7 +79,6 @@ def _is_int(v):
|
|||
"""
|
||||
return type(v) == type(_an_int)
|
||||
|
||||
|
||||
def _is_tuple(v):
|
||||
"""Returns True if v is an instance of a tuple.
|
||||
|
||||
|
@ -98,7 +90,6 @@ def _is_tuple(v):
|
|||
"""
|
||||
return type(v) == type(_a_tuple)
|
||||
|
||||
|
||||
def _is_dict(v):
|
||||
"""Returns True if v is an instance of a dict.
|
||||
|
||||
|
@ -110,7 +101,6 @@ def _is_dict(v):
|
|||
"""
|
||||
return type(v) == type(_a_dict)
|
||||
|
||||
|
||||
def _is_function(v):
|
||||
"""Returns True if v is an instance of a function.
|
||||
|
||||
|
@ -122,14 +112,13 @@ def _is_function(v):
|
|||
"""
|
||||
return type(v) == type(_a_function)
|
||||
|
||||
|
||||
types = struct(
|
||||
is_list=_is_list,
|
||||
is_string=_is_string,
|
||||
is_bool=_is_bool,
|
||||
is_none=_is_none,
|
||||
is_int=_is_int,
|
||||
is_tuple=_is_tuple,
|
||||
is_dict=_is_dict,
|
||||
is_function=_is_function,
|
||||
is_list = _is_list,
|
||||
is_string = _is_string,
|
||||
is_bool = _is_bool,
|
||||
is_none = _is_none,
|
||||
is_int = _is_int,
|
||||
is_tuple = _is_tuple,
|
||||
is_dict = _is_dict,
|
||||
is_function = _is_function,
|
||||
)
|
||||
|
|
|
@ -20,10 +20,9 @@ assertions used to within tests.
|
|||
"""
|
||||
|
||||
load(":sets.bzl", "sets")
|
||||
load(":new_sets.bzl", new_sets="sets")
|
||||
load(":new_sets.bzl", new_sets = "sets")
|
||||
|
||||
|
||||
def _make(impl, attrs=None):
|
||||
def _make(impl, attrs = None):
|
||||
"""Creates a unit test rule from its implementation function.
|
||||
|
||||
Each unit test is defined in an implementation function that must then be
|
||||
|
@ -69,16 +68,15 @@ def _make(impl, attrs=None):
|
|||
impl_name = impl_name.rpartition(">")[0]
|
||||
|
||||
attrs = dict(attrs) if attrs else {}
|
||||
attrs["_impl_name"] = attr.string(default=impl_name)
|
||||
attrs["_impl_name"] = attr.string(default = impl_name)
|
||||
|
||||
return rule(
|
||||
impl,
|
||||
attrs=attrs,
|
||||
_skylark_testable=True,
|
||||
test=True,
|
||||
attrs = attrs,
|
||||
_skylark_testable = True,
|
||||
test = True,
|
||||
)
|
||||
|
||||
|
||||
def _suite(name, *test_rules):
|
||||
"""Defines a `test_suite` target that contains multiple tests.
|
||||
|
||||
|
@ -126,15 +124,14 @@ def _suite(name, *test_rules):
|
|||
test_names = []
|
||||
for index, test_rule in enumerate(test_rules):
|
||||
test_name = "%s_test_%d" % (name, index)
|
||||
test_rule(name=test_name)
|
||||
test_rule(name = test_name)
|
||||
test_names.append(test_name)
|
||||
|
||||
native.test_suite(
|
||||
name=name,
|
||||
tests=[":%s" % t for t in test_names]
|
||||
name = name,
|
||||
tests = [":%s" % t for t in test_names],
|
||||
)
|
||||
|
||||
|
||||
def _begin(ctx):
|
||||
"""Begins a unit test.
|
||||
|
||||
|
@ -152,8 +149,7 @@ def _begin(ctx):
|
|||
`unittest.end`. Do not rely on internal details about the fields in this
|
||||
struct as it may change.
|
||||
"""
|
||||
return struct(ctx=ctx, failures=[])
|
||||
|
||||
return struct(ctx = ctx, failures = [])
|
||||
|
||||
def _end(env):
|
||||
"""Ends a unit test and logs the results.
|
||||
|
@ -171,12 +167,11 @@ def _end(env):
|
|||
"exit %d" % len(env.failures),
|
||||
])
|
||||
env.ctx.file_action(
|
||||
output=env.ctx.outputs.executable,
|
||||
content=cmd,
|
||||
executable=True,
|
||||
output = env.ctx.outputs.executable,
|
||||
content = cmd,
|
||||
executable = True,
|
||||
)
|
||||
|
||||
|
||||
def _fail(env, msg):
|
||||
"""Unconditionally causes the current test to fail.
|
||||
|
||||
|
@ -188,10 +183,10 @@ def _fail(env, msg):
|
|||
print(full_msg)
|
||||
env.failures.append(full_msg)
|
||||
|
||||
|
||||
def _assert_true(env,
|
||||
def _assert_true(
|
||||
env,
|
||||
condition,
|
||||
msg="Expected condition to be true, but was false."):
|
||||
msg = "Expected condition to be true, but was false."):
|
||||
"""Asserts that the given `condition` is true.
|
||||
|
||||
Args:
|
||||
|
@ -203,10 +198,10 @@ def _assert_true(env,
|
|||
if not condition:
|
||||
_fail(env, msg)
|
||||
|
||||
|
||||
def _assert_false(env,
|
||||
def _assert_false(
|
||||
env,
|
||||
condition,
|
||||
msg="Expected condition to be false, but was true."):
|
||||
msg = "Expected condition to be false, but was true."):
|
||||
"""Asserts that the given `condition` is false.
|
||||
|
||||
Args:
|
||||
|
@ -218,8 +213,7 @@ def _assert_false(env,
|
|||
if condition:
|
||||
_fail(env, msg)
|
||||
|
||||
|
||||
def _assert_equals(env, expected, actual, msg=None):
|
||||
def _assert_equals(env, expected, actual, msg = None):
|
||||
"""Asserts that the given `expected` and `actual` values are equal.
|
||||
|
||||
Args:
|
||||
|
@ -237,8 +231,7 @@ def _assert_equals(env, expected, actual, msg=None):
|
|||
full_msg = expectation_msg
|
||||
_fail(env, full_msg)
|
||||
|
||||
|
||||
def _assert_set_equals(env, expected, actual, msg=None):
|
||||
def _assert_set_equals(env, expected, actual, msg = None):
|
||||
"""Asserts that the given `expected` and `actual` sets are equal.
|
||||
|
||||
Args:
|
||||
|
@ -256,7 +249,7 @@ def _assert_set_equals(env, expected, actual, msg=None):
|
|||
full_msg = expectation_msg
|
||||
_fail(env, full_msg)
|
||||
|
||||
def _assert_new_set_equals(env, expected, actual, msg=None):
|
||||
def _assert_new_set_equals(env, expected, actual, msg = None):
|
||||
"""Asserts that the given `expected` and `actual` sets are equal.
|
||||
|
||||
Args:
|
||||
|
@ -275,17 +268,17 @@ def _assert_new_set_equals(env, expected, actual, msg=None):
|
|||
_fail(env, full_msg)
|
||||
|
||||
asserts = struct(
|
||||
equals=_assert_equals,
|
||||
false=_assert_false,
|
||||
set_equals=_assert_set_equals,
|
||||
equals = _assert_equals,
|
||||
false = _assert_false,
|
||||
set_equals = _assert_set_equals,
|
||||
new_set_equals = _assert_new_set_equals,
|
||||
true=_assert_true,
|
||||
true = _assert_true,
|
||||
)
|
||||
|
||||
unittest = struct(
|
||||
make=_make,
|
||||
suite=_suite,
|
||||
begin=_begin,
|
||||
end=_end,
|
||||
fail=_fail,
|
||||
make = _make,
|
||||
suite = _suite,
|
||||
begin = _begin,
|
||||
end = _end,
|
||||
fail = _fail,
|
||||
)
|
||||
|
|
|
@ -19,7 +19,6 @@ def _get_bazel_version():
|
|||
|
||||
return native.bazel_version
|
||||
|
||||
|
||||
def _extract_version_number(bazel_version):
|
||||
"""Extracts the semantic version number from a version string
|
||||
|
||||
|
@ -55,7 +54,6 @@ def _parse_bazel_version(bazel_version):
|
|||
version = _extract_version_number(bazel_version)
|
||||
return tuple([int(n) for n in version.split(".")])
|
||||
|
||||
|
||||
def _is_at_most(threshold, version):
|
||||
"""Check that a version is lower or equals to a threshold.
|
||||
|
||||
|
@ -68,7 +66,6 @@ def _is_at_most(threshold, version):
|
|||
"""
|
||||
return _parse_bazel_version(version) <= _parse_bazel_version(threshold)
|
||||
|
||||
|
||||
def _is_at_least(threshold, version):
|
||||
"""Check that a version is higher or equals to a threshold.
|
||||
|
||||
|
@ -82,8 +79,7 @@ def _is_at_least(threshold, version):
|
|||
|
||||
return _parse_bazel_version(version) >= _parse_bazel_version(threshold)
|
||||
|
||||
|
||||
def _check_bazel_version(minimum_bazel_version, maximum_bazel_version=None, bazel_version=None):
|
||||
def _check_bazel_version(minimum_bazel_version, maximum_bazel_version = None, bazel_version = None):
|
||||
"""Check that the version of Bazel is valid within the specified range.
|
||||
|
||||
Args:
|
||||
|
@ -103,23 +99,29 @@ def _check_bazel_version(minimum_bazel_version, maximum_bazel_version=None, baze
|
|||
|
||||
if not _is_at_least(
|
||||
threshold = minimum_bazel_version,
|
||||
version = bazel_version):
|
||||
version = bazel_version,
|
||||
):
|
||||
fail("\nCurrent Bazel version is {}, expected at least {}\n".format(
|
||||
bazel_version, minimum_bazel_version))
|
||||
bazel_version,
|
||||
minimum_bazel_version,
|
||||
))
|
||||
|
||||
if maximum_bazel_version:
|
||||
if not _is_at_most(
|
||||
threshold = maximum_bazel_version,
|
||||
version = bazel_version):
|
||||
version = bazel_version,
|
||||
):
|
||||
fail("\nCurrent Bazel version is {}, expected at most {}\n".format(
|
||||
bazel_version, maximum_bazel_version))
|
||||
bazel_version,
|
||||
maximum_bazel_version,
|
||||
))
|
||||
|
||||
pass
|
||||
|
||||
versions = struct(
|
||||
get=_get_bazel_version,
|
||||
parse=_parse_bazel_version,
|
||||
check=_check_bazel_version,
|
||||
is_at_most=_is_at_most,
|
||||
is_at_least=_is_at_least,
|
||||
get = _get_bazel_version,
|
||||
parse = _parse_bazel_version,
|
||||
check = _check_bazel_version,
|
||||
is_at_most = _is_at_most,
|
||||
is_at_least = _is_at_least,
|
||||
)
|
||||
|
|
|
@ -15,46 +15,46 @@
|
|||
"""Skylib module containing a library rule for aggregating rules files."""
|
||||
|
||||
SkylarkLibraryInfo = provider(
|
||||
'Information on contained Skylark rules.',
|
||||
fields={
|
||||
'srcs': 'Top level rules files.',
|
||||
'transitive_srcs': 'Transitive closure of rules files required for ' +
|
||||
'interpretation of the srcs',
|
||||
"Information on contained Skylark rules.",
|
||||
fields = {
|
||||
"srcs": "Top level rules files.",
|
||||
"transitive_srcs": "Transitive closure of rules files required for " +
|
||||
"interpretation of the srcs",
|
||||
},
|
||||
)
|
||||
|
||||
def _skylark_library_impl(ctx):
|
||||
deps_files = [depset(x.files, order="postorder") for x in ctx.attr.deps]
|
||||
all_files = depset(ctx.files.srcs, order="postorder", transitive=deps_files)
|
||||
deps_files = [depset(x.files, order = "postorder") for x in ctx.attr.deps]
|
||||
all_files = depset(ctx.files.srcs, order = "postorder", transitive = deps_files)
|
||||
return [
|
||||
# All dependent files should be listed in both `files` and in `runfiles`;
|
||||
# this ensures that a `skylark_library` can be referenced as `data` from
|
||||
# a separate program, or from `tools` of a genrule().
|
||||
DefaultInfo(
|
||||
files=all_files,
|
||||
runfiles=ctx.runfiles(files=list(all_files)),
|
||||
files = all_files,
|
||||
runfiles = ctx.runfiles(files = list(all_files)),
|
||||
),
|
||||
|
||||
# We also define our own provider struct, for aggregation and testing.
|
||||
SkylarkLibraryInfo(
|
||||
srcs=ctx.files.srcs,
|
||||
transitive_srcs=all_files,
|
||||
srcs = ctx.files.srcs,
|
||||
transitive_srcs = all_files,
|
||||
),
|
||||
]
|
||||
|
||||
skylark_library = rule(
|
||||
implementation=_skylark_library_impl,
|
||||
attrs={
|
||||
implementation = _skylark_library_impl,
|
||||
attrs = {
|
||||
"srcs": attr.label_list(
|
||||
allow_files=[".bzl"],
|
||||
allow_files = [".bzl"],
|
||||
),
|
||||
"deps": attr.label_list(
|
||||
allow_files=[".bzl"],
|
||||
providers=[
|
||||
allow_files = [".bzl"],
|
||||
providers = [
|
||||
[SkylarkLibraryInfo],
|
||||
],
|
||||
)
|
||||
}
|
||||
),
|
||||
},
|
||||
)
|
||||
"""Creates a logical collection of Skylark .bzl files.
|
||||
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for collections.bzl."""
|
||||
|
||||
load("//:lib.bzl", "collections", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "collections", "unittest")
|
||||
|
||||
def _after_each_test(ctx):
|
||||
"""Unit tests for collections.after_each."""
|
||||
|
@ -23,54 +22,86 @@ def _after_each_test(ctx):
|
|||
|
||||
asserts.equals(env, [], collections.after_each("1", []))
|
||||
asserts.equals(env, ["a", "1"], collections.after_each("1", ["a"]))
|
||||
asserts.equals(env, ["a", "1", "b", "1"],
|
||||
collections.after_each("1", ["a", "b"]))
|
||||
asserts.equals(
|
||||
env,
|
||||
["a", "1", "b", "1"],
|
||||
collections.after_each("1", ["a", "b"]),
|
||||
)
|
||||
|
||||
# We don't care what type the separator is, we just put it there; so None
|
||||
# should be just as valid as anything else.
|
||||
asserts.equals(env, ["a", None, "b", None],
|
||||
collections.after_each(None, ["a", "b"]))
|
||||
asserts.equals(
|
||||
env,
|
||||
["a", None, "b", None],
|
||||
collections.after_each(None, ["a", "b"]),
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
after_each_test = unittest.make(_after_each_test)
|
||||
|
||||
|
||||
def _before_each_test(ctx):
|
||||
"""Unit tests for collections.before_each."""
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.equals(env, [], collections.before_each("1", []))
|
||||
asserts.equals(env, ["1", "a"], collections.before_each("1", ["a"]))
|
||||
asserts.equals(env, ["1", "a", "1", "b"],
|
||||
collections.before_each("1", ["a", "b"]))
|
||||
asserts.equals(
|
||||
env,
|
||||
["1", "a", "1", "b"],
|
||||
collections.before_each("1", ["a", "b"]),
|
||||
)
|
||||
|
||||
# We don't care what type the separator is, we just put it there; so None
|
||||
# should be just as valid as anything else.
|
||||
asserts.equals(env, [None, "a", None, "b"],
|
||||
collections.before_each(None, ["a", "b"]))
|
||||
asserts.equals(
|
||||
env,
|
||||
[None, "a", None, "b"],
|
||||
collections.before_each(None, ["a", "b"]),
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
before_each_test = unittest.make(_before_each_test)
|
||||
|
||||
|
||||
def _uniq_test(ctx):
|
||||
env = unittest.begin(ctx)
|
||||
asserts.equals(env, collections.uniq([0, 1, 2, 3]), [0, 1, 2, 3])
|
||||
asserts.equals(env, collections.uniq([]), [])
|
||||
asserts.equals(env, collections.uniq([1, 1, 1, 1, 1]), [1])
|
||||
asserts.equals(env, collections.uniq([True, 5, "foo", 5, False, struct(a=1),
|
||||
True, struct(b=2), "bar", (1,), "foo",
|
||||
struct(a=1), (1,)]),
|
||||
[True, 5, "foo", False, struct(a=1), struct(b=2),
|
||||
"bar", (1,)])
|
||||
asserts.equals(
|
||||
env,
|
||||
collections.uniq([
|
||||
True,
|
||||
5,
|
||||
"foo",
|
||||
5,
|
||||
False,
|
||||
struct(a = 1),
|
||||
True,
|
||||
struct(b = 2),
|
||||
"bar",
|
||||
(1,),
|
||||
"foo",
|
||||
struct(a = 1),
|
||||
(1,),
|
||||
]),
|
||||
[
|
||||
True,
|
||||
5,
|
||||
"foo",
|
||||
False,
|
||||
struct(a = 1),
|
||||
struct(b = 2),
|
||||
"bar",
|
||||
(1,),
|
||||
],
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
uniq_test = unittest.make(_uniq_test)
|
||||
|
||||
|
||||
def collections_test_suite():
|
||||
"""Creates the test targets and test suite for collections.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for dicts.bzl."""
|
||||
|
||||
load("//:lib.bzl", "dicts", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "dicts", "unittest")
|
||||
|
||||
def _add_test(ctx):
|
||||
"""Unit tests for dicts.add."""
|
||||
|
@ -29,17 +28,26 @@ def _add_test(ctx):
|
|||
asserts.equals(env, {"a": 1, "b": 2}, dicts.add({"a": 1}, {"b": 2}))
|
||||
|
||||
# Test simple more-than-two-argument behavior.
|
||||
asserts.equals(env, {"a": 1, "b": 2, "c": 3, "d": 4},
|
||||
dicts.add({"a": 1}, {"b": 2}, {"c": 3}, {"d": 4}))
|
||||
asserts.equals(
|
||||
env,
|
||||
{"a": 1, "b": 2, "c": 3, "d": 4},
|
||||
dicts.add({"a": 1}, {"b": 2}, {"c": 3}, {"d": 4}),
|
||||
)
|
||||
|
||||
# Test same-key overriding.
|
||||
asserts.equals(env, {"a": 100}, dicts.add({"a": 1}, {"a": 100}))
|
||||
asserts.equals(env, {"a": 10}, dicts.add({"a": 1}, {"a": 100}, {"a": 10}))
|
||||
asserts.equals(env, {"a": 100, "b": 10},
|
||||
dicts.add({"a": 1}, {"a": 100}, {"b": 10}))
|
||||
asserts.equals(
|
||||
env,
|
||||
{"a": 100, "b": 10},
|
||||
dicts.add({"a": 1}, {"a": 100}, {"b": 10}),
|
||||
)
|
||||
asserts.equals(env, {"a": 10}, dicts.add({"a": 1}, {}, {"a": 10}))
|
||||
asserts.equals(env, {"a": 10, "b": 5},
|
||||
dicts.add({"a": 1}, {"a": 10, "b": 5}))
|
||||
asserts.equals(
|
||||
env,
|
||||
{"a": 10, "b": 5},
|
||||
dicts.add({"a": 1}, {"a": 10, "b": 5}),
|
||||
)
|
||||
|
||||
# Test some other boundary cases.
|
||||
asserts.equals(env, {"a": 1}, dicts.add({"a": 1}, {}))
|
||||
|
@ -58,7 +66,6 @@ def _add_test(ctx):
|
|||
|
||||
add_test = unittest.make(_add_test)
|
||||
|
||||
|
||||
def dicts_test_suite():
|
||||
"""Creates the test targets and test suite for dicts.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for new_sets.bzl."""
|
||||
|
||||
load("//:lib.bzl", "new_sets", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "new_sets", "unittest")
|
||||
|
||||
def _is_equal_test(ctx):
|
||||
"""Unit tests for new_sets.is_equal."""
|
||||
|
@ -43,7 +42,6 @@ def _is_equal_test(ctx):
|
|||
|
||||
is_equal_test = unittest.make(_is_equal_test)
|
||||
|
||||
|
||||
def _is_subset_test(ctx):
|
||||
"""Unit tests for new_sets.is_subset."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -63,7 +61,6 @@ def _is_subset_test(ctx):
|
|||
|
||||
is_subset_test = unittest.make(_is_subset_test)
|
||||
|
||||
|
||||
def _disjoint_test(ctx):
|
||||
"""Unit tests for new_sets.disjoint."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -83,7 +80,6 @@ def _disjoint_test(ctx):
|
|||
|
||||
disjoint_test = unittest.make(_disjoint_test)
|
||||
|
||||
|
||||
def _intersection_test(ctx):
|
||||
"""Unit tests for new_sets.intersection."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -103,7 +99,6 @@ def _intersection_test(ctx):
|
|||
|
||||
intersection_test = unittest.make(_intersection_test)
|
||||
|
||||
|
||||
def _union_test(ctx):
|
||||
"""Unit tests for new_sets.union."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -125,7 +120,6 @@ def _union_test(ctx):
|
|||
|
||||
union_test = unittest.make(_union_test)
|
||||
|
||||
|
||||
def _difference_test(ctx):
|
||||
"""Unit tests for new_sets.difference."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -145,7 +139,6 @@ def _difference_test(ctx):
|
|||
|
||||
difference_test = unittest.make(_difference_test)
|
||||
|
||||
|
||||
def _to_list_test(ctx):
|
||||
"""Unit tests for new_sets.to_list."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -158,7 +151,6 @@ def _to_list_test(ctx):
|
|||
|
||||
to_list_test = unittest.make(_to_list_test)
|
||||
|
||||
|
||||
def _make_test(ctx):
|
||||
"""Unit tests for new_sets.make."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -171,13 +163,13 @@ def _make_test(ctx):
|
|||
|
||||
make_test = unittest.make(_make_test)
|
||||
|
||||
|
||||
def _copy_test(ctx):
|
||||
"""Unit tests for new_sets.copy."""
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.new_set_equals(env, new_sets.copy(new_sets.make()), new_sets.make())
|
||||
asserts.new_set_equals(env, new_sets.copy(new_sets.make([1, 2, 3])), new_sets.make([1, 2, 3]))
|
||||
|
||||
# Ensure mutating the copy does not mutate the original
|
||||
original = new_sets.make([1, 2, 3])
|
||||
copy = new_sets.copy(original)
|
||||
|
@ -188,23 +180,26 @@ def _copy_test(ctx):
|
|||
|
||||
copy_test = unittest.make(_copy_test)
|
||||
|
||||
|
||||
def _insert_test(ctx):
|
||||
"""Unit tests for new_sets.insert."""
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.new_set_equals(env, new_sets.make([1, 2, 3]), new_sets.insert(new_sets.make([1, 2]), 3))
|
||||
|
||||
# Ensure mutating the inserted set does mutate the original set.
|
||||
original = new_sets.make([1, 2, 3])
|
||||
after_insert = new_sets.insert(original, 4)
|
||||
asserts.new_set_equals(env, original, after_insert,
|
||||
msg="Insert creates a new set which is an O(n) operation, insert should be O(1).")
|
||||
asserts.new_set_equals(
|
||||
env,
|
||||
original,
|
||||
after_insert,
|
||||
msg = "Insert creates a new set which is an O(n) operation, insert should be O(1).",
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
insert_test = unittest.make(_insert_test)
|
||||
|
||||
|
||||
def _contains_test(ctx):
|
||||
"""Unit tests for new_sets.contains."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -218,7 +213,6 @@ def _contains_test(ctx):
|
|||
|
||||
contains_test = unittest.make(_contains_test)
|
||||
|
||||
|
||||
def _length_test(ctx):
|
||||
"""Unit test for new_sets.length."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -231,12 +225,12 @@ def _length_test(ctx):
|
|||
|
||||
length_test = unittest.make(_length_test)
|
||||
|
||||
|
||||
def _remove_test(ctx):
|
||||
"""Unit test for new_sets.remove."""
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.new_set_equals(env, new_sets.make([1, 2]), new_sets.remove(new_sets.make([1, 2, 3]), 3))
|
||||
|
||||
# Ensure mutating the inserted set does mutate the original set.
|
||||
original = new_sets.make([1, 2, 3])
|
||||
after_removal = new_sets.remove(original, 3)
|
||||
|
@ -246,7 +240,6 @@ def _remove_test(ctx):
|
|||
|
||||
remove_test = unittest.make(_remove_test)
|
||||
|
||||
|
||||
def _repr_str_test(ctx):
|
||||
"""Unit test for new_sets.repr and new_sets.str."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -263,7 +256,6 @@ def _repr_str_test(ctx):
|
|||
|
||||
repr_str_test = unittest.make(_repr_str_test)
|
||||
|
||||
|
||||
def new_sets_test_suite():
|
||||
"""Creates the test targets and test suite for new_sets.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for partial.bzl."""
|
||||
|
||||
load("//:lib.bzl", "partial", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "partial", "unittest")
|
||||
|
||||
def _make_noargs_nokwargs():
|
||||
"""Test utility for no args no kwargs case"""
|
||||
|
@ -31,15 +30,15 @@ def _make_args_kwargs(arg1, arg2, arg3, **kwargs):
|
|||
|
||||
def _call_noargs_nokwargs(call_arg1):
|
||||
"""Test utility no args no kwargs case where values passed from call site"""
|
||||
return call_arg1;
|
||||
return call_arg1
|
||||
|
||||
def _call_args_nokwargs(func_arg1, call_arg1):
|
||||
"""Test utility for args no kwargs case where values passed from call site"""
|
||||
return func_arg1 + call_arg1;
|
||||
return func_arg1 + call_arg1
|
||||
|
||||
def _call_args_kwargs(func_arg1, call_arg1, func_mult, call_mult):
|
||||
"""Test utility for args and kwargs case where values passed from call site"""
|
||||
return (func_arg1 + call_arg1) * func_mult * call_mult;
|
||||
return (func_arg1 + call_arg1) * func_mult * call_mult
|
||||
|
||||
def _make_call_test(ctx):
|
||||
"""Unit tests for partial.make and partial.call."""
|
||||
|
@ -54,7 +53,7 @@ def _make_call_test(ctx):
|
|||
asserts.equals(env, 6, partial.call(foo, 1, 2, 3))
|
||||
|
||||
foo = partial.make(_make_args_kwargs)
|
||||
asserts.equals(env, 15, partial.call(foo, 1, 2, 3, x=4, y=5))
|
||||
asserts.equals(env, 15, partial.call(foo, 1, 2, 3, x = 4, y = 5))
|
||||
|
||||
# Test cases where there are args (and/or kwargs) at the make site and the
|
||||
# call site.
|
||||
|
@ -64,19 +63,18 @@ def _make_call_test(ctx):
|
|||
foo = partial.make(_call_args_nokwargs, 100)
|
||||
asserts.equals(env, 112, partial.call(foo, 12))
|
||||
|
||||
foo = partial.make(_call_args_kwargs, 100, func_mult=10)
|
||||
asserts.equals(env, 2240, partial.call(foo, 12, call_mult=2))
|
||||
foo = partial.make(_call_args_kwargs, 100, func_mult = 10)
|
||||
asserts.equals(env, 2240, partial.call(foo, 12, call_mult = 2))
|
||||
|
||||
# Test case where there are args and kwargs ath the make site, and the call
|
||||
# site overrides some make site args.
|
||||
foo = partial.make(_call_args_kwargs, 100, func_mult=10)
|
||||
asserts.equals(env, 1120, partial.call(foo, 12, func_mult=5, call_mult=2))
|
||||
foo = partial.make(_call_args_kwargs, 100, func_mult = 10)
|
||||
asserts.equals(env, 1120, partial.call(foo, 12, func_mult = 5, call_mult = 2))
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
make_call_test = unittest.make(_make_call_test)
|
||||
|
||||
|
||||
def partial_test_suite():
|
||||
"""Creates the test targets and test suite for partial.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for paths.bzl."""
|
||||
|
||||
load("//:lib.bzl", "paths", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "paths", "unittest")
|
||||
|
||||
def _basename_test(ctx):
|
||||
"""Unit tests for paths.basename."""
|
||||
|
@ -41,7 +40,6 @@ def _basename_test(ctx):
|
|||
|
||||
basename_test = unittest.make(_basename_test)
|
||||
|
||||
|
||||
def _dirname_test(ctx):
|
||||
"""Unit tests for paths.dirname."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -67,7 +65,6 @@ def _dirname_test(ctx):
|
|||
|
||||
dirname_test = unittest.make(_dirname_test)
|
||||
|
||||
|
||||
def _is_absolute_test(ctx):
|
||||
"""Unit tests for paths.is_absolute."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -90,7 +87,6 @@ def _is_absolute_test(ctx):
|
|||
|
||||
is_absolute_test = unittest.make(_is_absolute_test)
|
||||
|
||||
|
||||
def _join_test(ctx):
|
||||
"""Unit tests for paths.join."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -135,7 +131,6 @@ def _join_test(ctx):
|
|||
|
||||
join_test = unittest.make(_join_test)
|
||||
|
||||
|
||||
def _normalize_test(ctx):
|
||||
"""Unit tests for paths.normalize."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -178,7 +173,6 @@ def _normalize_test(ctx):
|
|||
|
||||
normalize_test = unittest.make(_normalize_test)
|
||||
|
||||
|
||||
def _relativize_test(ctx):
|
||||
"""Unit tests for paths.relativize."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -205,7 +199,6 @@ def _relativize_test(ctx):
|
|||
|
||||
relativize_test = unittest.make(_relativize_test)
|
||||
|
||||
|
||||
def _replace_extension_test(ctx):
|
||||
"""Unit tests for paths.replace_extension."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -216,8 +209,11 @@ def _replace_extension_test(ctx):
|
|||
asserts.equals(env, "foo.bar", paths.replace_extension("foo", ".bar"))
|
||||
|
||||
# Try a directory with an extension and basename that doesn't have one.
|
||||
asserts.equals(env, "foo.bar/baz.quux",
|
||||
paths.replace_extension("foo.bar/baz", ".quux"))
|
||||
asserts.equals(
|
||||
env,
|
||||
"foo.bar/baz.quux",
|
||||
paths.replace_extension("foo.bar/baz", ".quux"),
|
||||
)
|
||||
|
||||
# Now try some things with legit extensions.
|
||||
asserts.equals(env, "a.z", paths.replace_extension("a.b", ".z"))
|
||||
|
@ -234,7 +230,6 @@ def _replace_extension_test(ctx):
|
|||
|
||||
replace_extension_test = unittest.make(_replace_extension_test)
|
||||
|
||||
|
||||
def _split_extension_test(ctx):
|
||||
"""Unit tests for paths.split_extension."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -248,13 +243,19 @@ def _split_extension_test(ctx):
|
|||
asserts.equals(env, (".", ""), paths.split_extension("."))
|
||||
asserts.equals(env, (".bashrc", ""), paths.split_extension(".bashrc"))
|
||||
asserts.equals(env, ("foo/.bashrc", ""), paths.split_extension("foo/.bashrc"))
|
||||
asserts.equals(env, (".foo/.bashrc", ""),
|
||||
paths.split_extension(".foo/.bashrc"))
|
||||
asserts.equals(
|
||||
env,
|
||||
(".foo/.bashrc", ""),
|
||||
paths.split_extension(".foo/.bashrc"),
|
||||
)
|
||||
|
||||
# Try some directories with extensions with basenames that don't have one.
|
||||
asserts.equals(env, ("foo.bar/baz", ""), paths.split_extension("foo.bar/baz"))
|
||||
asserts.equals(env, ("foo.bar/.bashrc", ""),
|
||||
paths.split_extension("foo.bar/.bashrc"))
|
||||
asserts.equals(
|
||||
env,
|
||||
("foo.bar/.bashrc", ""),
|
||||
paths.split_extension("foo.bar/.bashrc"),
|
||||
)
|
||||
|
||||
# Now try some things that will actually get split.
|
||||
asserts.equals(env, ("a", ".b"), paths.split_extension("a.b"))
|
||||
|
@ -268,7 +269,6 @@ def _split_extension_test(ctx):
|
|||
|
||||
split_extension_test = unittest.make(_split_extension_test)
|
||||
|
||||
|
||||
def paths_test_suite():
|
||||
"""Creates the test targets and test suite for paths.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for selects.bzl."""
|
||||
|
||||
load("//:lib.bzl", "selects", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "selects", "unittest")
|
||||
|
||||
def _with_or_test(ctx):
|
||||
"""Unit tests for with_or."""
|
||||
|
@ -30,21 +29,33 @@ def _with_or_test(ctx):
|
|||
|
||||
# Test OR syntax.
|
||||
or_dict = {(":foo", ":bar"): ":d1"}
|
||||
asserts.equals(env, {":foo": ":d1", ":bar": ":d1"},
|
||||
selects.with_or_dict(or_dict))
|
||||
asserts.equals(
|
||||
env,
|
||||
{":foo": ":d1", ":bar": ":d1"},
|
||||
selects.with_or_dict(or_dict),
|
||||
)
|
||||
|
||||
# Test mixed syntax.
|
||||
mixed_dict = {":foo": ":d1", (":bar", ":baz"): ":d2",
|
||||
"//conditions:default": ":d3"}
|
||||
asserts.equals(env, {":foo": ":d1", ":bar": ":d2", ":baz": ":d2",
|
||||
"//conditions:default": ":d3"},
|
||||
selects.with_or_dict(mixed_dict))
|
||||
mixed_dict = {
|
||||
":foo": ":d1",
|
||||
(":bar", ":baz"): ":d2",
|
||||
"//conditions:default": ":d3",
|
||||
}
|
||||
asserts.equals(
|
||||
env,
|
||||
{
|
||||
":foo": ":d1",
|
||||
":bar": ":d2",
|
||||
":baz": ":d2",
|
||||
"//conditions:default": ":d3",
|
||||
},
|
||||
selects.with_or_dict(mixed_dict),
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
with_or_test = unittest.make(_with_or_test)
|
||||
|
||||
|
||||
def selects_test_suite():
|
||||
"""Creates the test targets and test suite for selects.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for sets.bzl."""
|
||||
|
||||
load("//:lib.bzl", "sets", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "sets", "unittest")
|
||||
|
||||
def _is_equal_test(ctx):
|
||||
"""Unit tests for sets.is_equal."""
|
||||
|
@ -43,7 +42,6 @@ def _is_equal_test(ctx):
|
|||
|
||||
is_equal_test = unittest.make(_is_equal_test)
|
||||
|
||||
|
||||
def _is_subset_test(ctx):
|
||||
"""Unit tests for sets.is_subset."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -63,7 +61,6 @@ def _is_subset_test(ctx):
|
|||
|
||||
is_subset_test = unittest.make(_is_subset_test)
|
||||
|
||||
|
||||
def _disjoint_test(ctx):
|
||||
"""Unit tests for sets.disjoint."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -83,7 +80,6 @@ def _disjoint_test(ctx):
|
|||
|
||||
disjoint_test = unittest.make(_disjoint_test)
|
||||
|
||||
|
||||
def _intersection_test(ctx):
|
||||
"""Unit tests for sets.intersection."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -103,7 +99,6 @@ def _intersection_test(ctx):
|
|||
|
||||
intersection_test = unittest.make(_intersection_test)
|
||||
|
||||
|
||||
def _union_test(ctx):
|
||||
"""Unit tests for sets.union."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -125,7 +120,6 @@ def _union_test(ctx):
|
|||
|
||||
union_test = unittest.make(_union_test)
|
||||
|
||||
|
||||
def _difference_test(ctx):
|
||||
"""Unit tests for sets.difference."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -145,7 +139,6 @@ def _difference_test(ctx):
|
|||
|
||||
difference_test = unittest.make(_difference_test)
|
||||
|
||||
|
||||
def sets_test_suite():
|
||||
"""Creates the test targets and test suite for sets.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for shell.bzl."""
|
||||
|
||||
load("//:lib.bzl", "shell", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "shell", "unittest")
|
||||
|
||||
def _shell_array_literal_test(ctx):
|
||||
"""Unit tests for shell.array_literal."""
|
||||
|
@ -31,7 +30,6 @@ def _shell_array_literal_test(ctx):
|
|||
|
||||
shell_array_literal_test = unittest.make(_shell_array_literal_test)
|
||||
|
||||
|
||||
def _shell_quote_test(ctx):
|
||||
"""Unit tests for shell.quote."""
|
||||
env = unittest.begin(ctx)
|
||||
|
@ -46,14 +44,13 @@ def _shell_quote_test(ctx):
|
|||
asserts.equals(env, "'$foo'", shell.quote("$foo"))
|
||||
asserts.equals(env, "'qu\"o\"te'", shell.quote('qu"o"te'))
|
||||
asserts.equals(env, "'it'\\''s'", shell.quote("it's"))
|
||||
asserts.equals(env, "'foo\\bar'", shell.quote(r"foo\bar"))
|
||||
asserts.equals(env, "'back`echo q`uote'", shell.quote(r"back`echo q`uote"))
|
||||
asserts.equals(env, "'foo\\bar'", shell.quote("foo\\bar"))
|
||||
asserts.equals(env, "'back`echo q`uote'", shell.quote("back`echo q`uote"))
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
shell_quote_test = unittest.make(_shell_quote_test)
|
||||
|
||||
|
||||
def _shell_spawn_e2e_test_impl(ctx):
|
||||
"""Test spawning a real shell."""
|
||||
args = [
|
||||
|
@ -67,7 +64,7 @@ def _shell_spawn_e2e_test_impl(ctx):
|
|||
"$foo",
|
||||
'qu"o"te',
|
||||
"it's",
|
||||
r"foo\bar",
|
||||
"foo\\bar",
|
||||
"back`echo q`uote",
|
||||
]
|
||||
script_content = "\n".join([
|
||||
|
@ -92,7 +89,7 @@ def _shell_spawn_e2e_test_impl(ctx):
|
|||
is_executable = True,
|
||||
)
|
||||
return [
|
||||
DefaultInfo(executable=script_file),
|
||||
DefaultInfo(executable = script_file),
|
||||
]
|
||||
|
||||
shell_spawn_e2e_test = rule(
|
||||
|
@ -100,7 +97,6 @@ shell_spawn_e2e_test = rule(
|
|||
implementation = _shell_spawn_e2e_test_impl,
|
||||
)
|
||||
|
||||
|
||||
def shell_test_suite():
|
||||
"""Creates the test targets and test suite for shell.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
"""Unit tests for structs.bzl."""
|
||||
|
||||
load("//:lib.bzl", "structs", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "structs", "unittest")
|
||||
|
||||
def _add_test(ctx):
|
||||
"""Unit tests for dicts.add."""
|
||||
|
@ -23,24 +22,29 @@ def _add_test(ctx):
|
|||
|
||||
# Test zero- and one-argument behavior.
|
||||
asserts.equals(env, {}, structs.to_dict(struct()))
|
||||
asserts.equals(env, {"a": 1}, structs.to_dict(struct(a=1)))
|
||||
asserts.equals(env, {"a": 1}, structs.to_dict(struct(a = 1)))
|
||||
|
||||
# Test simple two-argument behavior.
|
||||
asserts.equals(env, {"a": 1, "b": 2}, structs.to_dict(struct(a=1, b=2)))
|
||||
asserts.equals(env, {"a": 1, "b": 2}, structs.to_dict(struct(a = 1, b = 2)))
|
||||
|
||||
# Test simple more-than-two-argument behavior.
|
||||
asserts.equals(env, {"a": 1, "b": 2, "c": 3, "d": 4},
|
||||
structs.to_dict(struct(a=1, b=2, c=3, d=4)))
|
||||
asserts.equals(
|
||||
env,
|
||||
{"a": 1, "b": 2, "c": 3, "d": 4},
|
||||
structs.to_dict(struct(a = 1, b = 2, c = 3, d = 4)),
|
||||
)
|
||||
|
||||
# Test transformation is not applied transitively.
|
||||
asserts.equals(env, {"a": 1, "b": struct(bb=1)},
|
||||
structs.to_dict(struct(a=1, b=struct(bb=1))))
|
||||
asserts.equals(
|
||||
env,
|
||||
{"a": 1, "b": struct(bb = 1)},
|
||||
structs.to_dict(struct(a = 1, b = struct(bb = 1))),
|
||||
)
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
add_test = unittest.make(_add_test)
|
||||
|
||||
|
||||
def structs_test_suite():
|
||||
"""Creates the test targets and test suite for structs.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -13,14 +13,12 @@
|
|||
# limitations under the License.
|
||||
"""Unit tests for types.bzl."""
|
||||
|
||||
load("//:lib.bzl", "types", "asserts", "unittest")
|
||||
|
||||
load("//:lib.bzl", "asserts", "types", "unittest")
|
||||
|
||||
def _a_function():
|
||||
"""A dummy function for testing."""
|
||||
pass
|
||||
|
||||
|
||||
def _is_string_test(ctx):
|
||||
"""Unit tests for types.is_string."""
|
||||
|
||||
|
@ -39,10 +37,8 @@ def _is_string_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_string_test = unittest.make(_is_string_test)
|
||||
|
||||
|
||||
def _is_bool_test(ctx):
|
||||
"""Unit tests for types.is_bool."""
|
||||
|
||||
|
@ -61,10 +57,8 @@ def _is_bool_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_bool_test = unittest.make(_is_bool_test)
|
||||
|
||||
|
||||
def _is_list_test(ctx):
|
||||
"""Unit tests for types.is_list."""
|
||||
|
||||
|
@ -83,10 +77,8 @@ def _is_list_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_list_test = unittest.make(_is_list_test)
|
||||
|
||||
|
||||
def _is_none_test(ctx):
|
||||
"""Unit tests for types.is_none."""
|
||||
|
||||
|
@ -105,10 +97,8 @@ def _is_none_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_none_test = unittest.make(_is_none_test)
|
||||
|
||||
|
||||
def _is_int_test(ctx):
|
||||
"""Unit tests for types.is_int."""
|
||||
|
||||
|
@ -128,17 +118,15 @@ def _is_int_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_int_test = unittest.make(_is_int_test)
|
||||
|
||||
|
||||
def _is_tuple_test(ctx):
|
||||
"""Unit tests for types.is_tuple."""
|
||||
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.true(env, types.is_tuple(()))
|
||||
asserts.true(env, types.is_tuple((1, )))
|
||||
asserts.true(env, types.is_tuple((1,)))
|
||||
|
||||
asserts.false(env, types.is_tuple(1))
|
||||
asserts.false(env, types.is_tuple("s"))
|
||||
|
@ -151,17 +139,15 @@ def _is_tuple_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_tuple_test = unittest.make(_is_tuple_test)
|
||||
|
||||
|
||||
def _is_dict_test(ctx):
|
||||
"""Unit tests for types.is_dict."""
|
||||
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.true(env, types.is_dict({}))
|
||||
asserts.true(env, types.is_dict({'key': 'value'}))
|
||||
asserts.true(env, types.is_dict({"key": "value"}))
|
||||
|
||||
asserts.false(env, types.is_dict(1))
|
||||
asserts.false(env, types.is_dict("s"))
|
||||
|
@ -174,10 +160,8 @@ def _is_dict_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_dict_test = unittest.make(_is_dict_test)
|
||||
|
||||
|
||||
def _is_function_test(ctx):
|
||||
"""Unit tests for types.is_dict."""
|
||||
|
||||
|
@ -196,10 +180,8 @@ def _is_function_test(ctx):
|
|||
|
||||
unittest.end(env)
|
||||
|
||||
|
||||
is_function_test = unittest.make(_is_function_test)
|
||||
|
||||
|
||||
def types_test_suite():
|
||||
"""Creates the test targets and test suite for types.bzl tests."""
|
||||
unittest.suite(
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
"""Unit tests for versions.bzl."""
|
||||
|
||||
load("//:lib.bzl", "versions", "asserts", "unittest")
|
||||
load("//:lib.bzl", "asserts", "unittest", "versions")
|
||||
|
||||
def _parse_test(ctx):
|
||||
"""Unit tests for versions.parse"""
|
||||
|
@ -47,10 +47,10 @@ def _check_test(ctx):
|
|||
"""Unit tests for versions.check"""
|
||||
env = unittest.begin(ctx)
|
||||
|
||||
asserts.equals(env, None, versions.check("0.4.5 abcdef", bazel_version="0.10.0rc1 abcd123"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", bazel_version="0.4.5"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", bazel_version="0.10.0rc1 abcd123"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", maximum_bazel_version="1.0.0", bazel_version="0.10.0rc1 abcd123"))
|
||||
asserts.equals(env, None, versions.check("0.4.5 abcdef", bazel_version = "0.10.0rc1 abcd123"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", bazel_version = "0.4.5"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", bazel_version = "0.10.0rc1 abcd123"))
|
||||
asserts.equals(env, None, versions.check("0.4.5", maximum_bazel_version = "1.0.0", bazel_version = "0.10.0rc1 abcd123"))
|
||||
|
||||
unittest.end(env)
|
||||
|
||||
|
|
Loading…
Reference in New Issue