Skip to content

CPLAT-16476 Allow args after separator to TestTool #364

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

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

evanweible-wf
Copy link
Contributor

  • Update TestTool to allow arguments after a separator (--). These arguments will always be passed to the dart test process. The main use case for this is integration with IDE plugins that enable running tests directly from the IDE.
  • Update FunctionTool to allow arguments after a separator (--). There isn't a strong reason to disallow this since the function tool could do anything it wants with those args (and now we have a concrete use case for just that).
  • Fix a bug in takeAllArgs (the arg mapper util used with CompoundTool) so that it now properly restores the first separator (--) if present in the original arguments list.

@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

todbachman-wf
todbachman-wf previously approved these changes Dec 9, 2021
todbachman-wf
todbachman-wf previously approved these changes Dec 9, 2021
alanknight-wk
alanknight-wk previously approved these changes Dec 10, 2021

final args = argResults.arguments;
final rest = argResults.rest;
var rCursor = 0;

Choose a reason for hiding this comment

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

Maybe a clearer name? e.g. argSeparatorPosition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little torn on this. I originally had something like what you suggested, but then usages like this feel a bit more confusing:

if (args[aCursor] == rest[separatorArgPosition]) {

Choose a reason for hiding this comment

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

Yeah, I see that. What about not abbreviating. argsCursor and restCursor. I see aCursor at a glance and read it as "an instance of Cursor". Or argsIndex and restIndex?

final rest = argResults.rest;
var rCursor = 0;
for (var aCursor = 0; aCursor < args.length; aCursor++) {
// Iterate through the original args until we hit the first separator.

Choose a reason for hiding this comment

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

I'm having trouble following this. It seems like the only result of this is setting rCursor. But isn't rCursor just args.indexOf('--')?

Copy link
Contributor Author

@evanweible-wf evanweible-wf Dec 13, 2021

Choose a reason for hiding this comment

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

That would be the position of the separator within the original arguments list, which isn't necessarily the same as the position at which the separator should be restored in the rest arguments list, since the latter excludes flags and options that were parsed by the ArgParser. So for example:

final argParser = ArgParser()
  ..addOption('output')
  ..addFlag('verbose');
final argResults = argParser.parse(['foo', '--output', 'out', '--verbose', '--', 'bar', '--baz']);
print(argResults.arguments);
// ['foo', '--output', 'out', '--verbose', '--', 'bar', '--baz']
// In this list, separator index is 4
print(argResults.rest);
// ['foo', 'bar', '--baz']
// In this list, we want to restore the separator at index 1

Choose a reason for hiding this comment

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

OK, I get it. Ugh. It'd be better if ArgParser just didn't think it knew about '--' and included it.

alanknight-wk
alanknight-wk previously approved these changes Dec 15, 2021
final rest = argResults.rest;
var rCursor = 0;
for (var aCursor = 0; aCursor < args.length; aCursor++) {
// Iterate through the original args until we hit the first separator.

Choose a reason for hiding this comment

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

OK, I get it. Ugh. It'd be better if ArgParser just didn't think it knew about '--' and included it.


final args = argResults.arguments;
final rest = argResults.rest;
var rCursor = 0;

Choose a reason for hiding this comment

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

Yeah, I see that. What about not abbreviating. argsCursor and restCursor. I see aCursor at a glance and read it as "an instance of Cursor". Or argsIndex and restIndex?

alanknight-wk
alanknight-wk previously approved these changes Dec 15, 2021
@evanweible-wf
Copy link
Contributor Author

QA +1

  • Tested this locally in one of our projects that uses dart_dev + test_html_builder with browser tests and was able to run and debug tests via the links in the editor.

@rmconsole6-wk rmconsole6-wk changed the title Allow args after separator to TestTool CPLAT-16476 Allow args after separator to TestTool Dec 15, 2021
@evanweible-wf
Copy link
Contributor Author

@Workiva/release-management-p

Copy link
Contributor

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole3-wf rmconsole3-wf merged commit c61ed75 into master Dec 15, 2021
@rmconsole3-wf rmconsole3-wf deleted the test_tool_trailing_args branch December 15, 2021 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants