mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] RepeatCommand: restart on following iteration (#4706)
This fixes InstantCommand.repeatedly().
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user