[commands] RepeatCommand: restart on following iteration (#4706)

This fixes InstantCommand.repeatedly().
This commit is contained in:
Starlight220
2022-11-26 09:50:42 +02:00
committed by GitHub
parent dd1da77d20
commit 58ed112b51
7 changed files with 79 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
// the WPILib BSD license file in the root directory of this project.
#include "CommandTestBase.h"
#include "frc2/command/Commands.h"
#include "frc2/command/FunctionalCommand.h"
using namespace frc2;
@@ -47,7 +48,7 @@ TEST_F(RepeatCommandTest, CallsMethodsCorrectly) {
isFinishedHook = true;
scheduler.Run();
EXPECT_EQ(2, initCounter);
EXPECT_EQ(1, initCounter);
EXPECT_EQ(2, exeCounter);
EXPECT_EQ(2, isFinishedCounter);
EXPECT_EQ(1, endCounter);
@@ -59,3 +60,31 @@ TEST_F(RepeatCommandTest, CallsMethodsCorrectly) {
EXPECT_EQ(3, isFinishedCounter);
EXPECT_EQ(1, endCounter);
}
class RepeatCommandInterruptibilityTest
: public CommandTestBaseWithParam<Command::InterruptionBehavior> {};
TEST_P(RepeatCommandInterruptibilityTest, Interruptibility) {
CommandPtr command = cmd::WaitUntil([] { return false; })
.WithInterruptBehavior(GetParam())
.Repeatedly();
EXPECT_EQ(GetParam(), command.get()->GetInterruptionBehavior());
}
INSTANTIATE_TEST_SUITE_P(
RepeatCommandTests, RepeatCommandInterruptibilityTest,
testing::Values(Command::InterruptionBehavior::kCancelIncoming,
Command::InterruptionBehavior::kCancelSelf));
class RepeatCommandRunsWhenDisabledTest
: public CommandTestBaseWithParam<bool> {};
TEST_P(RepeatCommandRunsWhenDisabledTest, RunsWhenDisabled) {
CommandPtr command = cmd::WaitUntil([] { return false; })
.IgnoringDisable(GetParam())
.Repeatedly();
EXPECT_EQ(GetParam(), command.get()->RunsWhenDisabled());
}
INSTANTIATE_TEST_SUITE_P(RepeatCommandTests, RepeatCommandRunsWhenDisabledTest,
testing::Bool());

View File

@@ -70,6 +70,8 @@ TEST_F(TriggerTest, WhileTrueRepeatedly) {
scheduler.Run();
EXPECT_EQ(1, inits);
scheduler.Run();
EXPECT_EQ(1, inits);
scheduler.Run();
EXPECT_EQ(2, inits);
pressed = false;
scheduler.Run();