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

Use @union to make the v2 test runner generic #7661

Merged

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented May 5, 2019

Problem

Fixing #4535 moved us closer to supporting a Target API for v2, but did not begin to use @union and UnionRule to make the v2 test @console_rule generic.

Solution

Add @union TestTarget, and consume it in the v2 test @console_rule. The result is that a language implementer that wants to add support for testing a target type MyTestTarget can declare a UnionRule(TestTarget, MyTestTarget) in their registered rules, which would in turn require a declared @rule to produce a TestResult for MyTestTarget.

In order to use PythonTestAdaptor as a member of the TestTarget union, the bottom commit refactors the SymbolTable manipulation that we do to preserve the concrete TargetAdaptor classes.

Result

Although we're not quite ready to "bless" TargetAdaptor by requiring it in the SymbolTable or coupling it to the v1 Target class, this change represents an incremental step in the direction of using (a likely renamed) TargetAdaptor incarnation as the v2 Target class.

@stuhood
Copy link
Member Author

stuhood commented May 5, 2019

The commits are useful to review independently.

@stuhood stuhood force-pushed the stuhood/test-runner-rules-use-unions branch 2 times, most recently from 6cec590 to de006a8 Compare May 5, 2019 06:34
Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@stuhood stuhood force-pushed the stuhood/test-runner-rules-use-unions branch from de006a8 to f4abaa9 Compare May 7, 2019 04:17
src/python/pants/rules/core/test.py Show resolved Hide resolved
})

self.assertEqual(result, TestResult(status=Status.FAILURE, stdout='foo'))

def test_coordinator_unknown_test(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you restore this test to validate the claim in the implementation that "If the TargetAdaptor is not a member of the union, it will fail at runtime with a useful error message."?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah. You got me.

It will fail at runtime with a slightly awkward error message (that I attempted to improve over here: #7502)... namely, that there is no declared Get(TestResult, $type).

Copy link
Member Author

@stuhood stuhood May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that if we continue to improve that error message code path by either/or:

  1. using more readable @rule signatures (as in Call for proposals: improved @rule display #7509),
  2. allowing @unions to be directly included in error messages (which I encouraged @cosmicexplorer not to do in the original union PR, in order to keep things simpler)

... that this can become significantly more friendly.

With 2. in particular (and perhaps with something that consumes the docstring of the union, or takes a description to the union annotation?), something like:

Type $x is not a member of the TestTarget @union ($description).

... would be possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure whether this would be a mostly-rule-author-facing error, or whether it could also leak into general users... If the former, either of those sound good. If the latter, we should be a lot more verbose and explainy...

Either way, this sounds good. Happy to punt on this until some-time-this-week in the interests of getting this merged and avoiding merge conflicts for @Eric-Arellano, but I'd like us to come back to this soon :)

…order to allow matching on them in @rule definitions.
@stuhood stuhood force-pushed the stuhood/test-runner-rules-use-unions branch from f4abaa9 to 91054de Compare May 16, 2019 03:31
@stuhood stuhood force-pushed the stuhood/test-runner-rules-use-unions branch from 91054de to 60d96c2 Compare May 16, 2019 05:31
Copy link
Contributor

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Thanks!

@stuhood stuhood merged commit 155077e into pantsbuild:master May 16, 2019
@stuhood stuhood deleted the stuhood/test-runner-rules-use-unions branch May 16, 2019 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants