[cmd2] Flatten wpi::cmd::cmd to wpi::cmd (#8764)

Fixes #8763
This commit is contained in:
sciencewhiz
2026-04-13 21:48:13 -07:00
committed by GitHub
parent f89cf297e4
commit 613c86d1d7
36 changed files with 185 additions and 204 deletions

View File

@@ -21,7 +21,7 @@ TEST_F(CommandDecoratorTest, WithTimeout) {
wpi::sim::PauseTiming();
auto command = cmd::Idle().WithTimeout(100_ms);
auto command = Idle().WithTimeout(100_ms);
scheduler.Schedule(command);
scheduler.Run();
@@ -42,7 +42,7 @@ TEST_F(CommandDecoratorTest, Until) {
bool finish = false;
auto command = cmd::Idle().Until([&finish] { return finish; });
auto command = Idle().Until([&finish] { return finish; });
scheduler.Schedule(command);
scheduler.Run();
@@ -85,7 +85,7 @@ TEST_F(CommandDecoratorTest, OnlyWhile) {
bool run = true;
auto command = cmd::Idle().OnlyWhile([&run] { return run; });
auto command = Idle().OnlyWhile([&run] { return run; });
scheduler.Schedule(command);
scheduler.Run();
@@ -126,7 +126,7 @@ TEST_F(CommandDecoratorTest, OnlyWhileOrder) {
TEST_F(CommandDecoratorTest, IgnoringDisable) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Idle().IgnoringDisable(true);
auto command = Idle().IgnoringDisable(true);
SetDSEnabled(false);
@@ -141,7 +141,7 @@ TEST_F(CommandDecoratorTest, BeforeStarting) {
bool finished = false;
auto command = cmd::None().BeforeStarting([&finished] { finished = true; });
auto command = None().BeforeStarting([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -161,7 +161,7 @@ TEST_F(CommandDecoratorTest, AndThenLambda) {
bool finished = false;
auto command = cmd::None().AndThen([&finished] { finished = true; });
auto command = None().AndThen([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -181,8 +181,8 @@ TEST_F(CommandDecoratorTest, AndThen) {
bool finished = false;
auto command1 = cmd::None();
auto command2 = cmd::RunOnce([&finished] { finished = true; });
auto command1 = None();
auto command2 = RunOnce([&finished] { finished = true; });
auto group = std::move(command1).AndThen(std::move(command2));
scheduler.Schedule(group);
@@ -203,8 +203,8 @@ TEST_F(CommandDecoratorTest, DeadlineFor) {
bool finish = false;
auto dictator = cmd::WaitUntil([&finish] { return finish; });
auto endsAfter = cmd::Idle();
auto dictator = WaitUntil([&finish] { return finish; });
auto endsAfter = Idle();
auto group = std::move(dictator).DeadlineFor(std::move(endsAfter));
@@ -245,8 +245,8 @@ TEST_F(CommandDecoratorTest, AlongWith) {
bool finish = false;
auto command1 = cmd::WaitUntil([&finish] { return finish; });
auto command2 = cmd::None();
auto command1 = WaitUntil([&finish] { return finish; });
auto command2 = None();
auto group = std::move(command1).AlongWith(std::move(command2));
@@ -264,8 +264,8 @@ TEST_F(CommandDecoratorTest, AlongWith) {
TEST_F(CommandDecoratorTest, RaceWith) {
CommandScheduler scheduler = GetScheduler();
auto command1 = cmd::Idle();
auto command2 = cmd::None();
auto command1 = Idle();
auto command2 = None();
auto group = std::move(command1).RaceWith(std::move(command2));
@@ -288,7 +288,7 @@ TEST_F(CommandDecoratorTest, DeadlineForOrder) {
dictatorWasPolled = true;
return true;
});
auto other = cmd::Run([&dictatorHasRun, &dictatorWasPolled] {
auto other = wpi::cmd::Run([&dictatorHasRun, &dictatorWasPolled] {
EXPECT_TRUE(dictatorHasRun);
EXPECT_TRUE(dictatorWasPolled);
});
@@ -341,7 +341,7 @@ TEST_F(CommandDecoratorTest, AlongWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
auto command2 = wpi::cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
@@ -367,7 +367,7 @@ TEST_F(CommandDecoratorTest, RaceWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
auto command2 = wpi::cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
@@ -388,7 +388,7 @@ TEST_F(CommandDecoratorTest, Unless) {
bool unlessCondition = true;
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] {
RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] {
return unlessCondition;
});
@@ -409,7 +409,7 @@ TEST_F(CommandDecoratorTest, OnlyIf) {
bool onlyIfCondition = false;
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] {
RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] {
return onlyIfCondition;
});
@@ -483,7 +483,7 @@ TEST_F(CommandDecoratorTest, HandleInterrupt) {
}
TEST_F(CommandDecoratorTest, WithName) {
auto command = cmd::None();
auto command = None();
std::string name{"Named"};
auto named = std::move(command).WithName(name);
EXPECT_EQ(name, named.get()->GetName());

View File

@@ -19,7 +19,7 @@ TEST_F(CommandPtrTest, MovedFrom) {
int counter = 0;
CommandPtr movedFrom = cmd::Run([&counter] { counter++; });
CommandPtr movedFrom = wpi::cmd::Run([&counter] { counter++; });
CommandPtr movedTo = std::move(movedFrom);
EXPECT_NO_FATAL_FAILURE(scheduler.Schedule(movedTo));

View File

@@ -20,7 +20,7 @@ class CommandSendableButtonTest : public CommandTestBase {
void SetUp() override {
m_schedule = 0;
m_cancel = 0;
m_command = cmd::StartEnd([this] { m_schedule++; }, [this] { m_cancel++; });
m_command = StartEnd([this] { m_schedule++; }, [this] { m_cancel++; });
m_publish = wpi::nt::NetworkTableInstance::GetDefault()
.GetBooleanTopic("/SmartDashboard/command/running")
.Publish();

View File

@@ -57,72 +57,64 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) {
}
TEST_F(ConditionalCommandTest, AllTrue) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(true), [] { return true; });
auto command = Either(Idle().IgnoringDisable(true),
Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(true, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllFalse) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(false), [] { return true; });
auto command = Either(Idle().IgnoringDisable(false),
Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, OneTrueOneFalse) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(false), [] { return true; });
auto command = Either(Idle().IgnoringDisable(true),
Idle().IgnoringDisable(false), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, TwoFalseOneTrue) {
auto command =
cmd::Either(cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(true), [] { return true; });
auto command = Either(Idle().IgnoringDisable(false),
Idle().IgnoringDisable(true), [] { return true; });
EXPECT_EQ(false, command.get()->RunsWhenDisabled());
}
TEST_F(ConditionalCommandTest, AllCancelSelf) {
auto command = cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
auto command = Either(
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return true; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, AllCancelIncoming) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command = Either(Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
auto command = Either(
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}
TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) {
auto command =
cmd::Either(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
auto command = Either(
Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
Idle().WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
[] { return false; });
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.get()->GetInterruptionBehavior());
}

View File

@@ -16,7 +16,7 @@ TEST_F(DefaultCommandTest, DefaultCommandSchedule) {
TestSubsystem subsystem;
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command));
auto handle = scheduler.GetDefaultCommand(&subsystem);
@@ -30,8 +30,8 @@ TEST_F(DefaultCommandTest, DefaultCommandInterruptResume) {
TestSubsystem subsystem;
auto command1 = cmd::Idle({&subsystem});
auto command2 = cmd::Idle({&subsystem});
auto command1 = Idle({&subsystem});
auto command2 = Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command1));
auto handle = scheduler.GetDefaultCommand(&subsystem);

View File

@@ -55,7 +55,7 @@ TEST(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
int count = 0;
DeferredCommand command{[&count] {
count++;
return cmd::None();
return None();
},
{}};
@@ -70,7 +70,7 @@ TEST(DeferredCommandTest, DeferredSupplierOnlyCalledDuringInit) {
TEST(DeferredCommandTest, DeferredRequirements) {
TestSubsystem subsystem;
DeferredCommand command{cmd::None, {&subsystem}};
DeferredCommand command{None, {&subsystem}};
EXPECT_TRUE(command.GetRequirements().contains(&subsystem));
}

View File

@@ -15,7 +15,7 @@ TEST_F(InstantCommandTest, InstantCommandSchedule) {
int counter = 0;
auto command = cmd::RunOnce([&counter] { counter++; });
auto command = RunOnce([&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -79,7 +79,7 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupInterrupt) {
TEST_F(ParallelCommandGroupTest, ParallelGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Parallel(cmd::None(), cmd::None());
auto group = Parallel(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -89,9 +89,9 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Parallel(std::move(command));
auto group = Parallel(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -108,11 +108,11 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Parallel(std::move(command1), std::move(command2));
auto group = Parallel(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -96,7 +96,7 @@ TEST_F(ParallelDeadlineGroupTest, SequentialGroupInterrupt) {
TEST_F(ParallelDeadlineGroupTest, DeadlineGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Deadline(cmd::None(), cmd::None());
auto group = Deadline(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -106,9 +106,9 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Deadline(std::move(command));
auto group = Deadline(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -125,11 +125,11 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Deadline(std::move(command1), std::move(command2));
auto group = Deadline(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -91,7 +91,7 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceInterrupt) {
TEST_F(ParallelRaceGroupTest, ParallelRaceNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
auto group = cmd::Race(cmd::None(), cmd::None());
auto group = Race(None(), None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
@@ -101,9 +101,9 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Race(std::move(command));
auto group = Race(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -120,11 +120,11 @@ TEST_F(ParallelRaceGroupTest, RaceGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Race(std::move(command1), std::move(command2));
auto group = Race(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);
@@ -140,12 +140,12 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnce) {
bool finished2 = false;
bool finished3 = false;
auto command1 = cmd::WaitUntil([&finished1] { return finished1; });
auto command2 = cmd::WaitUntil([&finished2] { return finished2; });
auto command3 = cmd::WaitUntil([&finished3] { return finished3; });
auto command1 = WaitUntil([&finished1] { return finished1; });
auto command2 = WaitUntil([&finished2] { return finished2; });
auto command3 = WaitUntil([&finished3] { return finished3; });
auto group1 = cmd::Sequence(std::move(command1), std::move(command2));
auto group2 = cmd::Race(std::move(group1), std::move(command3));
auto group1 = Sequence(std::move(command1), std::move(command2));
auto group2 = Race(std::move(group1), std::move(command3));
scheduler.Schedule(group2);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ class PrintCommandTest : public CommandTestBase {};
TEST_F(PrintCommandTest, PrintCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Print("Test!");
auto command = Print("Test!");
testing::internal::CaptureStdout();

View File

@@ -54,7 +54,7 @@ TEST_F(ProxyCommandTest, OwningCommandSchedule) {
bool scheduled = false;
auto command = cmd::RunOnce([&scheduled] { scheduled = true; }).AsProxy();
auto command = RunOnce([&scheduled] { scheduled = true; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();
@@ -67,7 +67,7 @@ TEST_F(ProxyCommandTest, OwningCommandEnd) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; }).AsProxy();
auto command = WaitUntil([&finished] { return finished; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ TEST_F(RunCommandTest, RunCommandSchedule) {
int counter = 0;
auto command = cmd::Run([&counter] { counter++; });
auto command = wpi::cmd::Run([&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -16,7 +16,7 @@ class SchedulerTest : public CommandTestBase {};
TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::None();
auto command = None();
int counter = 0;
@@ -33,7 +33,7 @@ TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
TEST_F(SchedulerTest, SchedulerLambdaInterrupt) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Idle();
auto command = Idle();
int counter = 0;
@@ -57,7 +57,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptNoCause) {
counter++;
});
auto command = cmd::Idle();
auto command = Idle();
scheduler.Schedule(command);
scheduler.Cancel(command);
@@ -71,7 +71,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCause) {
int counter = 0;
TestSubsystem subsystem{};
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
scheduler.OnCommandInterrupt(
@@ -93,11 +93,11 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCauseInRunLoop) {
int counter = 0;
TestSubsystem subsystem{};
auto command = cmd::Idle({&subsystem});
auto command = Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
// This command will schedule interruptor in execute() inside the run loop
auto interruptorScheduler =
cmd::RunOnce([&] { scheduler.Schedule(&interruptor); });
RunOnce([&] { scheduler.Schedule(&interruptor); });
scheduler.OnCommandInterrupt(
[&](const Command&, const std::optional<Command*>& cause) {
@@ -143,8 +143,8 @@ TEST_F(SchedulerTest, UnregisterSubsystem) {
TEST_F(SchedulerTest, SchedulerCancelAll) {
CommandScheduler scheduler = GetScheduler();
auto command1 = cmd::Idle();
auto command2 = cmd::Idle();
auto command1 = Idle();
auto command2 = Idle();
int counter = 0;
@@ -167,7 +167,7 @@ TEST_F(SchedulerTest, ScheduleScheduledNoOp) {
int counter = 0;
auto command = cmd::StartEnd([&counter] { counter++; }, [] {});
auto command = StartEnd([&counter] { counter++; }, [] {});
scheduler.Schedule(command);
scheduler.Schedule(command);
@@ -202,9 +202,7 @@ TEST_F(SchedulerTest, ScheduleCommandPtr) {
{
auto commandPtr =
TrackDestroyCommand([&destructionCounter] { destructionCounter++; })
.AlongWith(wpi::cmd::InstantCommand([&runCounter] {
runCounter++;
}).ToPtr())
.AlongWith(InstantCommand([&runCounter] { runCounter++; }).ToPtr())
.Until([&finish] { return finish; });
EXPECT_EQ(destructionCounter, 0) << "Composition should not delete command";

View File

@@ -56,7 +56,8 @@ TEST_P(SchedulingRecursionTest, CancelFromInitialize) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.Schedule(&selfCancels);
scheduler.Run();
@@ -79,7 +80,8 @@ TEST_F(SchedulingRecursionTest, CancelFromInitializeAction) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.OnCommandInitialize([&scheduler, &selfCancels](const Command&) {
scheduler.Cancel(&selfCancels);
});
@@ -102,7 +104,8 @@ TEST_P(SchedulingRecursionTest,
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
auto other =
wpi::cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.SetDefaultCommand(&requirement, std::move(other));
scheduler.Schedule(&selfCancels);
@@ -285,7 +288,7 @@ TEST_P(SchedulingRecursionTest, ScheduleFromEndInterrupt) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
auto other = cmd::Idle({&requirement});
auto other = Idle({&requirement});
scheduler.Schedule(&selfCancels);
EXPECT_NO_THROW({ scheduler.Schedule(other); });
@@ -298,8 +301,8 @@ TEST_F(SchedulingRecursionTest, ScheduleFromEndInterruptAction) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
TestSubsystem requirement;
auto selfCancels = cmd::Idle({&requirement});
auto other = cmd::Idle({&requirement});
auto selfCancels = Idle({&requirement});
auto other = Idle({&requirement});
scheduler.OnCommandInterrupt([&](const Command&) {
counter++;
scheduler.Schedule(other);
@@ -320,7 +323,7 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
auto other = cmd::Idle({&requirement});
auto other = Idle({&requirement});
FunctionalCommand cancelDefaultCommand{[] {}, [] {},
[&](bool) {
counter++;
@@ -343,15 +346,15 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
TEST_F(SchedulingRecursionTest, CancelNextCommandFromCommand) {
CommandScheduler scheduler = GetScheduler();
wpi::cmd::RunCommand* command1Ptr = nullptr;
wpi::cmd::RunCommand* command2Ptr = nullptr;
RunCommand* command1Ptr = nullptr;
RunCommand* command2Ptr = nullptr;
int counter = 0;
auto command1 = wpi::cmd::RunCommand([&counter, &command2Ptr, &scheduler] {
auto command1 = RunCommand([&counter, &command2Ptr, &scheduler] {
scheduler.Cancel(command2Ptr);
counter++;
});
auto command2 = wpi::cmd::RunCommand([&counter, &command1Ptr, &scheduler] {
auto command2 = RunCommand([&counter, &command1Ptr, &scheduler] {
scheduler.Cancel(command1Ptr);
counter++;
});

View File

@@ -49,13 +49,12 @@ TEST_F(SelectCommandTest, SelectCommandRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto select =
cmd::Select<int>([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
auto select = Select<int>([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
scheduler.Schedule(select);
scheduler.Schedule(command3);

View File

@@ -106,9 +106,9 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupCopy) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
auto group = cmd::Sequence(std::move(command));
auto group = Sequence(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(group));
@@ -125,11 +125,11 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
auto command1 = RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = RunOnce([] {}, {&requirement3});
auto command3 = RunOnce([] {}, {&requirement3, &requirement4});
auto group = cmd::Sequence(std::move(command1), std::move(command2));
auto group = Sequence(std::move(command1), std::move(command2));
scheduler.Schedule(group);
scheduler.Schedule(command3);

View File

@@ -15,8 +15,7 @@ TEST_F(StartEndCommandTest, StartEndCommandSchedule) {
int counter = 0;
auto command =
cmd::StartEnd([&counter] { counter++; }, [&counter] { counter++; });
auto command = StartEnd([&counter] { counter++; }, [&counter] { counter++; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -17,7 +17,7 @@ TEST_F(WaitCommandTest, WaitCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
auto command = cmd::Wait(100_ms);
auto command = wpi::cmd::Wait(100_ms);
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -15,7 +15,7 @@ TEST_F(WaitUntilCommandTest, WaitUntilCommandSchedule) {
bool finished = false;
auto command = cmd::WaitUntil([&finished] { return finished; });
auto command = WaitUntil([&finished] { return finished; });
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -109,7 +109,7 @@ TEST_F(TriggerTest, WhileTrueLambdaRun) {
auto& scheduler = CommandScheduler::GetInstance();
int counter = 0;
bool pressed = false;
CommandPtr command = cmd::Run([&counter] { counter++; });
CommandPtr command = wpi::cmd::Run([&counter] { counter++; });
pressed = false;
Trigger([&pressed] { return pressed; }).WhileTrue(std::move(command));
@@ -130,8 +130,8 @@ TEST_F(TriggerTest, WhenTrueOnce) {
int endCounter = 0;
bool pressed = false;
CommandPtr command = cmd::StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
CommandPtr command = StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
pressed = false;
Trigger([&pressed] { return pressed; }).WhileTrue(std::move(command));
@@ -154,8 +154,8 @@ TEST_F(TriggerTest, ToggleOnTrue) {
bool pressed = false;
int startCounter = 0;
int endCounter = 0;
CommandPtr command = cmd::StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
CommandPtr command = StartEnd([&startCounter] { startCounter++; },
[&endCounter] { endCounter++; });
Trigger([&pressed] { return pressed; }).ToggleOnTrue(std::move(command));
scheduler.Run();