8000 Release/9.7.0 by JorelAli · Pull Request #618 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Release/9.7.0 #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 64 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b38936a
Set version to 9.6.2-SNAPSHOT
JorelAli Oct 28, 2024
558f09c
Create `commandapi-bukkit-test-toolkit`
willkroboth Jul 4, 2024
1816bff
Add `MockCommandAPIPlugin` for testing with `commandapi-bukkit-plugin`
willkroboth Jul 5, 2024
9ad579f
Add `assertCommandSucceeds` and `assertCommandFails` methods to Comma…
willkroboth Jul 5, 2024
8ed2acf
Add `assertCommandRunsWithArguments` methods to CommandAPITestUtilities
willkroboth Jul 9, 2024
d2fa55e
Implement testing IntegerRangeArgument NMS independently
willkroboth Jul 9, 2024
b86eb60
Fix CommandAPIHandler javadoc error that breaks full build
willkroboth Jul 9, 2024
be330ca
Add `assertCommandSuggests` methods to CommandAPITestUtilities
willkroboth Jul 10, 2024
7178477
Add `assertCommandFailsWithArguments` methods
willkroboth Jul 10, 2024
dafa99a
Improve coverage report by using Supplier<String> in CommandAPITestUt…
willkroboth Jul 10, 2024
83e5133
Add example argument and suggestion tests
willkroboth Jul 10, 2024
363c247
Add EntitySelectorArgument, PlayerArgument, and OfflinePlayerArgument…
willkroboth Jul 13, 2024
874770b
Implement ArgumentType suggestions for test toolkit
willkroboth Jul 16, 2024
2824ed8
Refactor Parser building syntax
willkroboth Jul 17, 2024
421fa57
Add README files for the test toolkit example projects
willkroboth Jul 17, 2024
4b67594
Add javadocs for important test toolkit methods and classes
willkroboth Jul 18, 2024
2ab0c17
Add docs for the test toolkit
willkroboth Jul 19, 2024
3b92c11
Fix trailing space (markdown lint)
willkroboth Jul 19, 2024
7b5750a
Add manual update notes to `update.sh`
willkroboth Jul 22, 2024
6b5f791
Allow developers to load custom MockCommandAPIBukkit instances in the…
willkroboth Aug 24, 2024
3b74499
Use translation keys instead of literal messages
willkroboth Sep 23, 2024
c8264e3
Update note about unimplemented methods in test_intro.md
willkroboth Sep 23, 2024
764f72e
Update MockBukkit-v1.21 to match paper updates
willkroboth Sep 23, 2024
5b286a3
Add javadocs to ArgumentUtilities and parser package
willkroboth Oct 6, 2024
87406f3
Update dependencies to 1.21
willkroboth Oct 16, 2024
40e8f87
Add @n to suggestions
willkroboth Oct 16, 2024
e9003b5
Add braces to inlined if-statements
willkroboth Oct 16, 2024
d2a8f88
Update documented dependency versions and mention gradle dependencies
willkroboth Oct 16, 2024
461f9f9
Fix markdownlint errors in test_setup.md
willkroboth Oct 16, 2024
ba8d578
Update MockBukkit to fix Paper 1.21 api update
willkroboth Oct 22, 2024
ac84d75
Rework `Parser` definition
willkroboth Oct 25, 2024
0bb04fa
Fix test-toolkit dependencies
willkroboth Oct 26, 2024
8688a08
Code review
willkroboth Oct 26, 2024
cf61f14
Update test toolkit versions to 9.6.2-SNAPSHOT manually
willkroboth Oct 28, 2024
e000a4b
Add new 9.6.0 NMS methods to MockCommandAPIBukkit
willkroboth Oct 28, 2024
c53e451
Merge pull request #575 from JorelAli/dev/simple-test-suite
willkroboth Oct 28, 2024
b27fc71
complete #529
MC-XiaoHei Nov 13, 2024
a47d939
format, docs, and fix tests
MC-XiaoHei Nov 15, 2024
1582991
format
MC-XiaoHei Nov 15, 2024
ab330ee
use const for more readable
MC-XiaoHei Nov 15, 2024
2c9b081
Update commandapi-core/src/main/java/dev/jorel/commandapi/AbstractArg…
MC-XiaoHei Nov 18, 2024
fd2eca8
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
90e6045
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
994653c
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 18, 2024
d0dd2c8
add thenNested() list ver, implement array ver with list ver
MC-XiaoHei Nov 18, 2024
0203144
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
3a8a6f2
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
59572b2
Update docssrc/src/commandtrees.md
MC-XiaoHei Nov 19, 2024
a31e859
implement nested { } with list ver thenNested() method
MC-XiaoHei Nov 19, 2024
54d3e36
Update commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/…
MC-XiaoHei Nov 19, 2024
8771911
fix indentation
MC-XiaoHei Nov 20, 2024
50fa068
fix indentation
MC-XiaoHei Nov 20, 2024
27b9360
Merge pull request #613 from MC-XiaoHei/dev/dev
JorelAli Nov 20, 2024
082bee7
Initial work for 1.21. 8000 4 support
DerEchtePilz Dec 3, 2024
ed915a3
Adds support for new Trail particle in 1.21.4
JorelAli Dec 3, 2024
0cb559a
Adds documentation for Trail particle and adds thenNested to the docu…
JorelAli Dec 3, 2024
362b8e6
Add 1.21.4 to the issue template
DerEchtePilz Dec 3, 2024
32319cf
Add test toolkit to 9.7.0 documentation changelog
willkroboth Dec 4, 2024
6017fd0
Set version to 9.7.0
JorelAli Dec 4, 2024
28cc2f5
Adds 9.7.0 documentation
JorelAli Dec 4, 2024
e79fb6e
Update homepage to point to 9.7.0
JorelAli Dec 4, 2024
aea0a3e
Generate 9.7.0 JavaDocs
JorelAli Dec 4, 2024
2e3adc2
Update documentation wiki.vg links to point to the MinecraftWiki wiki…
JorelAli Dec 4, 2024
7fe69b7
Merge branch 'master' into release/9.7.0
JorelAli Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add docs for the test toolkit
  • Loading branch information
