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

This commit is contained in:
ハイドラント
2024-12-29 10:45:17 -06:00
committed by GitHub
parent e7dd5dca82
commit 78b6d61e88
30 changed files with 374 additions and 412 deletions

View File

@@ -8,6 +8,7 @@
#include <frc/simulation/SimHooks.h>
#include "CommandTestBase.h"
#include "frc2/command/Commands.h"
#include "frc2/command/FunctionalCommand.h"
#include "frc2/command/InstantCommand.h"
#include "frc2/command/RunCommand.h"
@@ -21,7 +22,7 @@ TEST_F(CommandDecoratorTest, WithTimeout) {
frc::sim::PauseTiming();
auto command = RunCommand([] {}, {}).WithTimeout(100_ms);
auto command = cmd::Idle().WithTimeout(100_ms);
scheduler.Schedule(command);
scheduler.Run();
@@ -42,7 +43,7 @@ TEST_F(CommandDecoratorTest, Until) {
bool finish = false;
auto command = RunCommand([] {}, {}).Until([&finish] { return finish; });
auto command = cmd::Idle().Until([&finish] { return finish; });
scheduler.Schedule(command);
scheduler.Run();
@@ -85,7 +86,7 @@ TEST_F(CommandDecoratorTest, OnlyWhile) {
bool run = true;
auto command = RunCommand([] {}, {}).OnlyWhile([&run] { return run; });
auto command = cmd::Idle().OnlyWhile([&run] { return run; });
scheduler.Schedule(command);
scheduler.Run();
@@ -126,7 +127,7 @@ TEST_F(CommandDecoratorTest, OnlyWhileOrder) {
TEST_F(CommandDecoratorTest, IgnoringDisable) {
CommandScheduler scheduler = GetScheduler();
auto command = RunCommand([] {}, {}).IgnoringDisable(true);
auto command = cmd::Idle().IgnoringDisable(true);
SetDSEnabled(false);
@@ -141,8 +142,7 @@ TEST_F(CommandDecoratorTest, BeforeStarting) {
bool finished = false;
auto command = InstantCommand([] {}, {}).BeforeStarting(
[&finished] { finished = true; });
auto command = cmd::None().BeforeStarting([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -162,8 +162,7 @@ TEST_F(CommandDecoratorTest, AndThenLambda) {
bool finished = false;
auto command =
InstantCommand([] {}, {}).AndThen([&finished] { finished = true; });
auto command = cmd::None().AndThen([&finished] { finished = true; });
scheduler.Schedule(command);
@@ -183,9 +182,9 @@ TEST_F(CommandDecoratorTest, AndThen) {
bool finished = false;
auto command1 = InstantCommand();
auto command2 = InstantCommand([&finished] { finished = true; });
auto group = std::move(command1).AndThen(std::move(command2).ToPtr());
auto command1 = cmd::None();
auto command2 = cmd::RunOnce([&finished] { finished = true; });
auto group = std::move(command1).AndThen(std::move(command2));
scheduler.Schedule(group);
@@ -205,10 +204,10 @@ TEST_F(CommandDecoratorTest, DeadlineFor) {
bool finish = false;
auto dictator = WaitUntilCommand([&finish] { return finish; });
auto endsAfter = WaitUntilCommand([] { return false; });
auto dictator = cmd::WaitUntil([&finish] { return finish; });
auto endsAfter = cmd::Idle();
auto group = std::move(dictator).DeadlineFor(std::move(endsAfter).ToPtr());
auto group = std::move(dictator).DeadlineFor(std::move(endsAfter));
scheduler.Schedule(group);
scheduler.Run();
@@ -247,10 +246,10 @@ TEST_F(CommandDecoratorTest, AlongWith) {
bool finish = false;
auto command1 = WaitUntilCommand([&finish] { return finish; });
auto command2 = InstantCommand();
auto command1 = cmd::WaitUntil([&finish] { return finish; });
auto command2 = cmd::None();
auto group = std::move(command1).AlongWith(std::move(command2).ToPtr());
auto group = std::move(command1).AlongWith(std::move(command2));
scheduler.Schedule(group);
scheduler.Run();
@@ -266,10 +265,10 @@ TEST_F(CommandDecoratorTest, AlongWith) {
TEST_F(CommandDecoratorTest, RaceWith) {
CommandScheduler scheduler = GetScheduler();
auto command1 = WaitUntilCommand([] { return false; });
auto command2 = InstantCommand();
auto command1 = cmd::Idle();
auto command2 = cmd::None();
auto group = std::move(command1).RaceWith(std::move(command2).ToPtr());
auto group = std::move(command1).RaceWith(std::move(command2));
scheduler.Schedule(group);
scheduler.Run();
@@ -290,12 +289,12 @@ TEST_F(CommandDecoratorTest, DeadlineForOrder) {
dictatorWasPolled = true;
return true;
});
auto other = RunCommand([&dictatorHasRun, &dictatorWasPolled] {
auto other = cmd::Run([&dictatorHasRun, &dictatorWasPolled] {
EXPECT_TRUE(dictatorHasRun);
EXPECT_TRUE(dictatorWasPolled);
});
auto group = std::move(dictator).DeadlineFor(std::move(other).ToPtr());
auto group = std::move(dictator).DeadlineFor(std::move(other));
scheduler.Schedule(group);
scheduler.Run();
@@ -343,12 +342,12 @@ TEST_F(CommandDecoratorTest, AlongWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = RunCommand([&firstHasRun, &firstWasPolled] {
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
auto group = std::move(command1).AlongWith(std::move(command2).ToPtr());
auto group = std::move(command1).AlongWith(std::move(command2));
scheduler.Schedule(group);
scheduler.Run();
@@ -369,12 +368,12 @@ TEST_F(CommandDecoratorTest, RaceWithOrder) {
firstWasPolled = true;
return true;
});
auto command2 = RunCommand([&firstHasRun, &firstWasPolled] {
auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] {
EXPECT_TRUE(firstHasRun);
EXPECT_TRUE(firstWasPolled);
});
auto group = std::move(command1).RaceWith(std::move(command2).ToPtr());
auto group = std::move(command1).RaceWith(std::move(command2));
scheduler.Schedule(group);
scheduler.Run();
@@ -389,8 +388,10 @@ TEST_F(CommandDecoratorTest, Unless) {
bool hasRun = false;
bool unlessCondition = true;
auto command = InstantCommand([&hasRun] { hasRun = true; }, {})
.Unless([&unlessCondition] { return unlessCondition; });
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] {
return unlessCondition;
});
scheduler.Schedule(command);
scheduler.Run();
@@ -408,8 +409,10 @@ TEST_F(CommandDecoratorTest, OnlyIf) {
bool hasRun = false;
bool onlyIfCondition = false;
auto command = InstantCommand([&hasRun] { hasRun = true; }, {})
.OnlyIf([&onlyIfCondition] { return onlyIfCondition; });
auto command =
cmd::RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] {
return onlyIfCondition;
});
scheduler.Schedule(command);
scheduler.Run();
@@ -481,8 +484,8 @@ TEST_F(CommandDecoratorTest, HandleInterrupt) {
}
TEST_F(CommandDecoratorTest, WithName) {
InstantCommand command;
auto command = cmd::None();
std::string name{"Named"};
CommandPtr named = std::move(command).WithName(name);
auto named = std::move(command).WithName(name);
EXPECT_EQ(name, named.get()->GetName());
}

View File

@@ -23,15 +23,13 @@ TYPED_TEST_SUITE_P(SingleCompositionRunsWhenDisabledTest);
TYPED_TEST_P(SingleCompositionRunsWhenDisabledTest, True) {
auto param = true;
TypeParam command = TypeParam(
cmd::WaitUntil([] { return false; }).IgnoringDisable(param).Unwrap());
TypeParam command = TypeParam(cmd::Idle().IgnoringDisable(param).Unwrap());
EXPECT_EQ(param, command.RunsWhenDisabled());
}
TYPED_TEST_P(SingleCompositionRunsWhenDisabledTest, False) {
auto param = false;
TypeParam command = TypeParam(
cmd::WaitUntil([] { return false; }).IgnoringDisable(param).Unwrap());
TypeParam command = TypeParam(cmd::Idle().IgnoringDisable(param).Unwrap());
EXPECT_EQ(param, command.RunsWhenDisabled());
}
@@ -44,17 +42,15 @@ TYPED_TEST_SUITE_P(SingleCompositionInterruptibilityTest);
TYPED_TEST_P(SingleCompositionInterruptibilityTest, CancelSelf) {
auto param = Command::InterruptionBehavior::kCancelSelf;
TypeParam command = TypeParam(cmd::WaitUntil([] { return false; })
.WithInterruptBehavior(param)
.Unwrap());
TypeParam command =
TypeParam(cmd::Idle().WithInterruptBehavior(param).Unwrap());
EXPECT_EQ(param, command.GetInterruptionBehavior());
}
TYPED_TEST_P(SingleCompositionInterruptibilityTest, CancelIncoming) {
auto param = Command::InterruptionBehavior::kCancelIncoming;
TypeParam command = TypeParam(cmd::WaitUntil([] { return false; })
.WithInterruptBehavior(param)
.Unwrap());
TypeParam command =
TypeParam(cmd::Idle().WithInterruptBehavior(param).Unwrap());
EXPECT_EQ(param, command.GetInterruptionBehavior());
}
@@ -77,47 +73,43 @@ TYPED_TEST_SUITE_P(MultiCompositionRunsWhenDisabledTest);
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, OneTrue) {
auto param = true;
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(param))));
TypeParam command = TypeParam(CommandPtr::UnwrapVector(
cmd::impl::MakeVector(cmd::Idle().IgnoringDisable(param))));
EXPECT_EQ(param, command.RunsWhenDisabled());
}
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, OneFalse) {
auto param = false;
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(param))));
TypeParam command = TypeParam(CommandPtr::UnwrapVector(
cmd::impl::MakeVector(cmd::Idle().IgnoringDisable(param))));
EXPECT_EQ(param, command.RunsWhenDisabled());
}
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, AllTrue) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true))));
cmd::Idle().IgnoringDisable(true), cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(true))));
EXPECT_EQ(true, command.RunsWhenDisabled());
}
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, AllFalse) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false))));
cmd::Idle().IgnoringDisable(false), cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(false))));
EXPECT_EQ(false, command.RunsWhenDisabled());
}
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, TwoTrueOneFalse) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false))));
cmd::Idle().IgnoringDisable(true), cmd::Idle().IgnoringDisable(true),
cmd::Idle().IgnoringDisable(false))));
EXPECT_EQ(false, command.RunsWhenDisabled());
}
TYPED_TEST_P(MultiCompositionRunsWhenDisabledTest, TwoFalseOneTrue) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(false),
cmd::WaitUntil([] { return false; }).IgnoringDisable(true))));
cmd::Idle().IgnoringDisable(false), cmd::Idle().IgnoringDisable(false),
cmd::Idle().IgnoringDisable(true))));
EXPECT_EQ(false, command.RunsWhenDisabled());
}
@@ -132,61 +124,49 @@ class MultiCompositionInterruptibilityTest
TYPED_TEST_SUITE_P(MultiCompositionInterruptibilityTest);
TYPED_TEST_P(MultiCompositionInterruptibilityTest, AllCancelSelf) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf))));
TypeParam command = TypeParam(CommandPtr::UnwrapVector(
cmd::impl::MakeVector(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf))));
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.GetInterruptionBehavior());
}
TYPED_TEST_P(MultiCompositionInterruptibilityTest, AllCancelIncoming) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] { return false; })
.WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming))));
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming))));
EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming,
command.GetInterruptionBehavior());
}
TYPED_TEST_P(MultiCompositionInterruptibilityTest, TwoCancelSelfOneIncoming) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf),
cmd::WaitUntil([] { return false; })
.WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming))));
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming))));
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.GetInterruptionBehavior());
}
TYPED_TEST_P(MultiCompositionInterruptibilityTest, TwoCancelIncomingOneSelf) {
TypeParam command = TypeParam(CommandPtr::UnwrapVector(cmd::impl::MakeVector(
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming),
cmd::WaitUntil([] {
return false;
}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf))));
TypeParam command = TypeParam(CommandPtr::UnwrapVector(
cmd::impl::MakeVector(cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelIncoming),
cmd::Idle().WithInterruptBehavior(
Command::InterruptionBehavior::kCancelSelf))));
EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf,
command.GetInterruptionBehavior());
}

