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

Code before:
      false to e.stackTraceToString()
    } catch (e: PklException) {
      false to e.message!!
        .stripLineNumbers()
        .stripVersionCheckErrorMessage()
    }

    val stderr = logWriter.toString()

    return (success && stderr.isBlank()) to (output + stderr).stripFilePaths().stripWebsite()
  }
}

abstract class AbstractNativeLanguageSnippetTestsEngine : AbstractLanguageSnippetTestsEngine() {
  abstract val pklExecutablePath: Path

  override val excludedTests: List<Regex> = listOf(
    // exclude test that loads module from class path (there is no class path when using native executable)
    // on the other hand, don't exclude /native/
    Regex(".*/import1b\\.pkl"),
  )

  override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor {
    if (!pklExecutablePath.exists()) {
      // return empty descriptor w/o children
      return EngineDescriptor(uniqueId, javaClass.simpleName)
    }
    
    return super.discover(discoveryRequest, uniqueId)
  }
  
  override fun generateOutputFor(inputFile: Path): kotlin.Pair<Boolean, String> {
    val args = buildList {
      add(pklExecutablePath.toString())
      add("eval")
      add("--cache-dir")
      add(cacheDir.toString())
      if (inputFile.startsWith(projectsDir)) {
        val projectDir = inputFile.getProjectDir()
        if (projectDir != null) {
          add("--project-dir")
          add(projectDir.toString())
        }
      } else {
        add("--no-project")
        add("--property")
        add("name1=value1")
        add("--property")
        add("name2=value2")
        add("--property")
        add("/foo/bar=foobar")

Review comment (suggestion):
Warrants a comment.
```suggestion
  /**
   * Avoid running tests for native binaries when those native binaries have not been built.
   */
  override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor {
```

Code after:
      false to e.stackTraceToString()
    } catch (e: PklException) {
      false to e.message!!
        .stripLineNumbers()
        .stripVersionCheckErrorMessage()
    }

    val stderr = logWriter.toString()

    return (success && stderr.isBlank()) to (output + stderr).stripFilePaths().stripWebsite()
  }
}

abstract class AbstractNativeLanguageSnippetTestsEngine : AbstractLanguageSnippetTestsEngine() {
  abstract val pklExecutablePath: Path

  override val excludedTests: List<Regex> = listOf(
    // exclude test that loads module from class path (there is no class path when using native executable)
    // on the other hand, don't exclude /native/
    Regex(".*/import1b\\.pkl"),
  )

  /**
   * Avoid running tests for native binaries when those native binaries have not been built.
   */
  override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor {
    if (!pklExecutablePath.exists()) {
      // return empty descriptor w/o children
      return EngineDescriptor(uniqueId, javaClass.simpleName)
    }
    
    return super.discover(discoveryRequest, uniqueId)
  }
  
  override fun generateOutputFor(inputFile: Path): kotlin.Pair<Boolean, String> {
    val args = buildList {
      add(pklExecutablePath.toString())
      add("eval")
      add("--cache-dir")
      add(cacheDir.toString())
      if (inputFile.startsWith(projectsDir)) {
        val projectDir = inputFile.getProjectDir()
        if (projectDir != null) {
          add("--project-dir")
          add(projectDir.toString())
        }
      } else {
        add("--no-project")
        add("--property")
        add("name1=value1")
        add("--property")