Skip to content

Commit

Permalink
Add toolchains argument to unittests.make (#483)
Browse files Browse the repository at this point in the history
* Add toolchains argument to unittests.make

Make unittests.make bypass toolchains arguments to target rule's constructor.

* update doc

---------

Co-authored-by: JiaYan Lin <jiayanl@google.com>
  • Loading branch information
jylinv0 and JiaYan Lin authored Jan 8, 2024
1 parent 1a1ee6c commit 60241d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/unittest_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Registers the toolchains for unittest users.
## unittest.make

<pre>
unittest.make(<a href="#unittest.make-impl">impl</a>, <a href="#unittest.make-attrs">attrs</a>, <a href="#unittest.make-doc">doc</a>)
unittest.make(<a href="#unittest.make-impl">impl</a>, <a href="#unittest.make-attrs">attrs</a>, <a href="#unittest.make-doc">doc</a>, <a href="#unittest.make-toolchains">toolchains</a>)
</pre>

Creates a unit test rule from its implementation function.
Expand All @@ -439,6 +439,9 @@ implementation function's name so that it can be printed in test feedback.
The optional `attrs` argument can be used to define dependencies for this
test, in order to form unit tests of rules.

The optional `toolchains` argument can be used to define toolchain
dependencies for this test.

An example of a unit test:

```
Expand All @@ -463,6 +466,7 @@ Recall that names of test rules must end in `_test`.
| <a id="unittest.make-impl"></a>impl | The implementation function of the unit test. | none |
| <a id="unittest.make-attrs"></a>attrs | An optional dictionary to supplement the attrs passed to the unit test's <code>rule()</code> constructor. | <code>{}</code> |
| <a id="unittest.make-doc"></a>doc | A description of the rule that can be extracted by documentation generating tools. | <code>""</code> |
| <a id="unittest.make-toolchains"></a>toolchains | An optional list to supplement the toolchains passed to the unit test's <code>rule()</code> constructor. | <code>[]</code> |

**RETURNS**

Expand Down
9 changes: 7 additions & 2 deletions lib/unittest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _impl_function_name(impl):
impl_name = impl_name.partition("<function ")[-1]
return impl_name.rpartition(">")[0]

def _make(impl, attrs = {}, doc = ""):
def _make(impl, attrs = {}, doc = "", toolchains = []):
"""Creates a unit test rule from its implementation function.
Each unit test is defined in an implementation function that must then be
Expand All @@ -159,6 +159,9 @@ def _make(impl, attrs = {}, doc = ""):
The optional `attrs` argument can be used to define dependencies for this
test, in order to form unit tests of rules.
The optional `toolchains` argument can be used to define toolchain
dependencies for this test.
An example of a unit test:
```
Expand All @@ -179,6 +182,8 @@ def _make(impl, attrs = {}, doc = ""):
attrs: An optional dictionary to supplement the attrs passed to the
unit test's `rule()` constructor.
doc: A description of the rule that can be extracted by documentation generating tools.
toolchains: An optional list to supplement the toolchains passed to
the unit test's `rule()` constructor.
Returns:
A rule definition that should be stored in a global whose name ends in
Expand All @@ -193,7 +198,7 @@ def _make(impl, attrs = {}, doc = ""):
attrs = attrs,
_skylark_testable = True,
test = True,
toolchains = [TOOLCHAIN_TYPE],
toolchains = toolchains + [TOOLCHAIN_TYPE],
)

_ActionInfo = provider(
Expand Down

0 comments on commit 60241d2

Please sign in to comment.