Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toolchains argument to unittests.make #483

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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