|
| 1 | +/* |
| 2 | + * Copyright 2017 Colin Fleming |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package cursive |
| 18 | + |
| 19 | +import org.assertj.core.api.KotlinAssertions.assertThat |
| 20 | +import org.gradle.testkit.runner.TaskOutcome |
| 21 | +import org.junit.Test |
| 22 | + |
| 23 | +class JavaAndClojureInOneSourceSetTest : IntegrationTestBase() { |
| 24 | + val coreNsSourceFile = testProjectDir.resolve("src/main/clojure/clj_example/core.clj") |
| 25 | + val utilsNsSourceFile = testProjectDir.resolve("src/main/clojure/clj_example/utils.clj") |
| 26 | + val javaClassFile = testProjectDir.resolve("build/classes/main/javaExample/Example.class") |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `Incremental compile task does not remove Java class files`() { |
| 30 | + // when |
| 31 | + val firstRunResult = projectBuildRunner().withArguments("build").build() |
| 32 | + |
| 33 | + // then |
| 34 | + assertThat(firstRunResult.task(":compileClojure").outcome).isEqualTo(TaskOutcome.SUCCESS) |
| 35 | + assertThat(firstRunResult.task(":compileJava").outcome).isEqualTo(TaskOutcome.SUCCESS) |
| 36 | + assertSourceFileIsOnlyCompiledToOutputDir(coreNsSourceFile) |
| 37 | + assertThat(javaClassFile.exists()).isTrue() |
| 38 | + |
| 39 | + coreNsSourceFile.delete() |
| 40 | + utilsNsSourceFile.writeText("""(ns clj-example.utils) (defn ping [] "pong")""") |
| 41 | + |
| 42 | + // when |
| 43 | + val secondRunResult = projectBuildRunner().withArguments("build").build() |
| 44 | + |
| 45 | + // then |
| 46 | + assertThat(secondRunResult.task(":compileClojure").outcome).isEqualTo(TaskOutcome.SUCCESS) |
| 47 | + assertThat(secondRunResult.task(":compileJava").outcome).isEqualTo(TaskOutcome.UP_TO_DATE) |
| 48 | + assertSourceFileNotCopiedToOutputDir(coreNsSourceFile) |
| 49 | + assertSourceFileNotCompiledToOutputDir(coreNsSourceFile) |
| 50 | + assertSourceFileIsOnlyCompiledToOutputDir(utilsNsSourceFile) |
| 51 | + assertThat(javaClassFile.exists()).isTrue() |
| 52 | + } |
| 53 | +} |
0 commit comments