diff options
author | nickreid <nickreid@google.com> | 2022-07-22 09:48:34 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-07-22 09:49:17 -0700 |
commit | 1afa217c5ba3f467998d1475590591bc10fd2815 (patch) | |
tree | 8d35639e7be61fec44421480b87cc7858e47deb9 /tests | |
parent | 4ed105aaeb66460f5da948635db3dd5d6040fa61 (diff) | |
download | bazelbuild-kotlin-rules-1afa217c5ba3f467998d1475590591bc10fd2815.tar.gz |
Support tree-artifacts containing Java in common.kt_jvm_library.
This change also adds checks for unexpected src types.
PiperOrigin-RevId: 462643106
Diffstat (limited to 'tests')
-rw-r--r-- | tests/analysis/jvm_compile_test.bzl | 16 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/BUILD | 66 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/JavaInJavaDir.java | 31 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/JavaSrc.java | 31 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/JavaSrcjar.java | 31 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/KtInKotlinDir.kt | 29 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/KtSrc.kt | 29 | ||||
-rw-r--r-- | tests/jvm/java/srcartifacts/SrcArtifactsTest.kt | 47 |
8 files changed, 277 insertions, 3 deletions
diff --git a/tests/analysis/jvm_compile_test.bzl b/tests/analysis/jvm_compile_test.bzl index 31ba75c..899266d 100644 --- a/tests/analysis/jvm_compile_test.bzl +++ b/tests/analysis/jvm_compile_test.bzl @@ -326,11 +326,21 @@ def _test_kt_jvm_compile_unsupported_src_artifacts(): name = test_name + "/src.java", content = "", ) - - # TODO: Add java_srcjar and java_dir inputs + java_dir = create_dir( + name = test_name + "/java", + subdir = "", + srcs = [create_file( + name = test_name + "/dir.java", + content = "", + )], + ) + java_srcjar = create_file( + name = test_name + "/java.srcjar", + content = "", + ) _kt_jvm_compile( name = test_name + "_expected_lib", - srcs = [kt_src, kt_dir, java_src], + srcs = [kt_src, kt_dir, java_src, java_dir, java_srcjar], tags = ONLY_FOR_ANALYSIS_TEST_TAGS, ) diff --git a/tests/jvm/java/srcartifacts/BUILD b/tests/jvm/java/srcartifacts/BUILD new file mode 100644 index 0000000..8407f11 --- /dev/null +++ b/tests/jvm/java/srcartifacts/BUILD @@ -0,0 +1,66 @@ +# Copyright 2022 Google LLC. All rights reserved. +# +# 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. + +load("@//kotlin:rules.bzl", "kt_jvm_test") +load("@//tests/analysis:util.bzl", "create_dir") + +package(default_testonly = 1) + +licenses(["notice"]) + +kt_jvm_test( + name = "srcartifacts", + srcs = [ + "JavaSrc.java", + "KtSrc.kt", + "SrcArtifactsTest.kt", + ":JavaSrcjar_gen", + ":dir/java", + ":dir/kotlin", + ], + test_class = "srcartifacts.SrcArtifactsTest", + deps = [ + "@maven//:com_google_truth_truth", + "@maven//:junit_junit", + ], +) + +create_dir( + name = "dir/java", + srcs = [ + "JavaInJavaDir.java", + ], + subdir = "srcartifacts", +) + +create_dir( + name = "dir/kotlin", + srcs = [ + "KtInKotlinDir.kt", + ], + subdir = "srcartifacts", +) + +genrule( + name = "JavaSrcjar_gen", + srcs = [":libJavaSrcjar_lib-src.jar"], + outs = ["JavaSrcjar.srcjar"], + cmd = "cp $(location :libJavaSrcjar_lib-src.jar) $(location :JavaSrcjar.srcjar)", +) + +java_library( + name = "JavaSrcjar_lib", + srcs = ["JavaSrcjar.java"], + tags = ["manual"], +) diff --git a/tests/jvm/java/srcartifacts/JavaInJavaDir.java b/tests/jvm/java/srcartifacts/JavaInJavaDir.java new file mode 100644 index 0000000..70aa7c9 --- /dev/null +++ b/tests/jvm/java/srcartifacts/JavaInJavaDir.java @@ -0,0 +1,31 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts; + +import java.util.Set; + +final class JavaInJavaDir implements SrcArtifact { + @Override + public Set<Class<? extends SrcArtifact>> getAllSrcArtifacts() { + return Set.of( + JavaInJavaDir.class, // + JavaSrc.class, + JavaSrcjar.class, + KtInKotlinDir.class, + KtSrc.class); + } +} diff --git a/tests/jvm/java/srcartifacts/JavaSrc.java b/tests/jvm/java/srcartifacts/JavaSrc.java new file mode 100644 index 0000000..4fdb1c7 --- /dev/null +++ b/tests/jvm/java/srcartifacts/JavaSrc.java @@ -0,0 +1,31 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts; + +import java.util.Set; + +final class JavaSrc implements SrcArtifact { + @Override + public Set<Class<? extends SrcArtifact>> getAllSrcArtifacts() { + return Set.of( + JavaInJavaDir.class, // + JavaSrc.class, + JavaSrcjar.class, + KtInKotlinDir.class, + KtSrc.class); + } +} diff --git a/tests/jvm/java/srcartifacts/JavaSrcjar.java b/tests/jvm/java/srcartifacts/JavaSrcjar.java new file mode 100644 index 0000000..1be65d5 --- /dev/null +++ b/tests/jvm/java/srcartifacts/JavaSrcjar.java @@ -0,0 +1,31 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts; + +import java.util.Set; + +final class JavaSrcjar implements SrcArtifact { + @Override + public Set<Class<? extends SrcArtifact>> getAllSrcArtifacts() { + return Set.of( + JavaInJavaDir.class, // + JavaSrc.class, + JavaSrcjar.class, + KtInKotlinDir.class, + KtSrc.class); + } +} diff --git a/tests/jvm/java/srcartifacts/KtInKotlinDir.kt b/tests/jvm/java/srcartifacts/KtInKotlinDir.kt new file mode 100644 index 0000000..dd2b96d --- /dev/null +++ b/tests/jvm/java/srcartifacts/KtInKotlinDir.kt @@ -0,0 +1,29 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts + +class KtInKotlinDir() : SrcArtifact { + override fun getAllSrcArtifacts(): Set<Class<out SrcArtifact>> { + return setOf( + JavaInJavaDir::class.java, + JavaSrc::class.java, + JavaSrcjar::class.java, + KtInKotlinDir::class.java, + KtSrc::class.java, + ) + } +} diff --git a/tests/jvm/java/srcartifacts/KtSrc.kt b/tests/jvm/java/srcartifacts/KtSrc.kt new file mode 100644 index 0000000..cca27dc --- /dev/null +++ b/tests/jvm/java/srcartifacts/KtSrc.kt @@ -0,0 +1,29 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts + +class KtSrc() : SrcArtifact { + override fun getAllSrcArtifacts(): Set<Class<out SrcArtifact>> { + return setOf( + JavaInJavaDir::class.java, + JavaSrc::class.java, + JavaSrcjar::class.java, + KtInKotlinDir::class.java, + KtSrc::class.java, + ) + } +} diff --git a/tests/jvm/java/srcartifacts/SrcArtifactsTest.kt b/tests/jvm/java/srcartifacts/SrcArtifactsTest.kt new file mode 100644 index 0000000..e996491 --- /dev/null +++ b/tests/jvm/java/srcartifacts/SrcArtifactsTest.kt @@ -0,0 +1,47 @@ +/* + * * Copyright 2022 Google LLC. All rights reserved. + * + * 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 srcartifacts + +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +interface SrcArtifact { + fun getAllSrcArtifacts(): Set<Class<out SrcArtifact>> +} + +@RunWith(JUnit4::class) +class SrcArtifactsTest { + + @Test + fun allSrcArtifactsInterop() { + val allSrcArtifacts = + setOf( + JavaInJavaDir::class.java, + JavaSrc::class.java, + JavaSrcjar::class.java, + KtInKotlinDir::class.java, + KtSrc::class.java, + ) + + for (artifact in allSrcArtifacts) { + val instance = artifact.getDeclaredConstructor().newInstance() + assertThat(instance.getAllSrcArtifacts()).isEqualTo(allSrcArtifacts) + } + } +} |