-
Notifications
You must be signed in to change notification settings - Fork 626
Add DackkaPlugin tests #4508
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
Open
daymxn
wants to merge
9
commits into
main
Choose a base branch
from
daymon-add-tests-for-dackka
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add DackkaPlugin tests #4508
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b498d0
Moved fixtures to resources
daymxn 32a0a5f
Added a test project for Dackka
daymxn ae51af3
Added output from test files for comparison
daymxn aa46cb1
Added a custom impl of the UNIX diff command
daymxn a38a192
Added tests for DackkaPlugin
daymxn 5c5614f
Added tasks to call the new tests
daymxn 3963d68
Fix the project fixture warnings
daymxn e11c194
Added newline for project docs in DakkaPlugin
daymxn 73c035c
Fix formatting
daymxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
buildSrc/src/test/kotlin/com/google/firebase/gradle/plugins/DackkaPluginTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.gradle.plugins | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import java.io.File | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.BeforeClass | ||
import org.junit.ClassRule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
/** | ||
* Ensures the current state of Dackka outputs what we expect from it. | ||
* | ||
* We do this by running the [DackkaPlugin] against a small project fixture and comparing the output | ||
* to a pre-compiled output that represents what we expect Dackka to generate. | ||
* | ||
* ## Resources | ||
* | ||
* The resources for the tests are stored under `src/test/resources/dackka-plugin-tests` with two | ||
* sub directories that will be explained below. | ||
* | ||
* ### project | ||
* | ||
* Directory containing a small gradle project, with various sub-projects. These exist to test edge | ||
* case scenarios in our doc generation- to ensure any changes do not break previous fixes. | ||
* | ||
* ### output | ||
* | ||
* Directory containing the **expected** output from running the [DackkaPlugin] against the | ||
* predefined project fixture. | ||
* | ||
* ## Updating Output | ||
* | ||
* Should the time come where Dackka behavior completely changes, the format changes, or maybe we | ||
* find a new edge-case; the output directory that gets compared during testing time should be | ||
* updated. | ||
* | ||
* Since the tests run on a project fixture, the easiest way to update the output is to add a clause | ||
* in the tests itself to overwrite the previous output. This behavior is not preferred, and should | ||
* be evaluated at a later date. You can see this in [DackkaPluginTests.updateDocs]. | ||
* | ||
* You can trigger this function to run one of two ways; passing the `rebuildDackkaOutput` property | ||
* to gradle during the build, or calling the `updateDackkaTestsPlugin` task. | ||
* | ||
* Example: | ||
* ``` | ||
* ./gradlew -b buildSrc/build.gradle.kts updateDackkaTestsPlugin | ||
* ``` | ||
*/ | ||
class DackkaPluginTests { | ||
|
||
companion object { | ||
@ClassRule @JvmField val testProjectDir = TemporaryFolder() | ||
|
||
private val resourcesDirectory = File("src/test/resources/dackka-plugin-tests/") | ||
private val outputDirectory = File("$resourcesDirectory/output/firebase-kotlindoc") | ||
|
||
@BeforeClass | ||
@JvmStatic | ||
fun setup() { | ||
copyFixtureToTempDirectory() | ||
buildDocs() | ||
if (System.getProperty("rebuildDackkaOutput") == "true") { | ||
updateDocs() | ||
} | ||
} | ||
|
||
/** | ||
* Updates the current docs and output to match an updated source. | ||
* | ||
* Unfortunately, we need GradleRunner to be able to do this automatically, and this was the | ||
* cleanest way I could accomplish such. I'm sure this can be fixed down the line should we | ||
* expand buildSrc into its own composite build. | ||
*/ | ||
private fun updateDocs() { | ||
removeOldOutputFiles() | ||
|
||
val docDirectory = File("${testProjectDir.root}/build/firebase-kotlindoc") | ||
|
||
docDirectory.copyRecursively(outputDirectory, true) | ||
} | ||
|
||
private fun removeOldOutputFiles() { | ||
outputDirectory.deleteRecursively() | ||
} | ||
|
||
private fun copyFixtureToTempDirectory() { | ||
val project = File("$resourcesDirectory/project") | ||
project.copyRecursively(testProjectDir.root) | ||
} | ||
|
||
private fun buildDocs() { | ||
GradleRunner.create() | ||
.withProjectDir(testProjectDir.root) | ||
.withPluginClasspath() | ||
.withArguments("kotlindoc") | ||
.build() | ||
} | ||
} | ||
|
||
@Test | ||
fun `Transforms correctly`() { | ||
val buildDirectory = File("${testProjectDir.root}/build") | ||
val docDirectory = File("$buildDirectory/firebase-kotlindoc") | ||
|
||
val diff = docDirectory.recursiveDiff(outputDirectory) | ||
val diffAsString = diff.joinToString("\n") | ||
|
||
println(diffAsString) | ||
assertThat(diffAsString).isEmpty() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...t/resources/dackka-plugin-tests/output/firebase-kotlindoc/android/client/module/_toc.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
toc: | ||
- title: "com.example" | ||
path: "/reference/com/example/package-summary.html" | ||
|
||
section: | ||
- title: "Interfaces" | ||
|
||
section: | ||
- title: "Phrase" | ||
path: "/reference/com/example/Phrase.html" | ||
|
||
- title: "Classes" | ||
|
||
section: | ||
- title: "CheckTheReleaseSpreadsheet" | ||
path: "/reference/com/example/CheckTheReleaseSpreadsheet.html" | ||
- title: "Goodbye" | ||
path: "/reference/com/example/Goodbye.html" | ||
- title: "Hello" | ||
path: "/reference/com/example/Hello.html" | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.