bazelbuild / bazelbuild/rules_testing

Support more complex types by using generics

Open
#93 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
29
Forks
11
Avg merge
15h 15m
Merged PRs (30d)
3

Description

It's currently very hard to work with custom providers. One example of somewhere seriously lacking is if I want to do assertions on the following type:
```
FooInfo = provider(fields = {"name": "str")
BarInfo = provider(fields = {
"foos": "(depset[Foo]) the foos",
})
```
I would like to be able to write something like:
```
env.expect.that_provider(BarInfo).foos()
.contains_at_least_predicates(lambda foo: foo.name().equals("foo"))
```

I propose that we allow generics by turning generic types into functions. For example:

```
FooInfoSubject = subjects.struct(name = subjects.string)
BarInfoSubject = subjects.struct(
foos = subjects.depset(FooInfoSubject)
)
```

This would make the above predicates far more easily implemented (although the caveat is that it would require a change in matchers so that you could simply use them as a boolean predicate - at the moment, not matching simply fails the test).

We could also use this to easily solve #63 via the generic type `subjects.optional` (eg. `subjects.optional(subjects.string)`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.