mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[commands] Improve error message when composing commands twice in same composition (#6091)
Also disallow deadline command from also appearing in other commands.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior;
|
||||
@@ -112,4 +113,19 @@ abstract class MultiCompositionTestBase<T extends Command> extends SingleComposi
|
||||
var command = compose(command1, command2, command3);
|
||||
assertEquals(expected, command.runsWhenDisabled());
|
||||
}
|
||||
|
||||
static Stream<Arguments> composeDuplicates() {
|
||||
Command a = new InstantCommand(() -> {});
|
||||
Command b = new InstantCommand(() -> {});
|
||||
return Stream.of(
|
||||
arguments("AA", new Command[] {a, a}),
|
||||
arguments("ABA", new Command[] {a, b, a}),
|
||||
arguments("BAA", new Command[] {b, a, a}));
|
||||
}
|
||||
|
||||
@MethodSource
|
||||
@ParameterizedTest(name = "composeDuplicates[{index}]: {0}")
|
||||
void composeDuplicates(@SuppressWarnings("unused") String name, Command[] commands) {
|
||||
assertThrows(IllegalArgumentException.class, () -> compose(commands));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -124,6 +125,21 @@ class ParallelDeadlineGroupTest extends MultiCompositionTestBase<ParallelDeadlin
|
||||
IllegalArgumentException.class, () -> new ParallelDeadlineGroup(command1, command2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parallelDeadlineSetDeadlineToDeadlineTest() {
|
||||
Command a = new InstantCommand(() -> {});
|
||||
ParallelDeadlineGroup group = new ParallelDeadlineGroup(a);
|
||||
assertDoesNotThrow(() -> group.setDeadline(a));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parallelDeadlineSetDeadlineDuplicateTest() {
|
||||
Command a = new InstantCommand(() -> {});
|
||||
Command b = new InstantCommand(() -> {});
|
||||
ParallelDeadlineGroup group = new ParallelDeadlineGroup(a, b);
|
||||
assertThrows(IllegalArgumentException.class, () -> group.setDeadline(b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParallelDeadlineGroup compose(Command... members) {
|
||||
return new ParallelDeadlineGroup(members[0], Arrays.copyOfRange(members, 1, members.length));
|
||||
|
||||
Reference in New Issue
Block a user