willkroboth committed Oct 28, 2024
commit 2ab0c177b552d964c73e86ec7b45354deebfef35
18 changes: 17 additions & 1 deletion commandapi-documentation-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
Expand All @@ -69,6 +68,23 @@
<version>${project.version}</version>
</dependency>

<!-- Testing examples dependencies -->
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-test-toolkit</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
</dependency>

<!-- Other -->
<dependency>
<groupId>de.tr7zw</groupId>
Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************************************/

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.ParseResults;
Expand Down Expand Up @@ -74,6 +76,8 @@
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.EulerAngle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import java.util.*;
import java.util.Map.Entry;
Expand Down Expand Up @@ -2519,6 +2523,33 @@ void subcommands() {
/* ANCHOR_END: subcommands4 */
}

class test {
class Main extends JavaPlugin {

}
/* ANCHOR: testLoadMockPlugin1 */
@BeforeEach
public void setUp() {
// Set up MockBukkit server
ServerMock server = MockBukkit.mock();

// Load the CommandAPI plugin
MockCommandAPIPlugin.load(config -> config
.missingExecutorImplementationMessage("This command cannot be run by %S")
);

// Load our plugin
MockBukkit.load(Main.class);
}

@AfterEach
public void tearDown() {
// Reset for a clean slate next test
MockBukkit.unmock();
}
/* ANCHOR_END: testLoadMockPlugin1 */
}

