From 09a0cdd16a98719edc8b965a24c09ec6a19cd6c3 Mon Sep 17 00:00:00 2001 From: Stef Tervelde Date: Sat, 28 Jun 2025 10:32:52 +0200 Subject: [PATCH] Add CLITest for testing CLI commands in Processing IDE Introduces a new Kotlin test class, CLITest, to facilitate running and testing CLI commands of the Processing IDE directly from the IDE. This allows for easier and faster development and debugging of CLI features without manual command line invocation. --- app/test/processing/app/CLITest.kt | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/test/processing/app/CLITest.kt diff --git a/app/test/processing/app/CLITest.kt b/app/test/processing/app/CLITest.kt new file mode 100644 index 000000000..2bd8cc81e --- /dev/null +++ b/app/test/processing/app/CLITest.kt @@ -0,0 +1,50 @@ +package processing.app + +import java.io.File +import kotlin.test.Test + +/* +This class is used to test the CLI commands of the Processing IDE. +It mostly exists to quickly run CLI commands without having to specify run configurations +or to manually run it on the command line. + +In IntelliJ IDEA, it should display runnable arrows next to each test method. +Use this to quickly test the CLI commands. +The output will be displayed in the console after `Running CLI with arguments: ...`. +When developing on the CLI commands, feel free to add more test methods here. + */ +class CLITest { + + @Test + fun testLSP(){ + runCLIWithArguments("lsp") + } + + @Test + fun testLegacyCLI(){ + runCLIWithArguments("cli --help") + } + + /* + This function runs the CLI with the given arguments. + */ + fun runCLIWithArguments(args: String) { + // TODO: Once Processing PDE correctly builds in IntelliJ IDEA switch over to using the code directly + // To see if the PDE builds correctly can be tested by running the Processing.kt main function directly in IntelliJ IDEA + // Set the JAVA_HOME environment variable to the JDK used by the IDE + println("Running CLI with arguments: $args") + val process = ProcessBuilder("./gradlew", "run", "--args=$args", "--quiet") + .directory(File(System.getProperty("user.dir")).resolve("../../../")) + .inheritIO() + + process.environment().apply { + put("JAVA_HOME", System.getProperty("java.home")) + } + + val result = process + .start() + .waitFor() + println("Done running CLI with arguments: $args (Result: $result)") + + } +} \ No newline at end of file