Repository: apple/pkl
File: pkl-executor/src/test/kotlin/org/pkl/executor/EmbeddedExecutorTest.kt (Kotlin)

Code before:
    fun afterAll() {
      for (executor in allExecutors) {
        if (executor.isInitialized()) executor.value.close()
      }
    }

    // a Pkl distribution that supports ExecutorSpiOptions up to v1
    private val pklDistribution1: Path by lazy {
      FileTestUtils.rootProjectDir.resolve("pkl-executor/build/pklDistributions/pkl-config-java-all-0.25.0.jar").apply {
        if (!exists()) {
          throw AssertionError("Missing test fixture. " +
            "To fix this problem, run `./gradlew :pkl-executor:prepareTest`.")
        }
      }
    }

    // a Pkl distribution that supports ExecutorSpiOptions up to v2
    private val pklDistribution2: Path by lazy {
      val path = System.getProperty("pklDistributionCurrent")?.toPath() ?:
        // can get rid of this path by switching to IntelliJ's Gradle test runner
        FileTestUtils.rootProjectDir
          .resolve("pkl-config-java/build/libs/pkl-config-java-all-" +
            "${Release.current().version().withBuild(null).toString().replaceFirst("dev", "SNAPSHOT")}.jar")
      path.apply {
        if (!exists()) throw AssertionError("Missing test fixture. " +
          "To fix this problem, run `./gradlew :pkl-config-java:build`.")
      }
    }

    private fun convertToOptions2(options: ExecutorOptions): ExecutorOptions2 =
      if (options is ExecutorOptions2) options else ExecutorOptions2(
        options.allowedModules,
        options.allowedResources,
        options.environmentVariables,
        options.externalProperties,
        options.modulePath,
        options.rootDir,
        options.timeout,
        options.outputFormat,
        options.moduleCacheDir,
        options.projectDir,
        listOf(),
        listOf()
      )

    private fun convertToOptions1(options: ExecutorOptions): ExecutorOptions =
      if (options.javaClass == ExecutorOptions::class.java) options else ExecutorOptions(
        options.allowedModules,
        options.allowedResources,
        options.environmentVariables,
        options.externalProperties,

Review comment (suggestion):
It's much safer to always run `:pkl-executor:prepareTest`, which, by definition, is what's needed to run pkl-executor tests. `pkl-config-java:build` does more than what's needed (e.g., runs all pkl-config-java tests) and may also do less.

I can't tell if you want every Gradle build to prepare for running `EmbeddedExecutorTest` with IntelliJ. If you do, there's no point in keeping the system properties around. If you don't, both system properties should be kept, and `test.dependsOn(prepareTest)` should be replaced with `test.dependsOn(pklDistributionCurrent, pklDistribution025)`.

Code after:
    fun afterAll() {
      for (executor in allExecutors) {
        if (executor.isInitialized()) executor.value.close()
      }
    }

    // a Pkl distribution that supports ExecutorSpiOptions up to v1
    private val pklDistribution1: Path by lazy {
      FileTestUtils.rootProjectDir.resolve("pkl-executor/build/pklHistoricalDistributions/pkl-config-java-all-0.25.0.jar").apply {
        if (!exists()) {
          throw AssertionError("Missing test fixture. " +
            "To fix this problem, run `./gradlew :pkl-executor:prepareTest`.")
        }
      }
    }

    // a Pkl distribution that supports ExecutorSpiOptions up to v2
    private val pklDistribution2: Path by lazy {
      FileTestUtils.rootProjectDir
        .resolve("pkl-config-java/build/libs/pkl-config-java-all-" +
          "${Release.current().version().withBuild(null).toString().replaceFirst("dev", "SNAPSHOT")}.jar").apply {
        if (!exists()) throw AssertionError("Missing test fixture. " +
          "To fix this problem, run `./gradlew :pkl-executor:prepareTest`.")
      }
    }

    private fun convertToOptions2(options: ExecutorOptions): ExecutorOptions2 =
      if (options is ExecutorOptions2) options else ExecutorOptions2(
        options.allowedModules,
        options.allowedResources,
        options.environmentVariables,
        options.externalProperties,
        options.modulePath,
        options.rootDir,
        options.timeout,
        options.outputFormat,
        options.moduleCacheDir,
        options.projectDir,
        listOf(),
        listOf()
      )

    private fun convertToOptions1(options: ExecutorOptions): ExecutorOptions =
      if (options.javaClass == ExecutorOptions::class.java) options else ExecutorOptions(
        options.allowedModules,
        options.allowedResources,
        options.environmentVariables,
        options.externalProperties,
        options.modulePath,
        options.rootDir,
        options.timeout,