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

[commands] Use factories and decorators in Command tests #7006

Merged

Conversation

TheComputer314
Copy link
Contributor

@TheComputer314 TheComputer314 commented Aug 25, 2024

Closes #6652.

@TheComputer314 TheComputer314 requested a review from a team as a code owner August 25, 2024 15:47
Copy link
Contributor

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@TheComputer314
Copy link
Contributor Author

/format

Copy link
Contributor

@spacey-sooty spacey-sooty left a comment

Choose a reason for hiding this comment

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

Looks good to me but needs C++ and Python ports

@TheComputer314 TheComputer314 marked this pull request as draft September 22, 2024 04:22
@TheComputer314
Copy link
Contributor Author

/format

@github-actions github-actions bot added the component: command-based WPILib Command Based Library label Dec 8, 2024
Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

I'm a bit iffy about using factories instead of the command constructors in tests that are specifically testing those command types, but the command constructors also don't support CommandPtr. I could see either way (replacing command constructors in command type tests with factories or not using any factories in command type tests) being fine. @rzblue thoughts?

Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

Submitted before I meant to, whoops. I've also updated my comment with a list of what needs to be changed.

@TheComputer314
Copy link
Contributor Author

ScheduleCommand doesn't have a factory yet, and I'm not entirely sure how to POVButtonTest.

@TheComputer314
Copy link
Contributor Author

/format

@KangarooKoala
Copy link
Contributor

Great progress! I've updated the list of changes to make.

ScheduleCommand doesn't have a factory yet, and I'm not entirely sure how to POVButtonTest.

For ScheduleCommandTest, you just need to replace InstantCommand, and for POVButtonTest, you just need to replace WaitUntilCommand.

P.S. I get email notifications for GitHub comments on this PR (and other PRs I've participated in), and I also usually see all updated PRs (which includes PRs with new commits) within a day. If you want to make sure I see it, though, you can always keep on requesting my review- Emails are cheap!

@TheComputer314
Copy link
Contributor Author

For ScheduleCommandTest, ScheduleCommand doesn't have a constructor that accepts a CommandPtr, and for POVButtonTest, (as far as my understand of cpp goes) Trigger only has a constructor for an rvalue CommandPtr when command needs to be used elsewhere, necessitating making it an lvalue.

@KangarooKoala
Copy link
Contributor

Ah, you're right, I missed that. Don't worry about them, then.

@TheComputer314
Copy link
Contributor Author

CommandPtr also doesn't have .addRequirements() necessary for AddRequirementsTest.

@KangarooKoala
Copy link
Contributor

Ah, I missed that too. I think that leaves just ParallelRaceGroupTest.ParallelRaceCopy?

@TheComputer314
Copy link
Contributor Author

I think everything on the checklist is done now.

@KangarooKoala
Copy link
Contributor

KangarooKoala commented Dec 17, 2024

Whoops, looks like I missed these earlier:

  • CompositionTestBase: cmd::WaitUntil([] { return false; }) -> cmd::Idle()
  • ConditionalCommandTest.AllCancelSelf: cmd::WaitUntil([] { return false; })

Other than that, should be everything. (Though I am still iffy about using the factories in tests of the command classes themselves)

@TheComputer314
Copy link
Contributor Author

(Though I am still iffy about using the factories in tests of the command classes themselves)

I feel like it should be fine? The actual code logic is entirely identical so the only way for the factories to break is for the command behind the factory to break, which preserves the function of the command unit tests.

@TheComputer314
Copy link
Contributor Author

* `CompositionTestBase`: `cmd::WaitUntil([] { return false; })` -> `cmd::Idle()`

* `ConditionalCommandTest.AllCancelSelf`: `cmd::WaitUntil([] { return false; })`

Done those 2.

Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

Looks good to me, for what it's worth. One of the actual maintainers will need to review and approve this too before this gets merged.

@@ -45,7 +45,7 @@ void requirementUninterruptibleTest() {
Subsystem requirement = new SubsystemBase() {};

Command notInterrupted =
new RunCommand(() -> {}, requirement)
Commands.idle(requirement)
Copy link
Member

Choose a reason for hiding this comment

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

Does requirement.idle() exist?

Copy link
Contributor

Choose a reason for hiding this comment

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

No

@PeterJohnson PeterJohnson changed the title Make Command tests use command factories and decorators. [commands] Use factories and decorators in Command tests Dec 29, 2024
@PeterJohnson PeterJohnson merged commit 78b6d61 into wpilibsuite:main Dec 29, 2024
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: command-based WPILib Command Based Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cmd] Use command factories and decorators in command tests
6 participants