Skip to content
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

NMS independent test toolkit to allow developers to test their commands with MockBukkit #575

Open
wants to merge 28 commits into
base: dev/dev
Choose a base branch
from

Commits on Aug 22, 2024

  1. Create commandapi-bukkit-test-toolkit

    Create `automated-tests-shaded` example project to test using the test toolkit
    
    Resolves #356
    
    Alternative idea to current work on `dev/public-test-suite`
    
    Attempts to allow developers to test their commands independently of any version or nms stuff. Currently, most of the methods throw an UnimplementedMethodException, but I have implemented enough to get the simple `PingPongCommandTests` file to work as a proof of concept.
    
    TODO:
    - Implement the methods required to test:
      - `commandapi-bukkit-plugin` based projects
      - Common arguments
      - Suggestions
    - Write documentation
    - Maybe add a module to more rigorously test the toolkit without cluttering the example project
    
    I think if we can get a simple version working and published as a snapshot, users can try it out and identify methods that need to be implemented.
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    2edad90 View commit details
    Browse the repository at this point in the history
  2. Add MockCommandAPIPlugin for testing with commandapi-bukkit-plugin

    Add automated-tests example project for showing testing with `commandapi-bukkit-plugin`
    
    Remove unnecessary plugin constructors (it seems MockBukkit does not need them)
    
    Add MockCommandAPIPluginLoadingTests to thoroughly test loading options without cluttering example projects
    
    Fix some typos
    
    Fix some logging-based warnings
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    ce2c907 View commit details
    Browse the repository at this point in the history
  3. Add assertCommandSucceeds and assertCommandFails methods to Comma…

    …ndAPITestUtilities
    
    Add DispatchCommandUtilitiesTests to fully test these methods
    
    Add CommandTestBase to provide utilities when testing the test toolkit
    
    Enable Jacoco code coverage report for `commandapi-test-toolkit`
    
    Add some comments
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    313c299 View commit details
    Browse the repository at this point in the history
  4. Add assertCommandRunsWithArguments methods to CommandAPITestUtilities

    Add CommandAPIHandlerSpy and ExecutionQueue to intercept and track command executions
    
    Add AssertArgumentUtilitiesTests and ExecutionQueueTests
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    ab04a99 View commit details
    Browse the repository at this point in the history
  5. Implement testing IntegerRangeArgument NMS independently

    Add IntegerRangeArgumentType to let Brigadier parse input to IntegerRange. Currently, the exceptions thrown are just their raw strings. I couldn't seem to get the translations keys `argument.range.empty` and `argument.range.swapped` to resolve due to MockBukkit/MockBukkit#1040.
    
    Implement Parser builder to make defining object parsers easier. Inspired by Brigadier command parse trees and #544.
    
    Add IntegerRangeArgumentTests
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    1c604f9 View commit details
    Browse the repository at this point in the history
  6. Fix CommandAPIHandler javadoc error that breaks full build

    e08a90a made `CommandAPIHandler#generateCommand` public instead of protected so CommandAPIHandlerSpy could intercept invocations. This promoted a javadoc warning into a javadoc error that stopped the build.
    
    Javadocs incorrectly indicated that `CommandAPIHandler#generateCommand` could throw a CommandSyntaxException, when it actually returns a lambda that could throw that exception (Brigadier's Command interface).
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    8d10c62 View commit details
    Browse the repository at this point in the history
  7. Add assertCommandSuggests methods to CommandAPITestUtilities

    Add AssertSuggestionUtilitiesTest
    
    Some tweaks to internal testing error messages
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    afc0bc6 View commit details
    Browse the repository at this point in the history
  8. Add assertCommandFailsWithArguments methods

    Allows verifying the input to command executors when they end up throwing a WrapperCommandSyntaxException
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    9e04b02 View commit details
    Browse the repository at this point in the history
  9. Improve coverage report by using Supplier<String> in CommandAPITestUt…

    …ilities
    
    If the tests don't check the case where an assertion failed, the supplier won't run, so Jacoco can detect uncovered code.
    
    Cover and fix such a gap in `CommandAPITestUtilities#getExecutionInfo`
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    5d8a164 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    6e6d69c View commit details
    Browse the repository at this point in the history
  11. Add EntitySelectorArgument, PlayerArgument, and OfflinePlayerArgument…

    … to test toolkit
    
    I was initially going to just do PlayerArgument because I thought it would have simple suggestions. I then realized that OfflinePlayerArgument was basically the same argument, so I did that as well.
    
    The ProfileArgumentType is also basically half a EntitySelectorParser, so I did the EntitySelectorArgument as well, though selector options are currently left unimplemented.
    
    I wrote tests for all these, and that took a while.
    
    I still haven't implemented any ArgumentType suggestions code...
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    29f5e66 View commit details
    Browse the repository at this point in the history
  12. Implement ArgumentType suggestions for test toolkit

    I think the way I set up the Parser builder to support suggestions makes sense. It works at least.
    
    Parser now returns Result object, which tracks whether an object was returned or an exception was thrown, as well as a SuggestionProvider for the current location. Default methods added to Parser to handle this result appropriately when either parsing or suggesting.
    
    Moved Parser into its own package and extracted some of the inner classes and interfaces. Package-protected access accomplishes the same sort of encapsulation.
    
    Added methods to CommandAPITestUtilities to assert that suggestions are located at a specific offset index.
    
    Added tests~
    willkroboth committed Aug 22, 2024
    Configuration menu
    Copy the full SHA
    e78f12f View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    122581d View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    2e102aa View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    f4663f5 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    e25ba25 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    0ee2fe0 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    525f12d View commit details
    Browse the repository at this point in the history

Commits on Aug 24, 2024

  1. Allow developers to load custom MockCommandAPIBukkit instances in the…

    …ir tests
    
    This makes it possible to avoid UnimplementedMethodExceptions by overriding and implementing the method yourself
    
    NOTE: CommandAPIVersionHandler was changed from an interface to an abstract class so the test-toolkit version could have a non-final field. I don't think this affects anything else.
    willkroboth committed Aug 24, 2024
    Configuration menu
    Copy the full SHA
    f71519e View commit details
    Browse the repository at this point in the history

Commits on Sep 23, 2024

  1. Use translation keys instead of literal messages

    Updated test toolkit's MockBukkit version to include MockBukkit/MockBukkit#1077, which allows accessing Minecraft Language codes.
    
    Moved utilities for creating mock argument parsers into ArgumentUtilities class.
    
    Made example project build script run maven tests, so the tests in the `automated-tests` and `automated-tests-shaded` example projects are run by GitHub Actions.
    willkroboth committed Sep 23, 2024
    Configuration menu
    Copy the full SHA
    fd86f3d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cd4adae View commit details
    Browse the repository at this point in the history
  3. Update MockBukkit-v1.21 to match paper updates

    It seems that MockBukkit and Paper API need to match exactly. This seems a little annoying, because if something in Paper updates their API, a MockBukkit version can suddenly stop working, but you'll only realize once your local cached copy of paper-api updates.
    willkroboth committed Sep 23, 2024
    Configuration menu
    Copy the full SHA
    03d875f View commit details
    Browse the repository at this point in the history

Commits on Oct 6, 2024

  1. Add javadocs to ArgumentUtilities and parser package

    Users may want to use these methods if they are trying to implement an ArgumentType that isn't currently provided by the test toolkit. This ideally also makes the Parser system understandable for developers who are not me :P.
    willkroboth committed Oct 6, 2024
    Configuration menu
    Copy the full SHA
    5ade948 View commit details
    Browse the repository at this point in the history

Commits on Oct 16, 2024

  1. Configuration menu
    Copy the full SHA
    051d88f View commit details
    Browse the repository at this point in the history
  2. Add @n to suggestions

    Missed this when 1.21 came out and added @n.
    Future idea: allow users to specify a version to account for behavior like this that changes by version. For now though, matching latest behavior makes sense.
    willkroboth committed Oct 16, 2024
    Configuration menu
    Copy the full SHA
    a3e38e7 View commit details
    Browse the repository at this point in the history
  3. Add braces to inlined if-statements

    Other one line if statements do have `{ }`, so these were inconsistent.
    willkroboth committed Oct 16, 2024
    Configuration menu
    Copy the full SHA
    d7987b2 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0da49f1 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    498d8e6 View commit details
    Browse the repository at this point in the history