|
| 1 | +package com.google.devtools.ksp.test |
| 2 | + |
| 3 | +import com.google.devtools.ksp.test.fixtures.TemporaryTestProject |
| 4 | +import org.gradle.testkit.runner.BuildResult |
| 5 | +import org.gradle.testkit.runner.GradleRunner |
| 6 | +import org.gradle.testkit.runner.TaskOutcome |
| 7 | +import org.junit.Assert |
| 8 | +import org.junit.Assume |
| 9 | +import org.junit.Rule |
| 10 | +import org.junit.Test |
| 11 | + |
| 12 | +class NullabilityAnnotationsIT() { |
| 13 | + @Rule |
| 14 | + @JvmField |
| 15 | + val project: TemporaryTestProject = TemporaryTestProject("nullability-annotations") |
| 16 | + |
| 17 | + private fun GradleRunner.buildAndCheck(vararg args: String, extraCheck: (BuildResult) -> Unit = {}) = |
| 18 | + buildAndCheckOutcome(*args, outcome = TaskOutcome.SUCCESS, extraCheck = extraCheck) |
| 19 | + |
| 20 | + private fun GradleRunner.buildAndCheckOutcome( |
| 21 | + vararg args: String, |
| 22 | + outcome: TaskOutcome, |
| 23 | + extraCheck: (BuildResult) -> Unit = {} |
| 24 | + ) { |
| 25 | + val result = this.withArguments(*args).build() |
| 26 | + |
| 27 | + Assert.assertEquals(outcome, result.task(":workload:build")?.outcome) |
| 28 | + |
| 29 | + extraCheck(result) |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + fun testNullableAnnotations() { |
| 34 | + // FIXME: `clean` fails to delete files on windows. |
| 35 | + Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows", ignoreCase = true)) |
| 36 | + val gradleRunner = GradleRunner.create().withProjectDir(project.root) |
| 37 | + gradleRunner.buildAndCheck("clean", "build") { result -> |
| 38 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s0: (String..String?)\n")) |
| 39 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s1: String?\n")) |
| 40 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s2: String\n")) |
| 41 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s3: [@Nullable] String?\n")) |
| 42 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s4: [@NotNull] String\n")) |
| 43 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s5: [@Nullable] String?\n")) |
| 44 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s6: [@NonNull] String\n")) |
| 45 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s7: (String..String?)\n")) |
| 46 | + Assert.assertTrue(result.output.contains("w: [ksp] [Nullability check] s8: (String..String?)\n")) |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments