aboutsummaryrefslogtreecommitdiff
path: root/dokka-runners/dokkatoo/modules/dokkatoo-plugin/src/testFunctional/kotlin/GradlePluginProjectIntegrationTest.kt
blob: d35150a260d162e067ff7bb5f4f1cf00bd03277b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package org.jetbrains.dokka.dokkatoo

import org.jetbrains.dokka.dokkatoo.internal.DokkatooConstants
import org.jetbrains.dokka.dokkatoo.utils.*
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.inspectors.shouldForAll
import io.kotest.matchers.sequences.shouldNotBeEmpty
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldNotContain

class GradlePluginProjectIntegrationTest : FunSpec({

  context("given a gradle plugin project") {
    val project = initGradlePluginProject()

    project.runner
      .addArguments(
        "clean",
        "dokkatooGeneratePublicationHtml",
        "--stacktrace",
      )
      .forwardOutput()
      .build {

        test("expect project builds successfully") {
          output shouldContain "BUILD SUCCESSFUL"
        }

        test("expect no 'unknown class' message in HTML files") {
          val htmlFiles = project.projectDir.toFile()
            .resolve("build/dokka/html")
            .walk()
            .filter { it.isFile && it.extension == "html" }

          htmlFiles.shouldNotBeEmpty()

          htmlFiles.forEach { htmlFile ->
            val relativePath = htmlFile.relativeTo(project.projectDir.toFile())
            withClue("$relativePath should not contain Error class: unknown class") {
              htmlFile.useLines { lines ->
                lines.shouldForAll { line -> line.shouldNotContain("Error class: unknown class") }
              }
            }
          }
        }
      }
  }
})

private fun initGradlePluginProject(
  config: GradleProjectTest.() -> Unit = {},
): GradleProjectTest {
  return gradleKtsProjectTest("gradle-plugin-project") {

    settingsGradleKts += """
      |
    """.trimMargin()

    buildGradleKts = """
      |plugins {
      |  `kotlin-dsl`
      |  id("org.jetbrains.dokka.dokkatoo") version "${DokkatooConstants.DOKKATOO_VERSION}"
      |}
      |
    """.trimMargin()

    dir("src/main/kotlin") {

      createKotlinFile(
        "MyCustomGradlePlugin.kt",
        """
          |package com.project.gradle.plugin
          |
          |import javax.inject.Inject
          |import org.gradle.api.Plugin
          |import org.gradle.api.Project
          |import org.gradle.api.model.ObjectFactory
          |import org.gradle.kotlin.dsl.*
          |
          |abstract class MyCustomGradlePlugin @Inject constructor(
          |  private val objects: ObjectFactory
          |) : Plugin<Project> {
          |  override fun apply(project: Project) {
          |    println(objects.property<String>().getOrElse("empty"))
          |  }
          |}

        """.trimMargin()
      )

      createKotlinFile(
        "MyCustomGradlePluginExtension.kt",
        """
          |package com.project.gradle.plugin
          |
          |import org.gradle.api.provider.*
          |
          |interface MyCustomGradlePluginExtension {
          |  val versionProperty: Property<String>
          |  val versionProvider: Provider<String>
          |}
          |
        """.trimMargin()
      )
    }

    config()
  }
}