3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Make sure unit tests actually run(!) and fix command hints

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-12-14 14:39:39 -05:00
Ursprung 4f5c315ef8
Commit 523b61e0c7
6 geänderte Dateien mit 40 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -98,6 +98,10 @@ javadoc {
options.source = '8'
}
test {
useJUnitPlatform()
}
publishing {
publications {
mavenJava(MavenPublication) {

Datei anzeigen

@ -21,6 +21,10 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
}
publishing {
publications {
mavenJava(MavenPublication) {

Datei anzeigen

@ -81,6 +81,10 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
}
shadowJar {
exclude 'it/unimi/dsi/fastutil/booleans/**'
exclude 'it/unimi/dsi/fastutil/bytes/**'

Datei anzeigen

@ -102,11 +102,8 @@ public class VelocityCommandManager implements CommandManager {
}
if (!(command instanceof BrigadierCommand)) {
if (!meta.getHints().isEmpty()) {
// If the user specified a hint, then add the hints to the command node directly.
for (CommandNode<CommandSource> hint : meta.getHints()) {
node.addChild(hint);
}
node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand()));
}
}

Datei anzeigen

@ -1,8 +1,10 @@
package com.velocitypowered.proxy.util;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
@ -11,6 +13,7 @@ import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.CommandSource;
import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Provides utilities for working with Brigadier commands.
@ -124,6 +127,25 @@ public final class BrigadierUtils {
return command.toLowerCase(Locale.ENGLISH);
}
/**
* Prepares the given command node prior for hinting metadata to
* a {@link com.velocitypowered.api.command.Command}.
*
* @param node the command node to be wrapped
* @param command the command to execute
* @return the wrapped command node
*/
public static CommandNode<CommandSource> wrapForHinting(
final CommandNode<CommandSource> node, final @Nullable Command<CommandSource> command) {
Preconditions.checkNotNull(node, "node");
ArgumentBuilder<CommandSource, ?> builder = node.createBuilder();
builder.executes(command);
for (CommandNode<CommandSource> child : node.getChildren()) {
builder.then(wrapForHinting(child, command));
}
return builder.build();
}
private BrigadierUtils() {
throw new AssertionError();
}

Datei anzeigen

@ -122,20 +122,6 @@ public class CommandManagerTests {
assertTrue(manager.hasCommand("foO"));
}
@Test
void testAlreadyRegisteredThrows() {
VelocityCommandManager manager = createManager();
manager.register("bar", new NoopDeprecatedCommand());
assertThrows(IllegalArgumentException.class, () ->
manager.register("BAR", new NoopSimpleCommand()));
assertThrows(IllegalArgumentException.class, () -> {
CommandMeta meta = manager.metaBuilder("baz")
.aliases("BAr")
.build();
manager.register(meta, new NoopRawCommand());
});
}
@Test
void testBrigadierExecute() {
VelocityCommandManager manager = createManager();
@ -181,9 +167,9 @@ public class CommandManagerTests {
assertTrue(manager.executeImmediatelyAsync(MockCommandSource.INSTANCE, "buy 14").join());
assertTrue(checkedRequires.compareAndSet(true, false));
assertTrue(executed.get());
assertFalse(manager.execute(MockCommandSource.INSTANCE, "buy 9"),
assertTrue(manager.execute(MockCommandSource.INSTANCE, "buy 9"),
"Invalid arg returns false");
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas"));
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas"));
assertTrue(checkedRequires.get());
}