View File

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

View File

@@ -5,6 +5,7 @@
#include <utility>
#include "CommandTestBase.h"
#include "frc2/command/Commands.h"
#include "frc2/command/RunCommand.h"
using namespace frc2;
@@ -15,9 +16,9 @@ TEST_F(DefaultCommandTest, DefaultCommandSchedule) {
TestSubsystem subsystem;
RunCommand command1([] {}, {&subsystem});
auto command = cmd::Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command1));
scheduler.SetDefaultCommand(&subsystem, std::move(command));
auto handle = scheduler.GetDefaultCommand(&subsystem);
scheduler.Run();
@@ -29,18 +30,18 @@ TEST_F(DefaultCommandTest, DefaultCommandInterruptResume) {
TestSubsystem subsystem;
RunCommand command1([] {}, {&subsystem});
RunCommand command2([] {}, {&subsystem});
auto command1 = cmd::Idle({&subsystem});
auto command2 = cmd::Idle({&subsystem});
scheduler.SetDefaultCommand(&subsystem, std::move(command1));
auto handle = scheduler.GetDefaultCommand(&subsystem);
scheduler.Run();
scheduler.Schedule(&command2);
scheduler.Schedule(command2);
EXPECT_TRUE(scheduler.IsScheduled(&command2));
EXPECT_TRUE(scheduler.IsScheduled(command2));
EXPECT_FALSE(scheduler.IsScheduled(handle));
scheduler.Cancel(&command2);
scheduler.Cancel(command2);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(handle));

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/InstantCommand.h"
using namespace frc2;
@@ -13,10 +14,10 @@ TEST_F(InstantCommandTest, InstantCommandSchedule) {
int counter = 0;
InstantCommand command([&counter] { counter++; }, {});
auto command = cmd::RunOnce([&counter] { counter++; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
EXPECT_FALSE(scheduler.IsScheduled(command));
EXPECT_EQ(counter, 1);
}

View File

@@ -78,9 +78,9 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupInterrupt) {
TEST_F(ParallelCommandGroupTest, ParallelGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelCommandGroup group((InstantCommand(), InstantCommand()));
auto group = cmd::Parallel(cmd::None(), cmd::None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
TEST_F(ParallelCommandGroupTest, ParallelGroupCopy) {
@@ -88,15 +88,15 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupCopy) {
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
auto command = cmd::WaitUntil([&finished] { return finished; });
ParallelCommandGroup group(command);
scheduler.Schedule(&group);
auto group = cmd::Parallel(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(group));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
TEST_F(ParallelCommandGroupTest, ParallelGroupRequirement) {
@@ -107,17 +107,17 @@ TEST_F(ParallelCommandGroupTest, ParallelGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
InstantCommand command1([] {}, {&requirement1, &requirement2});
InstantCommand command2([] {}, {&requirement3});
InstantCommand command3([] {}, {&requirement3, &requirement4});
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
ParallelCommandGroup group(std::move(command1), std::move(command2));
auto group = cmd::Parallel(std::move(command1), std::move(command2));
scheduler.Schedule(&group);
scheduler.Schedule(&command3);
scheduler.Schedule(group);
scheduler.Schedule(command3);
EXPECT_TRUE(scheduler.IsScheduled(&command3));
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(command3));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
INSTANTIATE_MULTI_COMMAND_COMPOSITION_TEST_SUITE(ParallelCommandGroupTest,

View File

@@ -95,9 +95,9 @@ TEST_F(ParallelDeadlineGroupTest, SequentialGroupInterrupt) {
TEST_F(ParallelDeadlineGroupTest, DeadlineGroupNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelDeadlineGroup group{InstantCommand(), InstantCommand()};
auto group = cmd::Deadline(cmd::None(), cmd::None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopy) {
@@ -105,15 +105,15 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineCopy) {
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
auto command = cmd::WaitUntil([&finished] { return finished; });
ParallelDeadlineGroup group(command);
scheduler.Schedule(&group);
auto group = cmd::Deadline(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(group));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirement) {
@@ -124,17 +124,17 @@ TEST_F(ParallelDeadlineGroupTest, ParallelDeadlineRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
InstantCommand command1([] {}, {&requirement1, &requirement2});
InstantCommand command2([] {}, {&requirement3});
InstantCommand command3([] {}, {&requirement3, &requirement4});
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
ParallelDeadlineGroup group(std::move(command1), std::move(command2));
auto group = cmd::Deadline(std::move(command1), std::move(command2));
scheduler.Schedule(&group);
scheduler.Schedule(&command3);
scheduler.Schedule(group);
scheduler.Schedule(command3);
EXPECT_TRUE(scheduler.IsScheduled(&command3));
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(command3));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
class TestableDeadlineCommand : public ParallelDeadlineGroup {

View File

@@ -90,9 +90,9 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceInterrupt) {
TEST_F(ParallelRaceGroupTest, ParallelRaceNotScheduledCancel) {
CommandScheduler scheduler = GetScheduler();
ParallelRaceGroup group{InstantCommand(), InstantCommand()};
auto group = cmd::Race(cmd::None(), cmd::None());
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(&group));
EXPECT_NO_FATAL_FAILURE(scheduler.Cancel(group));
}
TEST_F(ParallelRaceGroupTest, ParallelRaceCopy) {
@@ -100,15 +100,15 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceCopy) {
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
auto command = cmd::WaitUntil([&finished] { return finished; });
ParallelRaceGroup group(command);
scheduler.Schedule(&group);
auto group = cmd::Race(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(group));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
TEST_F(ParallelRaceGroupTest, RaceGroupRequirement) {
@@ -119,17 +119,17 @@ TEST_F(ParallelRaceGroupTest, RaceGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
InstantCommand command1([] {}, {&requirement1, &requirement2});
InstantCommand command2([] {}, {&requirement3});
InstantCommand command3([] {}, {&requirement3, &requirement4});
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
ParallelRaceGroup group(std::move(command1), std::move(command2));
auto group = cmd::Race(std::move(command1), std::move(command2));
scheduler.Schedule(&group);
scheduler.Schedule(&command3);
scheduler.Schedule(group);
scheduler.Schedule(command3);
EXPECT_TRUE(scheduler.IsScheduled(&command3));
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(command3));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnce) {
@@ -139,21 +139,21 @@ TEST_F(ParallelRaceGroupTest, ParallelRaceOnlyCallsEndOnce) {
bool finished2 = false;
bool finished3 = false;
WaitUntilCommand command1([&finished1] { return finished1; });
WaitUntilCommand command2([&finished2] { return finished2; });
WaitUntilCommand command3([&finished3] { return finished3; });
auto command1 = cmd::WaitUntil([&finished1] { return finished1; });
auto command2 = cmd::WaitUntil([&finished2] { return finished2; });
auto command3 = cmd::WaitUntil([&finished3] { return finished3; });
SequentialCommandGroup group1(command1, command2);
ParallelRaceGroup group2(std::move(group1), command3);
auto group1 = cmd::Sequence(std::move(command1), std::move(command2));
auto group2 = cmd::Race(std::move(group1), std::move(command3));
scheduler.Schedule(&group2);
scheduler.Schedule(group2);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&group2));
EXPECT_TRUE(scheduler.IsScheduled(group2));
finished1 = true;
scheduler.Run();
finished2 = true;
EXPECT_NO_FATAL_FAILURE(scheduler.Run());
EXPECT_FALSE(scheduler.IsScheduled(&group2));
EXPECT_FALSE(scheduler.IsScheduled(group2));
}
TEST_F(ParallelRaceGroupTest, ParallelRaceScheduleTwice) {

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include <regex>
#include "CommandTestBase.h"
@@ -13,15 +15,15 @@ class PrintCommandTest : public CommandTestBase {};
TEST_F(PrintCommandTest, PrintCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
PrintCommand command("Test!");
auto command = cmd::Print("Test!");
testing::internal::CaptureStdout();
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_TRUE(std::regex_search(testing::internal::GetCapturedStdout(),
std::regex("Test!")));
EXPECT_FALSE(scheduler.IsScheduled(&command));
EXPECT_FALSE(scheduler.IsScheduled(command));
}

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include <memory>
#include "CommandTestBase.h"
@@ -52,8 +54,7 @@ TEST_F(ProxyCommandTest, OwningCommandSchedule) {
bool scheduled = false;
CommandPtr command =
InstantCommand([&scheduled] { scheduled = true; }).AsProxy();
auto command = cmd::RunOnce([&scheduled] { scheduled = true; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();
@@ -66,8 +67,7 @@ TEST_F(ProxyCommandTest, OwningCommandEnd) {
bool finished = false;
CommandPtr command =
WaitUntilCommand([&finished] { return finished; }).AsProxy();
auto command = cmd::WaitUntil([&finished] { return finished; }).AsProxy();
scheduler.Schedule(command);
scheduler.Run();

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include "CommandTestBase.h"
#include "frc2/command/RunCommand.h"
@@ -13,9 +15,9 @@ TEST_F(RunCommandTest, RunCommandSchedule) {
int counter = 0;
RunCommand command([&counter] { counter++; }, {});
auto command = cmd::Run([&counter] { counter++; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
scheduler.Run();
scheduler.Run();

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include <utility>
#include "CommandTestBase.h"
@@ -15,7 +17,7 @@ class SchedulerTest : public CommandTestBase {};
TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
CommandScheduler scheduler = GetScheduler();
InstantCommand command;
auto command = cmd::None();
int counter = 0;
@@ -23,7 +25,7 @@ TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
scheduler.OnCommandExecute([&counter](const Command&) { counter++; });
scheduler.OnCommandFinish([&counter](const Command&) { counter++; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_EQ(counter, 3);
@@ -32,15 +34,15 @@ TEST_F(SchedulerTest, SchedulerLambdaTestNoInterrupt) {
TEST_F(SchedulerTest, SchedulerLambdaInterrupt) {
CommandScheduler scheduler = GetScheduler();
RunCommand command([] {}, {});
auto command = cmd::Idle();
int counter = 0;
scheduler.OnCommandInterrupt([&counter](const Command&) { counter++; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
scheduler.Cancel(&command);
scheduler.Cancel(command);
EXPECT_EQ(counter, 1);
}
@@ -56,10 +58,10 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptNoCause) {
counter++;
});
RunCommand command([] {});
auto command = cmd::Idle();
scheduler.Schedule(&command);
scheduler.Cancel(&command);
scheduler.Schedule(command);
scheduler.Cancel(command);
EXPECT_EQ(1, counter);
}
@@ -70,7 +72,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCause) {
int counter = 0;
TestSubsystem subsystem{};
RunCommand command([] {}, {&subsystem});
auto command = cmd::Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
scheduler.OnCommandInterrupt(
@@ -80,7 +82,7 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCause) {
counter++;
});
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Schedule(&interruptor);
EXPECT_EQ(1, counter);
@@ -92,11 +94,11 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCauseInRunLoop) {
int counter = 0;
TestSubsystem subsystem{};
RunCommand command([] {}, {&subsystem});
auto command = cmd::Idle({&subsystem});
InstantCommand interruptor([] {}, {&subsystem});
// This command will schedule interruptor in execute() inside the run loop
InstantCommand interruptorScheduler(
[&] { scheduler.Schedule(&interruptor); });
auto interruptorScheduler =
cmd::RunOnce([&] { scheduler.Schedule(&interruptor); });
scheduler.OnCommandInterrupt(
[&](const Command&, const std::optional<Command*>& cause) {
@@ -105,8 +107,8 @@ TEST_F(SchedulerTest, SchedulerLambdaInterruptCauseInRunLoop) {
counter++;
});
scheduler.Schedule(&command);
scheduler.Schedule(&interruptorScheduler);
scheduler.Schedule(command);
scheduler.Schedule(interruptorScheduler);
scheduler.Run();
@@ -142,8 +144,8 @@ TEST_F(SchedulerTest, UnregisterSubsystem) {
TEST_F(SchedulerTest, SchedulerCancelAll) {
CommandScheduler scheduler = GetScheduler();
RunCommand command([] {}, {});
RunCommand command2([] {}, {});
auto command1 = cmd::Idle();
auto command2 = cmd::Idle();
int counter = 0;
@@ -153,8 +155,8 @@ TEST_F(SchedulerTest, SchedulerCancelAll) {
EXPECT_FALSE(interruptor);
});
scheduler.Schedule(&command);
scheduler.Schedule(&command2);
scheduler.Schedule(command1);
scheduler.Schedule(command2);
scheduler.Run();
scheduler.CancelAll();
@@ -166,10 +168,10 @@ TEST_F(SchedulerTest, ScheduleScheduledNoOp) {
int counter = 0;
StartEndCommand command([&counter] { counter++; }, [] {});
auto command = cmd::StartEnd([&counter] { counter++; }, [] {});
scheduler.Schedule(&command);
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Schedule(command);
EXPECT_EQ(counter, 1);
}

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include <utility>
#include <gtest/gtest.h>
@@ -55,14 +57,14 @@ TEST_P(SchedulingRecursionTest, CancelFromInitialize) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
RunCommand other{[&hasOtherRun] { hasOtherRun = true; }, {&requirement}};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.Schedule(&selfCancels);
scheduler.Run();
scheduler.Schedule(&other);
scheduler.Schedule(other);
EXPECT_FALSE(scheduler.IsScheduled(&selfCancels));
EXPECT_TRUE(scheduler.IsScheduled(&other));
EXPECT_TRUE(scheduler.IsScheduled(other));
EXPECT_EQ(1, counter);
scheduler.Run();
EXPECT_TRUE(hasOtherRun);
@@ -78,16 +80,16 @@ TEST_F(SchedulingRecursionTest, CancelFromInitializeAction) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
RunCommand other{[&hasOtherRun] { hasOtherRun = true; }, {&requirement}};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.OnCommandInitialize([&scheduler, &selfCancels](const Command&) {
scheduler.Cancel(&selfCancels);
});
scheduler.Schedule(&selfCancels);
scheduler.Run();
scheduler.Schedule(&other);
scheduler.Schedule(other);
EXPECT_FALSE(scheduler.IsScheduled(&selfCancels));
EXPECT_TRUE(scheduler.IsScheduled(&other));
EXPECT_TRUE(scheduler.IsScheduled(other));
EXPECT_EQ(1, counter);
scheduler.Run();
EXPECT_TRUE(hasOtherRun);
@@ -101,7 +103,7 @@ TEST_P(SchedulingRecursionTest,
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
RunCommand other{[&hasOtherRun] { hasOtherRun = true; }, {&requirement}};
auto other = cmd::Run([&hasOtherRun] { hasOtherRun = true; }, {&requirement});
scheduler.SetDefaultCommand(&requirement, std::move(other));
scheduler.Schedule(&selfCancels);
@@ -202,6 +204,7 @@ TEST_F(SchedulingRecursionTest, CancelFromEndLoop) {
TEST_F(SchedulingRecursionTest, CancelFromEndLoopWhileInRunLoop) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
EndCommand dCancelsAll([&](bool) {
counter++;
scheduler.CancelAll();
@@ -270,7 +273,6 @@ TEST_P(SchedulingRecursionTest, ScheduleFromEndCancel) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
RunCommand other{[] {}, {&requirement}};
scheduler.Schedule(&selfCancels);
EXPECT_NO_THROW({ scheduler.Cancel(&selfCancels); });
@@ -284,30 +286,30 @@ TEST_P(SchedulingRecursionTest, ScheduleFromEndInterrupt) {
TestSubsystem requirement;
SelfCancellingCommand selfCancels{&scheduler, counter, &requirement,
GetParam()};
RunCommand other{[] {}, {&requirement}};
auto other = cmd::Idle({&requirement});
scheduler.Schedule(&selfCancels);
EXPECT_NO_THROW({ scheduler.Schedule(&other); });
EXPECT_NO_THROW({ scheduler.Schedule(other); });
EXPECT_EQ(1, counter);
EXPECT_FALSE(scheduler.IsScheduled(&selfCancels));
EXPECT_TRUE(scheduler.IsScheduled(&other));
EXPECT_TRUE(scheduler.IsScheduled(other));
}
TEST_F(SchedulingRecursionTest, ScheduleFromEndInterruptAction) {
CommandScheduler scheduler = GetScheduler();
int counter = 0;
TestSubsystem requirement;
RunCommand selfCancels{[] {}, {&requirement}};
RunCommand other{[] {}, {&requirement}};
auto selfCancels = cmd::Idle({&requirement});
auto other = cmd::Idle({&requirement});
scheduler.OnCommandInterrupt([&](const Command&) {
counter++;
scheduler.Schedule(&other);
scheduler.Schedule(other);
});
scheduler.Schedule(&selfCancels);
EXPECT_NO_THROW({ scheduler.Schedule(&other); });
scheduler.Schedule(selfCancels);
EXPECT_NO_THROW({ scheduler.Schedule(other); });
EXPECT_EQ(1, counter);
EXPECT_FALSE(scheduler.IsScheduled(&selfCancels));
EXPECT_TRUE(scheduler.IsScheduled(&other));
EXPECT_FALSE(scheduler.IsScheduled(selfCancels));
EXPECT_TRUE(scheduler.IsScheduled(other));
}
TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
@@ -319,11 +321,11 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
[&counter](bool) { counter++; },
[] { return false; },
{&requirement}};
RunCommand other{[] {}, {&requirement}};
auto other = cmd::Idle({&requirement});
FunctionalCommand cancelDefaultCommand{[] {}, [] {},
[&](bool) {
counter++;
scheduler.Schedule(&other);
scheduler.Schedule(other);
},
[] { return false; }};
@@ -336,7 +338,7 @@ TEST_F(SchedulingRecursionTest, CancelDefaultCommandFromEnd) {
});
EXPECT_EQ(2, counter);
EXPECT_FALSE(scheduler.IsScheduled(&defaultCommand));
EXPECT_TRUE(scheduler.IsScheduled(&other));
EXPECT_TRUE(scheduler.IsScheduled(other));
}
TEST_F(SchedulingRecursionTest, CancelNextCommandFromCommand) {

View File

@@ -48,18 +48,19 @@ TEST_F(SelectCommandTest, SelectCommandRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
InstantCommand command1([] {}, {&requirement1, &requirement2});
InstantCommand command2([] {}, {&requirement3});
InstantCommand command3([] {}, {&requirement3, &requirement4});
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
SelectCommand<int> select([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
auto select =
cmd::Select<int>([] { return 1; }, std::pair(1, std::move(command1)),
std::pair(2, std::move(command2)));
scheduler.Schedule(&select);
scheduler.Schedule(&command3);
scheduler.Schedule(select);
scheduler.Schedule(command3);
EXPECT_TRUE(scheduler.IsScheduled(&command3));
EXPECT_FALSE(scheduler.IsScheduled(&select));
EXPECT_TRUE(scheduler.IsScheduled(command3));
EXPECT_FALSE(scheduler.IsScheduled(select));
}
class TestableSelectCommand : public SelectCommand<int> {

View File

@@ -105,15 +105,15 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupCopy) {
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
auto command = cmd::WaitUntil([&finished] { return finished; });
SequentialCommandGroup group(command);
scheduler.Schedule(&group);
auto group = cmd::Sequence(std::move(command));
scheduler.Schedule(group);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(group));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
TEST_F(SequentialCommandGroupTest, SequentialGroupRequirement) {
@@ -124,17 +124,17 @@ TEST_F(SequentialCommandGroupTest, SequentialGroupRequirement) {
TestSubsystem requirement3;
TestSubsystem requirement4;
InstantCommand command1([] {}, {&requirement1, &requirement2});
InstantCommand command2([] {}, {&requirement3});
InstantCommand command3([] {}, {&requirement3, &requirement4});
auto command1 = cmd::RunOnce([] {}, {&requirement1, &requirement2});
auto command2 = cmd::RunOnce([] {}, {&requirement3});
auto command3 = cmd::RunOnce([] {}, {&requirement3, &requirement4});
SequentialCommandGroup group(std::move(command1), std::move(command2));
auto group = cmd::Sequence(std::move(command1), std::move(command2));
scheduler.Schedule(&group);
scheduler.Schedule(&command3);
scheduler.Schedule(group);
scheduler.Schedule(command3);
EXPECT_TRUE(scheduler.IsScheduled(&command3));
EXPECT_FALSE(scheduler.IsScheduled(&group));
EXPECT_TRUE(scheduler.IsScheduled(command3));
EXPECT_FALSE(scheduler.IsScheduled(group));
}
INSTANTIATE_MULTI_COMMAND_COMPOSITION_TEST_SUITE(SequentialCommandGroupTest,

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include "CommandTestBase.h"
#include "frc2/command/StartEndCommand.h"
@@ -13,13 +15,13 @@ TEST_F(StartEndCommandTest, StartEndCommandSchedule) {
int counter = 0;
StartEndCommand command([&counter] { counter++; }, [&counter] { counter++; },
{});
auto command =
cmd::StartEnd([&counter] { counter++; }, [&counter] { counter++; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
scheduler.Run();
scheduler.Cancel(&command);
scheduler.Cancel(command);
EXPECT_EQ(2, counter);
}

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include <frc/simulation/SimHooks.h>
#include "CommandTestBase.h"
@@ -16,14 +18,14 @@ TEST_F(WaitCommandTest, WaitCommandSchedule) {
CommandScheduler scheduler = GetScheduler();
WaitCommand command(100_ms);
auto command = cmd::Wait(100_ms);
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
EXPECT_TRUE(scheduler.IsScheduled(command));
frc::sim::StepTiming(110_ms);
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
EXPECT_FALSE(scheduler.IsScheduled(command));
frc::sim::ResumeTiming();
}

View File

@@ -2,6 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <frc2/command/Commands.h>
#include "CommandTestBase.h"
#include "frc2/command/WaitUntilCommand.h"
@@ -13,12 +15,12 @@ TEST_F(WaitUntilCommandTest, WaitUntilCommandSchedule) {
bool finished = false;
WaitUntilCommand command([&finished] { return finished; });
auto command = cmd::WaitUntil([&finished] { return finished; });
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
EXPECT_TRUE(scheduler.IsScheduled(command));
finished = true;
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
EXPECT_FALSE(scheduler.IsScheduled(command));
}