class tooltips {
{
/* ANCHOR: tooltips1 */
Expand Down
7 changes: 7 additions & 0 deletions docssrc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
- [Using the DSL](./kotlindsl.md)
- [Delegated properties](./delegated_properties.md)

# Testing Framework

- [Testing Commands](./test_intro.md)
- [Set Up](./test_setup.md)
- [Loading Test CommandAPI](./test_loadmockplugin.md)
- [Testing Utilities](./test_utilities.md)

-----

# Velocity
Expand Down
15 changes: 15 additions & 0 deletions docssrc/src/test_intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Testing Commands

When developing large projects, it is good practice to add automated tests for your code. This section of the documentation describes how to use the `commandapi-bukkit-test-toolkit` dependency along with [MockBukkit](https://github.com/MockBukkit/MockBukkit) and [JUnit](https://junit.org/junit5/) to test the usage of commands registered with the CommandAPI.

For a big-picture view, you can find example projects that include automated tests in the [CommandAPI GitHub repository](https://github.com/JorelAli/CommandAPI/tree/master/examples).

<div class="warning">

**Developer's Note:**

Many methods have not yet been implemented in the test toolkit. Most notably, only [primitive arguments](./argument_primitives.md), [String arguments](./argument_strings.md), [literal arguments](./category_literal_arguments.md), and the [`IntegerRangeArgument`](./argument_range.md) are fully implemented. The [`EntitySelectorArgument`, `PlayerArgument`, and `OfflinePlayerArgument`](./argument_entities.md) should mostly work, though [target selector arguments](https://minecraft.wiki/w/Target_selectors#Target_selector_arguments) (e.g. `@e[type=pig]`) are not yet implemented.

If a test ends up calling a method that has not yet been implemented, an `UnimplementedMethodException` will be thrown, causing the test to fail. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/JorelAli/CommandAPI/issues) or a message in the CommandAPI Discord. Pull requests are also always welcome!

</div>
33 changes: 33 additions & 0 deletions docssrc/src/test_loadmockplugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Loading The CommandAPI in Tests

## Plugin Dependency

If your plugin depends on the CommandAPI plugin to load, when running tests you should load the `JavaPlugin` `MockCommandAPIPlugin` before you use MockBukkit to [load your plugin](https://mockbukkit.readthedocs.io/en/latest/first_tests.html#creating-the-test-class). You can either load this class directly with `MockBukkit.load(MockCommandAPIPlugin.class)`, or use one of the static `MockCommandAPIPlugin#load` methods:

```java
MockCommandAPIPlugin load()
```

Loads the CommandAPI Plugin in the test environment. Works exactly the same as `MockBukkit.load(MockCommandAPIPlugin.class)`.

```java
MockCommandAPIPlugin load(Consumer<CommandAPIBukkitConfig> configureSettings)
```

Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](./config.md#configuration-settings) using the methods provided by [CommandAPIBukkitConfig](./setup_shading.md#loading).

<div class="example">

### Example - Loading test CommandAPI with settings

To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPIBukkitConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run:

```java
{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:testLoadMockPlugin1}}
```

</div>

## Shaded Dependency

If your plugin shades the CommandAPI, the CommandAPI will automatically load as usual when you use MockBukkit to load your plugin. Just note that you **must** call `CommandAPI.onDisable()` in your plugin's `onDisable` method in order for the test environment to reset properly after each test.
89 changes: 89 additions & 0 deletions docssrc/src/test_setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Setting up your project

In the most common simple case, tests can be added directly next to plugin code. Code that goes in your final jar file is located in the `/src/main/` directory, while tests go in `/src/test/`. You can find more information about setting up your project for tests in the [JUnit](https://junit.org/junit5/docs/current/user-guide/#overview-getting-started-example-projects) documentation.

## Dependencies

When you add the dependencies for MockBukkit and `commandapi-bukkit-test-toolkit`, make sure to place them before your main dependencies for the CommandAPI and Spigot/Paper API. This ensures that certain classes that are compatible with the testing environment override the regular classes when running tests.

<div class="multi-pre">

```xml,Plugin_Dependency
<dependencies>
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-test-toolkit</artifactId>
<version>9.6.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
```

```xml,Shading_CommandAPI
<dependencies>
<dependency>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit-v1.20</artifactId>
<version>3.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-test-toolkit</artifactId>
<version>9.6.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-shade</artifactId>
<version>9.6.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
```

</div>
108 changes: 108 additions & 0 deletions docssrc/src/test_utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Testing Utilities

The class `CommandAPITestUtilities` provides many static methods to interact with commands registered in the test environment. The standard way to access these methods is by using the class name.

```java
import dev.jorel.commandapi.CommandAPITestUtilities;

class Tests {
@Test
void test() {
CommandAPITestUtilities.assertCommandSucceeds(...);
}
}
```

However, you can also call these methods with just the method name if you add a static import:

```java
import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds;

class Tests {
@Test
void test() {
assertCommandSucceeds(...);
}
}
```

or make your test class extend `CommandAPITestUtilities`:

```java
import dev.jorel.commandapi.CommandAPITestUtilities;

class Tests extends CommandAPITestUtilties {
@Test
void test() {
assertCommandSucceeds(...);
}
}
```

This is similar to importing static methods from the [`org.junit.jupiter.api.Assertions`](https://junit.org/junit5/docs/current/user-guide/#writing-tests-assertions) class, and may help make your tests easier to read.

## Running commands

There are 3 methods to test basic command execution:

```java
void dispatchCommand(CommandSender sender, String command) throws CommandSyntaxException
void assertCommandSucceeds(CommandSender sender, String command)
CommandSyntaxException assertCommandFails(CommandSender sender, String command, String expectedMessage)
```

`dispatchCommand` will simply attempt to execute a command. It may throw a `CommandSyntaxException` if the command fails, either because it wasn't a valid command or because your command executor threw a [`WrapperCommandSyntaxException`](./commandfailures.md#handling-command-failures).

`assertCommandSucceeeds` will run `dispatchCommand` and cause the test to fail if the command fails for any reason.

`assertCommandFails` will run `dispatchCommand` and cause the test to fail if the command does _not_ throw a `CommandSyntaxException`. This method will also fail if the command throws an exception but with a different error message than the `expectedMessage` String. It returns the `CommandSyntaxException` that was caught in case you want to inspect any other features of the exception.

## Verifying arguments

When a command is executed, you may want to assert that the Objects provided as arguments match your expectations. There are 4 basic methods for doing this:

```java
void assertCommandSucceedsWithArguments(CommandSender sender, String command, Object... argumentsArray)
void assertCommandSucceedsWithArguments(CommandSender sender, String command, Map<String, Object> argumentsMap)

void assertCommandFailsWithArguments(CommandSender sender, String command, String expectedFailureMessage, Object... argumentsArray)
void assertCommandFailsWithArguments(CommandSender sender, String command, String expectedFailureMessage, Map<String, Object> argumentsMap)
```

If you expect the command to succeed, use `assertCommandSucceedsWithArguments`. If you expect the command's executor to throw a [`WrapperCommandSyntaxException`](./commandfailures.md#handling-command-failures), use `assertCommandFailsWithArguments`. You can give these methods either an array or a Map holding all arguments you expect to be present for the command.

Note that if the command input cannot be parsed, the command will fail, but a CommandAPI executor will never be run. In this case, a CommandAPI executor will have never been run, so `assertCommandFailsWithArguments` will not have any arguments to inspect, and the test will fail. You can only successfully use `assertCommandFails` in this situation.

## Verifying suggestions

### Suggestion texts

There are 4 basic methods that may be used to verify the text of a command's suggestions:

```java
void assertCommandSuggests(CommandSender sender, String command, String... expectedSuggestions)
void assertCommandSuggests(CommandSender sender, String command, List<String> expectedSuggestions)

void assertCommandSuggests(CommandSender sender, String command, int startingAt, String... expectedSuggestions)
void assertCommandSuggests(CommandSender sender, String command, int startingAt, List<String> expectedSuggestions)
```

You can either provide the expected suggestions as an array or a List. Note that the suggestions will be provided in alphabetical order.

You can optionally provide a `startingAt` index. This is the place in the command String where you expect the first character of the suggestions will be placed.

### Suggestion tooltips

If the suggestions you want to check include [tooltips](./tooltips.md), you may use these 5 methods:

```java
Suggestion makeTooltip(String text, String tooltip);

void assertCommandSuggestsTooltips(CommandSender sender, String command, Suggestion... expectedSuggestions)
void assertCommandSuggestsTooltips(CommandSender sender, String command, List<Suggestion> expectedSuggestions)

void assertCommandSuggestsTooltips(CommandSender sender, String command, int startingAt, Suggestion... expectedSuggestions)
void assertCommandSuggestsTooltips(CommandSender sender, String command, int startingAt, List<Suggestion> expectedSuggestions)
```

The 4 `assertCommandSuggestsTooltips` methods work the same as the `assertCommandSuggests` methods, but you provide `Suggestion` objects containing both the text and a tooltip. The `makeTooltip` method allows you to easily create these `Suggestion` objects.
1 change: 1 addition & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sed -i "s/<version>$oldVer<\/version>/<version>$newVer<\/version>/" docssrc/src/
sed -i "s/<version>$oldVer<\/version>/<version>$newVer<\/version>/" docssrc/src/setup_dev.md
sed -i "s/<version>$oldVer<\/version>/<version>$newVer<\/version>/" docssrc/src/setup_annotations.md
sed -i "s/<version>$oldVer<\/version>/<version>$newVer<\/version>/" docssrc/src/kotlinintro.md
sed -i "s/<version>$oldVer<\/version>/<version>$newVer<\/version>/" docssrc/src/test_setup.md

# Gradle
sed -i "s/dev\.jorel:commandapi-bukkit-shade:$oldVer/dev\.jorel:commandapi-bukkit-shade:$newVer/" docssrc/src/setup_shading.md
Expand Down
0