mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
Fix internal deprecation warnings (#4257)
This allows us to error out on deprecation warnings for thirdparty libraries and standard library features. Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
@@ -254,6 +254,7 @@ public interface Command {
|
||||
* @return the decorated command
|
||||
* @deprecated use {@link #endlessly()} instead.
|
||||
*/
|
||||
@SuppressWarnings("removal") // PerpetualCommand
|
||||
@Deprecated(forRemoval = true, since = "2023")
|
||||
default PerpetualCommand perpetually() {
|
||||
return new PerpetualCommand(this);
|
||||
|
||||
@@ -56,6 +56,7 @@ public class PerpetualCommand extends CommandBase {
|
||||
return m_command.runsWhenDisabled();
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal") // Command.perpetually()
|
||||
@Override
|
||||
public PerpetualCommand perpetually() {
|
||||
return this;
|
||||
|
||||
@@ -87,7 +87,9 @@ SequentialCommandGroup Command::AndThen(
|
||||
}
|
||||
|
||||
PerpetualCommand Command::Perpetually() && {
|
||||
WPI_IGNORE_DEPRECATED
|
||||
return PerpetualCommand(std::move(*this).TransferOwnership());
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
}
|
||||
|
||||
EndlessCommand Command::Endlessly() && {
|
||||
|
||||
@@ -31,8 +31,7 @@ namespace frc2 {
|
||||
*
|
||||
* @deprecated replace with EndlessCommand
|
||||
*/
|
||||
class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
|
||||
: public CommandHelper<CommandBase, PerpetualCommand> {
|
||||
class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
|
||||
public:
|
||||
/**
|
||||
* Creates a new PerpetualCommand. Will run another command in perpetuity,
|
||||
@@ -41,8 +40,10 @@ class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
|
||||
*
|
||||
* @param command the command to run perpetually
|
||||
*/
|
||||
WPI_DEPRECATED("Replace with EndlessCommand")
|
||||
explicit PerpetualCommand(std::unique_ptr<Command>&& command);
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
/**
|
||||
* Creates a new PerpetualCommand. Will run another command in perpetuity,
|
||||
* ignoring that command's end conditions, unless this command itself is
|
||||
@@ -52,9 +53,11 @@ class WPI_DEPRECATED("Replace with EndlessCommand") PerpetualCommand
|
||||
*/
|
||||
template <class T, typename = std::enable_if_t<std::is_base_of_v<
|
||||
Command, std::remove_reference_t<T>>>>
|
||||
WPI_DEPRECATED("Replace with EndlessCommand")
|
||||
explicit PerpetualCommand(T&& command)
|
||||
: PerpetualCommand(std::make_unique<std::remove_reference_t<T>>(
|
||||
std::forward<T>(command))) {}
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
PerpetualCommand(PerpetualCommand&& other) = default;
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ class CommandDecoratorTest extends CommandTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal") // Command.perpetually()
|
||||
@Test
|
||||
void perpetuallyTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
@@ -184,6 +185,22 @@ class CommandDecoratorTest extends CommandTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void endlesslyTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
Command command = new InstantCommand();
|
||||
|
||||
Command perpetual = command.endlessly();
|
||||
|
||||
scheduler.schedule(perpetual);
|
||||
scheduler.run();
|
||||
scheduler.run();
|
||||
scheduler.run();
|
||||
|
||||
assertTrue(scheduler.isScheduled(perpetual));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void unlessTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// 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.
|
||||
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class EndlessCommandTest extends CommandTestBase {
|
||||
@Test
|
||||
void endlessCommandScheduleTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
EndlessCommand command = new EndlessCommand(new InstantCommand());
|
||||
|
||||
scheduler.schedule(command);
|
||||
scheduler.run();
|
||||
|
||||
assertTrue(scheduler.isScheduled(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +137,8 @@ class ParallelRaceGroupTest extends CommandTestBase {
|
||||
Command command1 = command1Holder.getMock();
|
||||
MockCommandHolder command2Holder = new MockCommandHolder(true, system2);
|
||||
Command command2 = command2Holder.getMock();
|
||||
MockCommandHolder perpetualCommandHolder = new MockCommandHolder(true);
|
||||
Command command3 = new PerpetualCommand(perpetualCommandHolder.getMock());
|
||||
MockCommandHolder endlessCommandHolder = new MockCommandHolder(true);
|
||||
Command command3 = new EndlessCommand(endlessCommandHolder.getMock());
|
||||
|
||||
Command group1 = new SequentialCommandGroup(command1, command2);
|
||||
assertNotNull(group1);
|
||||
|
||||
@@ -9,6 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PerpetualCommandTest extends CommandTestBase {
|
||||
@SuppressWarnings("removal") // PerpetualCommand
|
||||
@Test
|
||||
void perpetualCommandScheduleTest() {
|
||||
try (CommandScheduler scheduler = new CommandScheduler()) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class ScheduleCommandTest extends CommandTestBase {
|
||||
new SequentialCommandGroup(new InstantCommand(), scheduleCommand);
|
||||
|
||||
scheduler.schedule(group);
|
||||
scheduler.schedule(new InstantCommand().perpetually());
|
||||
scheduler.schedule(new InstantCommand().endlessly());
|
||||
scheduler.run();
|
||||
assertDoesNotThrow(scheduler::run);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "CommandTestBase.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
#include "frc2/command/EndlessCommand.h"
|
||||
#include "frc2/command/InstantCommand.h"
|
||||
#include "frc2/command/ParallelRaceGroup.h"
|
||||
#include "frc2/command/PerpetualCommand.h"
|
||||
@@ -93,7 +94,22 @@ TEST_F(CommandDecoratorTest, AndThen) {
|
||||
TEST_F(CommandDecoratorTest, Perpetually) {
|
||||
CommandScheduler scheduler = GetScheduler();
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
auto command = InstantCommand([] {}, {}).Perpetually();
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
scheduler.Schedule(&command);
|
||||
|
||||
scheduler.Run();
|
||||
scheduler.Run();
|
||||
|
||||
EXPECT_TRUE(scheduler.IsScheduled(&command));
|
||||
}
|
||||
|
||||
TEST_F(CommandDecoratorTest, Endlessly) {
|
||||
CommandScheduler scheduler = GetScheduler();
|
||||
|
||||
auto command = InstantCommand([] {}, {}).Endlessly();
|
||||
|
||||
scheduler.Schedule(&command);
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// 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 "CommandTestBase.h"
|
||||
#include "frc2/command/EndlessCommand.h"
|
||||
#include "frc2/command/InstantCommand.h"
|
||||
|
||||
using namespace frc2;
|
||||
class EndlessCommandTest : public CommandTestBase {};
|
||||
|
||||
TEST_F(EndlessCommandTest, EndlessCommandSchedule) {
|
||||
CommandScheduler scheduler = GetScheduler();
|
||||
|
||||
bool check = false;
|
||||
|
||||
EndlessCommand command{InstantCommand([&check] { check = true; }, {})};
|
||||
|
||||
scheduler.Schedule(&command);
|
||||
scheduler.Run();
|
||||
EXPECT_TRUE(scheduler.IsScheduled(&command));
|
||||
EXPECT_TRUE(check);
|
||||
}
|
||||
@@ -14,7 +14,9 @@ TEST_F(PerpetualCommandTest, PerpetualCommandSchedule) {
|
||||
|
||||
bool check = false;
|
||||
|
||||
WPI_IGNORE_DEPRECATED
|
||||
PerpetualCommand command{InstantCommand([&check] { check = true; }, {})};
|
||||
WPI_UNIGNORE_DEPRECATED
|
||||
|
||||
scheduler.Schedule(&command);
|
||||
scheduler.Run();
|
||||
|
||||
Reference in New Issue
Block a user