aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/analysis/assert_failure_test.bzl31
-rw-r--r--tests/analysis/compiler_plugin/BUILD23
-rw-r--r--tests/analysis/compiler_plugin/propagation/BUILD79
-rw-r--r--tests/analysis/compiler_plugin/propagation/assert_propagation_test.bzl57
-rw-r--r--tests/analysis/compiler_plugin/provider_output/BUILD58
-rw-r--r--tests/analysis/compiler_plugin/provider_output/assert_compiler_plugin_test.bzl38
-rw-r--r--tests/analysis/for_test.bzl40
-rw-r--r--tests/analysis/internal_do_not_use/util/file_factory/BUILD41
-rw-r--r--tests/analysis/internal_do_not_use/util/file_factory/check_base_file_valid.bzl38
-rw-r--r--tests/analysis/internal_do_not_use/util/file_factory/happy_test.bzl78
-rw-r--r--tests/analysis/jvm_compile_test.bzl391
-rw-r--r--tests/analysis/jvm_import_test.bzl169
-rw-r--r--tests/analysis/jvm_library/runtime_deps/Input.kt16
-rw-r--r--tests/analysis/jvm_library/treeartifacts_srcs/Input.kt16
-rw-r--r--tests/analysis/jvm_library_test.bzl660
-rw-r--r--tests/analysis/testinputs/Bar.java21
-rw-r--r--tests/analysis/testinputs/CommonSrcs.kt19
-rw-r--r--tests/analysis/testinputs/Data.java21
-rw-r--r--tests/analysis/testinputs/Deps.java21
-rw-r--r--tests/analysis/testinputs/Foo.java21
-rw-r--r--tests/analysis/testinputs/Resources.java21
-rw-r--r--tests/analysis/testinputs/RuntimeDeps.java21
-rw-r--r--tests/analysis/testinputs/Srcs.kt19
-rw-r--r--tests/analysis/util.bzl125
-rw-r--r--tests/common/testing/unittest_suites/BUILD (renamed from tests/analysis/jvm_library/no_kt_srcs/BUILD)20
-rw-r--r--tests/common/testing/unittest_suites/unittests.bzl97
-rw-r--r--tests/jvm/analysis/compiler_plugin/forbidden_target/BUILD (renamed from tests/analysis/compiler_plugin/provider_ctor/BUILD)10
-rw-r--r--tests/jvm/analysis/compiler_plugin/provider_ctor/BUILD (renamed from tests/analysis/internal_do_not_use/util/file_factory/sub/BUILD)14
-rw-r--r--tests/jvm/analysis/compiler_plugin/provider_ctor/unittests.bzl (renamed from tests/analysis/compiler_plugin/provider_ctor/fake_compiler_plugin.bzl)36
-rw-r--r--tests/jvm/analysis/jvm_compile/no_srcs/BUILD63
-rw-r--r--tests/jvm/analysis/jvm_compile/r_java/BUILD61
-rw-r--r--tests/jvm/analysis/jvm_compile/r_java/Input.java (renamed from tests/analysis/jvm_library/deps/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_compile/r_java/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_compile/src_artifacts/BUILD61
-rw-r--r--tests/jvm/analysis/jvm_import/jars/BUILD45
-rw-r--r--tests/jvm/analysis/jvm_import/runtime_deps/BUILD42
-rw-r--r--tests/jvm/analysis/jvm_import/srcjar/BUILD (renamed from tests/analysis/jvm_library/no_java_srcs/BUILD)19
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/BUILD66
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/CommonSrc.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/Data.java (renamed from tests/analysis/jvm_library/data/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/Dep.java (renamed from tests/analysis/jvm_library/deps/Foo.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/Resource.java (renamed from tests/analysis/jvm_library/deps/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/RuntimeDep.java (renamed from tests/analysis/jvm_library/no_java_srcs/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/coverage/Src.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/data/BUILD (renamed from tests/analysis/jvm_library/data/BUILD)9
-rw-r--r--tests/jvm/analysis/jvm_library/data/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/data/data.txt (renamed from tests/analysis/BUILD)27
-rw-r--r--tests/jvm/analysis/jvm_library/deps/BUILD (renamed from tests/analysis/jvm_library/deps/BUILD)46
-rw-r--r--tests/jvm/analysis/jvm_library/deps/Input.java (renamed from tests/analysis/jvm_library/no_kt_srcs/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/deps/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/exports/BUILD66
-rw-r--r--tests/jvm/analysis/jvm_library/exports/Input.java (renamed from tests/analysis/jvm_library/nodeps/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/exports/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/forbidden_deps/BUILD54
-rw-r--r--tests/jvm/analysis/jvm_library/forbidden_deps/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/friends/BUILD (renamed from tests/analysis/jvm_library/friends/BUILD)48
-rw-r--r--tests/jvm/analysis/jvm_library/friends/Input.java (renamed from tests/analysis/jvm_library/friends/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/friends/Input.kt (renamed from tests/analysis/jvm_library/friends/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/friends/sub/BUILD (renamed from tests/analysis/jvm_library/friends/sub/BUILD)27
-rw-r--r--tests/jvm/analysis/jvm_library/friends/sub/Input.kt (renamed from tests/analysis/jvm_library/friends/sub/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/friends/testing/BUILD (renamed from tests/analysis/jvm_library/friends/testing/BUILD)42
-rw-r--r--tests/jvm/analysis/jvm_library/friends/testing/Input.kt (renamed from tests/analysis/jvm_library/friends/testing/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/no_srcs/BUILD69
-rw-r--r--tests/jvm/analysis/jvm_library/no_srcs/Input.java (renamed from tests/analysis/jvm_library/runtime_deps/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/no_srcs/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/only_common_srcs/BUILD (renamed from tests/analysis/jvm_library/only_common_srcs/BUILD)9
-rw-r--r--tests/jvm/analysis/jvm_library/only_common_srcs/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/plugins/BUILD153
-rw-r--r--tests/jvm/analysis/jvm_library/plugins/Input.java (renamed from tests/analysis/jvm_library/treeartifacts_srcs/Input.java)0
-rw-r--r--tests/jvm/analysis/jvm_library/plugins/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/resources/BUILD (renamed from tests/analysis/jvm_library/nodeps/BUILD)19
-rw-r--r--tests/jvm/analysis/jvm_library/resources/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/resources/resource.txt (renamed from tests/analysis/jvm_library/data/data.txt)3
-rw-r--r--tests/jvm/analysis/jvm_library/runtime_deps/BUILD (renamed from tests/analysis/jvm_library/runtime_deps/BUILD)11
-rw-r--r--tests/jvm/analysis/jvm_library/runtime_deps/Input.java (renamed from tests/analysis/jvm_library/nodeps/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/runtime_deps/Input.kt17
-rw-r--r--tests/jvm/analysis/jvm_library/treeartifacts_srcs/BUILD (renamed from tests/analysis/jvm_library/treeartifacts_srcs/BUILD)44
-rw-r--r--tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.java (renamed from tests/analysis/jvm_library/only_common_srcs/Input.kt)0
-rw-r--r--tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.kt17
-rw-r--r--tests/jvm/analysis/util/file_factory/BUILD (renamed from tests/analysis/compiler_plugin/forbidden_target/BUILD)12
-rw-r--r--tests/jvm/analysis/util/file_factory/unittests.bzl85
-rw-r--r--tests/jvm/java/neverlink/BUILD8
-rw-r--r--tests/jvm/java/srcartifacts/BUILD17
83 files changed, 1301 insertions, 2227 deletions
diff --git a/tests/analysis/assert_failure_test.bzl b/tests/analysis/assert_failure_test.bzl
deleted file mode 100644
index 2a742c3..0000000
--- a/tests/analysis/assert_failure_test.bzl
+++ /dev/null
@@ -1,31 +0,0 @@
-# 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.
-
-"""An assertion for analysis failure."""
-
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _assert_failure_test_impl(ctx):
- env = analysistest.begin(ctx)
- asserts.expect_failure(env, ctx.attr.msg_contains)
- return analysistest.end(env)
-
-assert_failure_test = analysistest.make(
- _assert_failure_test_impl,
- expect_failure = True,
- attrs = dict(
- msg_contains = attr.string(mandatory = True),
- ),
-)
diff --git a/tests/analysis/compiler_plugin/BUILD b/tests/analysis/compiler_plugin/BUILD
deleted file mode 100644
index 0c1f9b6..0000000
--- a/tests/analysis/compiler_plugin/BUILD
+++ /dev/null
@@ -1,23 +0,0 @@
-# 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.
-
-licenses(["notice"])
-
-genrule(
- name = "empty_jar",
- outs = ["empty.jar"],
- cmd = """$(location @bazel_tools//tools/zip:zipper) c $@ "assets/_empty=" """,
- tools = ["@bazel_tools//tools/zip:zipper"],
- visibility = ["//tests/analysis/compiler_plugin:__subpackages__"],
-)
diff --git a/tests/analysis/compiler_plugin/propagation/BUILD b/tests/analysis/compiler_plugin/propagation/BUILD
deleted file mode 100644
index 0c6fe19..0000000
--- a/tests/analysis/compiler_plugin/propagation/BUILD
+++ /dev/null
@@ -1,79 +0,0 @@
-# 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:compiler_plugin.bzl", "kt_compiler_plugin")
-load(":assert_propagation_test.bzl", "assert_propagation_test")
-
-licenses(["notice"])
-
-assert_propagation_test(
- name = "f",
- expected_plugin_ids = ["1"],
- deps = [":e"],
-)
-
-assert_propagation_test(
- name = "e",
- expected_plugin_ids = [],
- exports = [":a"],
-)
-
-assert_propagation_test(
- name = "d",
- expected_plugin_ids = [
- "1",
- "2",
- ],
- deps = [
- ":a",
- ":b",
- ],
-)
-
-assert_propagation_test(
- name = "c",
- expected_plugin_ids = ["2"],
- deps = [":b"],
-)
-
-assert_propagation_test(
- name = "b",
- expected_plugin_ids = ["1"],
- exported_plugins = [":2"],
- deps = [":a"],
-)
-
-assert_propagation_test(
- name = "a",
- expected_plugin_ids = [],
- exported_plugins = [":1"],
-)
-
-kt_compiler_plugin(
- name = "1",
- jar = "//tests/analysis/compiler_plugin:empty_jar",
- plugin_id = "1",
-)
-
-kt_compiler_plugin(
- name = "2",
- jar = "//tests/analysis/compiler_plugin:empty_jar",
- plugin_id = "2",
-)
-
-kt_compiler_plugin(
- name = "3",
- jar = "//tests/analysis/compiler_plugin:empty_jar",
- plugin_id = "3",
-)
diff --git a/tests/analysis/compiler_plugin/propagation/assert_propagation_test.bzl b/tests/analysis/compiler_plugin/propagation/assert_propagation_test.bzl
deleted file mode 100644
index 0c1b02a..0000000
--- a/tests/analysis/compiler_plugin/propagation/assert_propagation_test.bzl
+++ /dev/null
@@ -1,57 +0,0 @@
-# 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.
-
-"""Rule for asserting plugin propagation."""
-
-load("@bazel_skylib//lib:sets.bzl", "sets")
-load("@bazel_skylib//rules:build_test.bzl", "build_test")
-load("//kotlin:traverse_exports.bzl", "kt_traverse_exports")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _assert_propagation_impl(ctx):
- expected_ids = sets.make(ctx.attr.expected_plugin_ids)
- actual_ids = sets.make([
- p.plugin_id
- for p in kt_traverse_exports.expand_compiler_plugins(ctx.attr.deps).to_list()
- ])
-
- if not sets.is_equal(expected_ids, actual_ids):
- fail("Expected IDs %s, actual IDs %s" % (sets.to_list(expected_ids), sets.to_list(actual_ids)))
-
- return [
- # Needed for kt_traverse_exports.aspect
- JavaInfo(
- compile_jar = ctx.file._empty_jar,
- output_jar = ctx.file._empty_jar,
- ),
- ]
-
-_assert_propagation = rule(
- implementation = _assert_propagation_impl,
- attrs = dict(
- exports = attr.label_list(),
- exported_plugins = attr.label_list(),
- expected_plugin_ids = attr.string_list(),
- deps = attr.label_list(aspects = [kt_traverse_exports.aspect]),
- _empty_jar = attr.label(
- allow_single_file = True,
- default = "//tests/analysis/compiler_plugin:empty_jar",
- ),
- ),
-)
-
-def assert_propagation_test(name, **kwargs):
- _assert_propagation(name = name, **kwargs)
-
- build_test(name = name + "_build", targets = [name])
diff --git a/tests/analysis/compiler_plugin/provider_output/BUILD b/tests/analysis/compiler_plugin/provider_output/BUILD
deleted file mode 100644
index 4769965..0000000
--- a/tests/analysis/compiler_plugin/provider_output/BUILD
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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:compiler_plugin.bzl", "kt_compiler_plugin")
-load("//tests/analysis:util.bzl", "create_file")
-load("@bazel_skylib//rules:build_test.bzl", "build_test")
-load(":assert_compiler_plugin_test.bzl", "assert_compiler_plugin_test")
-
-licenses(["notice"])
-
-assert_compiler_plugin_test(
- name = "example_plugin_test",
- expected_args = [
- "plugin:com.google.example:key=value",
- ],
- expected_id = "com.google.example",
- expected_jar = "//tests/analysis/compiler_plugin:empty_jar",
- target_under_test = ":example_plugin",
-)
-
-build_test(
- name = "example_plugin_in_java_library_build_test",
- targets = [
- ":example_plugin_in_java_library",
- ],
-)
-
-java_library(
- name = "example_plugin_in_java_library",
- srcs = [create_file(
- name = "Tmp.java",
- content = """
- @SuppressWarnings("DefaultPackage")
- class Tmp { }
- """,
- )],
- plugins = [":example_plugin"],
-)
-
-kt_compiler_plugin(
- name = "example_plugin",
- args = {
- "key": "value",
- },
- jar = "//tests/analysis/compiler_plugin:empty_jar",
- plugin_id = "com.google.example",
-)
diff --git a/tests/analysis/compiler_plugin/provider_output/assert_compiler_plugin_test.bzl b/tests/analysis/compiler_plugin/provider_output/assert_compiler_plugin_test.bzl
deleted file mode 100644
index f4e1849..0000000
--- a/tests/analysis/compiler_plugin/provider_output/assert_compiler_plugin_test.bzl
+++ /dev/null
@@ -1,38 +0,0 @@
-# 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.
-
-"""An assertion on kt_compiler_plugin analysis."""
-
-load("//kotlin:compiler_plugin.bzl", "KtCompilerPluginInfo")
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _test_impl(ctx):
- env = analysistest.begin(ctx)
- info = ctx.attr.target_under_test[KtCompilerPluginInfo]
-
- asserts.equals(env, info.plugin_id, ctx.attr.expected_id)
- asserts.equals(env, info.jar, ctx.file.expected_jar)
- asserts.equals(env, info.args, ctx.attr.expected_args)
-
- return analysistest.end(env)
-
-assert_compiler_plugin_test = analysistest.make(
- impl = _test_impl,
- attrs = dict(
- expected_id = attr.string(),
- expected_jar = attr.label(allow_single_file = True, cfg = "exec"),
- expected_args = attr.string_list(),
- ),
-)
diff --git a/tests/analysis/for_test.bzl b/tests/analysis/for_test.bzl
deleted file mode 100644
index 2a75726..0000000
--- a/tests/analysis/for_test.bzl
+++ /dev/null
@@ -1,40 +0,0 @@
-# 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.
-
-"""Rules for test."""
-
-load("//kotlin:jvm_library.bzl", "kt_jvm_library")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _kt_jvm_library_for_test(name, **kwargs):
- kt_jvm_library(
- name = name,
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- **kwargs
- )
- return name
-
-def _java_library_for_test(name, **kwargs):
- native.java_library(
- name = name,
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- **kwargs
- )
- return name
-
-rules_for_test = struct(
- kt_jvm_library = _kt_jvm_library_for_test,
- java_library = _java_library_for_test,
-)
diff --git a/tests/analysis/internal_do_not_use/util/file_factory/BUILD b/tests/analysis/internal_do_not_use/util/file_factory/BUILD
deleted file mode 100644
index d92e379..0000000
--- a/tests/analysis/internal_do_not_use/util/file_factory/BUILD
+++ /dev/null
@@ -1,41 +0,0 @@
-# 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(":happy_test.bzl", "file_factory_happy_test")
-load(":check_base_file_valid.bzl", "check_base_file_valid")
-load("//tests/analysis:assert_failure_test.bzl", "assert_failure_test")
-
-licenses(["notice"])
-
-file_factory_happy_test(
- name = "happy_test",
-)
-
-assert_failure_test(
- name = "base_without_extension_test",
- msg_contains = "file must have an extension",
- target_under_test = check_base_file_valid(
- name = "base_without_extension",
- base_file = "BUILD",
- ),
-)
-
-assert_failure_test(
- name = "base_from_other_package_test",
- msg_contains = "file must be from ctx package",
- target_under_test = check_base_file_valid(
- name = "base_from_other_package",
- base_file = "//tests/analysis/internal_do_not_use/util/file_factory/sub",
- ),
-)
diff --git a/tests/analysis/internal_do_not_use/util/file_factory/check_base_file_valid.bzl b/tests/analysis/internal_do_not_use/util/file_factory/check_base_file_valid.bzl
deleted file mode 100644
index 9ca1f05..0000000
--- a/tests/analysis/internal_do_not_use/util/file_factory/check_base_file_valid.bzl
+++ /dev/null
@@ -1,38 +0,0 @@
-# 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.
-
-"""Happy tests for FileFactory."""
-
-load("//kotlin/jvm/internal_do_not_use/util:file_factory.bzl", "FileFactory")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _check_base_file_valid_impl(ctx):
- FileFactory(ctx, ctx.file.base_file)
- return []
-
-_check_base_file_valid = rule(
- implementation = _check_base_file_valid_impl,
- attrs = dict(
- base_file = attr.label(allow_single_file = True, mandatory = True),
- ),
-)
-
-def check_base_file_valid(name, tags = [], **kwargs):
- _check_base_file_valid(
- name = name,
- tags = tags + ONLY_FOR_ANALYSIS_TEST_TAGS,
- **kwargs
- )
- return name
diff --git a/tests/analysis/internal_do_not_use/util/file_factory/happy_test.bzl b/tests/analysis/internal_do_not_use/util/file_factory/happy_test.bzl
deleted file mode 100644
index 1a2a655..0000000
--- a/tests/analysis/internal_do_not_use/util/file_factory/happy_test.bzl
+++ /dev/null
@@ -1,78 +0,0 @@
-# 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.
-
-"""file_factory_happy_test"""
-
-load("//kotlin/jvm/internal_do_not_use/util:file_factory.bzl", "FileFactory")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _test_base_from_file(ctx, pkg_path):
- base_file = ctx.actions.declare_file("file/base.txt")
- factory = FileFactory(ctx, base_file)
-
- _assert_equals(pkg_path + "/file/base", factory.base_as_path)
-
- return [base_file]
-
-def _test_declare(ctx, pkg_path):
- factory = FileFactory(ctx, "string/base")
-
- _assert_equals(pkg_path + "/string/base", factory.base_as_path)
-
- a_file = factory.declare_file("a.txt")
- _assert_equals(pkg_path + "/string/basea.txt", a_file.path)
-
- b_dir = factory.declare_directory("b_dir")
- _assert_equals(pkg_path + "/string/baseb_dir", b_dir.path)
-
- return [a_file, b_dir]
-
-def _test_derive(ctx, pkg_path):
- factory = FileFactory(ctx, "")
-
- # Once
- factory_once = factory.derive("once")
- _assert_equals(pkg_path + "/once", factory_once.base_as_path)
-
- # Twice
- factory_twice = factory_once.derive("/twice")
- _assert_equals(pkg_path + "/once/twice", factory_twice.base_as_path)
-
-def _assert_equals(expected, actual):
- if expected != actual:
- fail("Expected '%s' but was '%s'" % (expected, actual))
-
-def _file_factory_happy_test_impl(ctx):
- pkg_path = ctx.bin_dir.path + "/" + ctx.label.package
- all_files = []
-
- all_files.extend(_test_base_from_file(ctx, pkg_path))
- all_files.extend(_test_declare(ctx, pkg_path))
- _test_derive(ctx, pkg_path)
-
- ctx.actions.run_shell(
- outputs = all_files,
- command = "exit 1",
- )
-
- test_script = ctx.actions.declare_file(ctx.label.name + "_test.sh")
- ctx.actions.write(test_script, "#!/bin/bash", True)
- return [
- DefaultInfo(executable = test_script),
- ]
-
-file_factory_happy_test = rule(
- implementation = _file_factory_happy_test_impl,
- test = True,
-)
diff --git a/tests/analysis/jvm_compile_test.bzl b/tests/analysis/jvm_compile_test.bzl
deleted file mode 100644
index 83e722c..0000000
--- a/tests/analysis/jvm_compile_test.bzl
+++ /dev/null
@@ -1,391 +0,0 @@
-# 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.
-
-"""Kotlin kt_jvm_compile API test."""
-
-load("//kotlin:traverse_exports.bzl", "kt_traverse_exports")
-load("//kotlin:jvm_compile.bzl", "kt_jvm_compile")
-load("//kotlin:common.bzl", "common")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS", "create_dir", "create_file")
-load("//toolchains/kotlin_jvm:java_toolchains.bzl", "java_toolchains")
-load("//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "kt_jvm_toolchains")
-load("@bazel_skylib//rules:build_test.bzl", "build_test")
-load(":assert_failure_test.bzl", "assert_failure_test")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _impl(ctx):
- # As additional capabilites need to be tested, this rule should support
- # additional fields/attributes.
- result = kt_jvm_compile(
- ctx,
- output = ctx.outputs.jar,
- srcs = ctx.files.srcs,
- common_srcs = ctx.files.common_srcs,
- deps = ctx.attr.deps,
- plugins = [],
- exported_plugins = [],
- runtime_deps = [],
- exports = ctx.attr.exports,
- javacopts = [],
- kotlincopts = [],
- neverlink = False,
- testonly = False,
- android_lint_plugins = [],
- manifest = None,
- merged_manifest = None,
- resource_files = [],
- rule_family = ctx.attr.rule_family,
- kt_toolchain = kt_jvm_toolchains.get(ctx),
- java_toolchain = java_toolchains.get(ctx),
- disable_lint_checks = [],
- r_java = ctx.attr.r_java[JavaInfo] if ctx.attr.r_java else None,
- )
- return [result.java_info]
-
-_kt_jvm_compile = rule(
- implementation = _impl,
- attrs = dict(
- srcs = attr.label_list(
- allow_files = True,
- ),
- common_srcs = attr.label_list(
- allow_files = True,
- ),
- deps = attr.label_list(
- aspects = [kt_traverse_exports.aspect],
- providers = [JavaInfo],
- ),
- exports = attr.label_list(
- aspects = [kt_traverse_exports.aspect],
- providers = [JavaInfo],
- ),
- rule_family = attr.int(
- default = common.RULE_FAMILY.UNKNOWN,
- ),
- r_java = attr.label(
- providers = [JavaInfo],
- ),
- _java_toolchain = attr.label(
- default = Label(
- "@bazel_tools//tools/jdk:current_java_toolchain",
- ),
- ),
- ),
- fragments = ["java"],
- outputs = dict(
- jar = "lib%{name}.jar",
- ),
- toolchains = [kt_jvm_toolchains.type, "@bazel_tools//tools/jdk:toolchain_type"],
-)
-
-def _test_kt_jvm_compile_using_kt_jvm_compile_with_r_java():
- test_name = "kt_jvm_compile_using_kt_jvm_compile_with_r_java_test"
-
- native.java_library(
- name = "foo_resources",
- srcs = [create_file(
- name = test_name + "/java/com/foo/R.java",
- content = """
-package com.foo;
-
-public final class R {
- public static final class string {
- public static int a_string=0x00000001;
- public static int b_string=0x00000002;
- }
-}
-""",
- )],
- )
-
- _kt_jvm_compile(
- name = "kt_jvm_compile_with_r_java",
- srcs = [create_file(
- name = test_name + "/AString.kt",
- content = """
-package test
-
-import com.foo.R.string.a_string
-
-fun aString(): String = "a_string=" + a_string
-""",
- )],
- r_java = ":foo_resources",
- )
-
- _kt_jvm_compile(
- name = "kt_jvm_compile_using_kt_jvm_compile_with_r_java",
- srcs = [create_file(
- name = test_name + "/ABString.kt",
- content = """
-package test
-
-import com.foo.R.string.b_string
-
-fun bString(): String = "b_string=" + b_string
-
-fun abString(): String = aString() + bString()
-""",
- )],
- deps = [":kt_jvm_compile_with_r_java"],
- )
-
- # If a failure occurs, it will be at build time.
- build_test(
- name = test_name,
- targets = [":kt_jvm_compile_using_kt_jvm_compile_with_r_java"],
- )
- return test_name
-
-def _test_kt_jvm_compile_with_illegal_r_java():
- test_name = "kt_jvm_compile_with_illegal_r_java_test"
-
- native.java_library(
- name = "foo",
- srcs = [create_file(
- name = test_name + "/java/com/foo/Foo.java",
- content = """
-package com.foo;
-
-public class Foo {}
-""",
- )],
- )
- _kt_jvm_compile(
- name = "kt_jvm_compile_with_illegal_r_java",
- srcs = [create_file(
- name = test_name + "/AString.kt",
- content = """
-package test
-
-import com.foo.Foo
-
-fun bar(): String = "Bar"
-""",
- )],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- r_java = ":foo",
- )
- assert_failure_test(
- name = test_name,
- target_under_test = ":kt_jvm_compile_with_illegal_r_java",
- msg_contains = "illegal dependency provided for r_java",
- )
- return test_name
-
-def _test_kt_jvm_compile_with_r_java_as_first_dep():
- test_name = "kt_jvm_compile_with_r_java_as_first_dep_test"
-
- # Note: The R from an android_library must be the first dependency in
- # the classpath to prevent another libraries R from being used for
- # compilation. If the ordering is incorrect, compiletime failures will
- # occur as the depot relies on this ordering.
-
- native.java_library(
- name = "foo_with_symbol_resources",
- srcs = [create_file(
- name = test_name + "/with_symbol/java/com/foo/R.java",
- content = """
-package com.foo;
-
-public final class R {
- public static final class string {
- public static int a_string=0x00000001;
- }
-}
-""",
- )],
- )
-
- native.java_library(
- name = "foo_without_symbol_resources",
- srcs = [create_file(
- name = test_name + "/without_symbol/java/com/foo/R.java",
- content = """
-package com.foo;
-
-public final class R {
- public static final class string {
- }
-}
-""",
- )],
- )
-
- _kt_jvm_compile(
- name = "kt_jvm_compile_with_r_java_as_first_dep",
- srcs = [create_file(
- name = test_name + "/AString.kt",
- content = """
-package test
-
-import com.foo.R.string.a_string
-
-fun aString(): String = "a_string=" + a_string
-""",
- )],
- r_java = ":foo_with_symbol_resources",
- deps = [":foo_without_symbol_resources"],
- )
-
- # If a failure occurs, it will be at build time.
- build_test(
- name = test_name,
- targets = [":kt_jvm_compile_with_r_java_as_first_dep"],
- )
- return test_name
-
-def _test_kt_jvm_compile_without_srcs_for_android():
- test_name = "kt_jvm_compile_without_srcs_for_android_test"
-
- # This is a common case for rules like android_library where Kotlin sources
- # could be empty, due to the rule being used for resource processing. For
- # this scenario, historically, rules continue to produce empty Jars.
- _kt_jvm_compile(
- name = "kt_jvm_compile_without_srcs_for_android",
- rule_family = common.RULE_FAMILY.ANDROID_LIBRARY,
- )
-
- # If a failure occurs, it will be at build time.
- build_test(
- name = test_name,
- targets = [":kt_jvm_compile_without_srcs_for_android"],
- )
- return test_name
-
-def _test_kt_jvm_compile_without_srcs_for_jvm():
- test_name = "kt_jvm_compile_without_srcs_for_jvm_test"
-
- _kt_jvm_compile(
- name = "kt_jvm_compile_without_srcs_for_jvm",
- srcs = [],
- common_srcs = [],
- exports = [],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
- assert_failure_test(
- name = test_name,
- target_under_test = ":kt_jvm_compile_without_srcs_for_jvm",
- msg_contains = "Expected one of (srcs, common_srcs, exports) is not empty",
- )
- return test_name
-
-def _test_kt_jvm_compile_without_srcs_and_with_exports():
- test_name = "kt_jvm_compile_without_srcs_and_with_exports_test"
-
- _kt_jvm_compile(
- name = "bar_lib",
- srcs = [create_file(
- name = test_name + "/Bar.kt",
- content = """
-package test
-
-fun bar(): String = "Bar"
-""",
- )],
- )
-
- _kt_jvm_compile(
- name = "kt_jvm_compile_without_srcs_and_with_exports",
- exports = [":bar_lib"],
- )
-
- _kt_jvm_compile(
- name = "foo_bar_lib",
- srcs = [create_file(
- name = test_name + "/FooBar.kt",
- content = """
-package test
-
-fun fooBar(): String = "Foo" + bar()
-""",
- )],
- deps = [":kt_jvm_compile_without_srcs_and_with_exports"],
- )
-
- # If a failure occurs, it will be at build time.
- build_test(
- name = test_name,
- targets = [":foo_bar_lib"],
- )
- return test_name
-
-def _test_kt_jvm_compile_unsupported_src_artifacts():
- test_name = "kt_jvm_compile_unsupported_src_artifacts_test"
-
- kt_src = create_file(
- name = test_name + "/src.kt",
- content = "",
- )
- kt_dir = create_dir(
- name = test_name + "/kotlin",
- subdir = "",
- srcs = [create_file(
- name = test_name + "/dir.kt",
- content = "",
- )],
- )
- java_src = create_file(
- name = test_name + "/src.java",
- content = "",
- )
- 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, java_dir, java_srcjar],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
-
- unexpected_file = create_file(
- name = test_name + "/src.unexpected",
- content = "",
- )
- _kt_jvm_compile(
- name = test_name + "_unexpected_lib",
- srcs = [unexpected_file],
- deps = [test_name + "_expected_lib"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
-
- assert_failure_test(
- name = test_name,
- target_under_test = test_name + "_unexpected_lib",
- msg_contains = "/src.unexpected",
- )
- return test_name
-
-def test_suite(name = None):
- native.test_suite(
- name = name,
- tests = [
- _test_kt_jvm_compile_unsupported_src_artifacts(),
- _test_kt_jvm_compile_using_kt_jvm_compile_with_r_java(),
- _test_kt_jvm_compile_with_illegal_r_java(),
- _test_kt_jvm_compile_with_r_java_as_first_dep(),
- _test_kt_jvm_compile_without_srcs_for_android(),
- _test_kt_jvm_compile_without_srcs_for_jvm(),
- _test_kt_jvm_compile_without_srcs_and_with_exports(),
- ],
- )
diff --git a/tests/analysis/jvm_import_test.bzl b/tests/analysis/jvm_import_test.bzl
deleted file mode 100644
index 6e56c02..0000000
--- a/tests/analysis/jvm_import_test.bzl
+++ /dev/null
@@ -1,169 +0,0 @@
-# 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.
-
-"""Kotlin kt_jvm_import rule tests."""
-
-load("//kotlin:jvm_import.bzl", "kt_jvm_import")
-load("//kotlin:jvm_library.bzl", "kt_jvm_library")
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS", "create_file")
-load(":assert_failure_test.bzl", "assert_failure_test")
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-def _impl(ctx):
- env = analysistest.begin(ctx)
- asserts.true(
- env,
- JavaInfo in ctx.attr.target_under_test,
- "kt_jvm_import did not produce JavaInfo provider.",
- )
- asserts.true(
- env,
- ProguardSpecProvider in ctx.attr.target_under_test,
- "kt_jvm_import did not produce ProguardSpecProvider provider.",
- )
- return analysistest.end(env)
-
-_test = analysistest.make(_impl)
-
-def _test_kt_jvm_import():
- test_name = "kt_jvm_import_test"
- native.java_library(
- name = "jar1",
- srcs = [],
- )
- kt_jvm_import(
- name = test_name + "_tut",
- jars = [
- "libjar1.jar",
- ],
- srcjar = "libjar1-src.jar",
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_import_no_srcjar():
- test_name = "kt_jvm_import_no_srcjar_test"
- native.java_library(
- name = "jar3",
- srcs = [],
- )
- kt_jvm_import(
- name = test_name + "_tut",
- jars = [
- "libjar3.jar",
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_import_with_srcjar_ext():
- test_name = "kt_jvm_import_test_with_srcjar_ext"
- native.java_library(
- name = "jar2",
- srcs = [],
- )
- native.genrule(
- name = "gen_jar2_srcjar",
- cmd = "touch $@",
- outs = ["libjar2.srcjar"],
- )
- kt_jvm_import(
- name = test_name + "_tut",
- jars = [
- "libjar2.jar",
- ],
- srcjar = ":libjar2.srcjar",
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_import_with_runtime_deps():
- test_name = "kt_jvm_import_with_runtime_deps"
- native.java_library(
- name = test_name + "_dep",
- srcs = [],
- )
- kt_jvm_import(
- name = test_name + "_tut",
- jars = [
- "lib%s_dep.jar" % test_name,
- ],
- runtime_deps = [
- test_name + "_dep",
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_import_with_proguard_specs():
- test_name = "kt_jvm_import_with_proguard_specs"
- native.java_library(
- name = test_name + "_jar",
- srcs = [],
- )
-
- kt_jvm_import(
- name = test_name + "_tut",
- jars = [
- "lib%s_jar.jar" % test_name,
- ],
- proguard_specs = [
- create_file(
- name = test_name + "/salutations.pgcfg",
- content = """
--keep class * {
- *** greeting();
-}
-""",
- ),
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _mock_jar(test_name, i):
- """Creates a Jar named after the given inputs and returns its name."""
- native.java_library(
- name = "%s_mock%s" % (test_name, i),
- srcs = [],
- )
- return "lib%s_mock%s.jar" % (test_name, i)
-
-def test_suite(name = None):
- native.test_suite(
- name = name,
- tests = [
- _test_kt_jvm_import(),
- _test_kt_jvm_import_with_srcjar_ext(),
- _test_kt_jvm_import_no_srcjar(),
- _test_kt_jvm_import_with_runtime_deps(),
- _test_kt_jvm_import_with_proguard_specs(),
- ],
- )
diff --git a/tests/analysis/jvm_library/runtime_deps/Input.kt b/tests/analysis/jvm_library/runtime_deps/Input.kt
deleted file mode 100644
index e675bc1..0000000
--- a/tests/analysis/jvm_library/runtime_deps/Input.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * * 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.
- */
-
diff --git a/tests/analysis/jvm_library/treeartifacts_srcs/Input.kt b/tests/analysis/jvm_library/treeartifacts_srcs/Input.kt
deleted file mode 100644
index e675bc1..0000000
--- a/tests/analysis/jvm_library/treeartifacts_srcs/Input.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * * 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.
- */
-
diff --git a/tests/analysis/jvm_library_test.bzl b/tests/analysis/jvm_library_test.bzl
deleted file mode 100644
index 1627c5f..0000000
--- a/tests/analysis/jvm_library_test.bzl
+++ /dev/null
@@ -1,660 +0,0 @@
-# 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.
-
-"""Kotlin kt_jvm_library rule tests."""
-
-load("//:visibility.bzl", "RULES_KOTLIN")
-load("//kotlin:jvm_library.bzl", "kt_jvm_library")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS", "create_file", "get_action", "get_arg")
-load("@bazel_skylib//lib:sets.bzl", "sets")
-load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
-load(":assert_failure_test.bzl", "assert_failure_test")
-
-_DEFAULT_LIST = ["__default__"]
-
-def _test_impl(ctx):
- env = analysistest.begin(ctx)
- actual = ctx.attr.target_under_test
-
- actions = analysistest.target_actions(env)
- kt_al_action = get_action(actions, "KtAndroidLint")
-
- asserts.true(
- env,
- JavaInfo in actual,
- "kt_jvm_library did not produce JavaInfo provider.",
- )
- asserts.true(
- env,
- ProguardSpecProvider in actual,
- "Expected a ProguardSpecProvider provider.",
- )
-
- if ctx.attr.expected_runfile_names != _DEFAULT_LIST:
- asserts.set_equals(
- env,
- sets.make(ctx.attr.expected_runfile_names),
- sets.make([
- f.basename
- for f in actual[DefaultInfo].data_runfiles.files.to_list()
- ]),
- )
-
- if ctx.attr.expected_compile_jar_names != _DEFAULT_LIST:
- asserts.set_equals(
- env,
- sets.make(ctx.attr.expected_compile_jar_names),
- sets.make([f.basename for f in actual[JavaInfo].compile_jars.to_list()]),
- "kt_jvm_library JavaInfo::compile_jars",
- )
-
- if ctx.attr.expected_exported_processor_jar_names != _DEFAULT_LIST:
- asserts.set_equals(
- env,
- sets.make(ctx.attr.expected_exported_processor_jar_names),
- sets.make([f.basename for f in actual[JavaInfo].plugins.processor_jars.to_list()]),
- )
-
- asserts.set_equals(
- env,
- sets.make(ctx.attr.expected_exported_processor_classes),
- sets.make(actual[JavaInfo].plugins.processor_classes.to_list()),
- )
-
- kt_2_java_compile = get_action(actions, "Kt2JavaCompile")
-
- if kt_2_java_compile:
- asserts.true(
- env,
- kt_2_java_compile.outputs.to_list()[0].basename.endswith(".jar"),
- "Expected first output to be a JAR (this affects the param file name).",
- )
-
- if ctx.attr.expected_friend_jar_names != _DEFAULT_LIST:
- friend_paths_arg = get_arg(kt_2_java_compile, "-Xfriend-paths=")
- friend_jar_names = [p.rsplit("/", 1)[1] for p in friend_paths_arg.split(",")] if friend_paths_arg else []
- asserts.set_equals(env, sets.make(ctx.attr.expected_friend_jar_names), sets.make(friend_jar_names))
-
- asserts.equals(
- env,
- ctx.attr.expect_neverlink,
- len(actual[JavaInfo].transitive_runtime_jars.to_list()) == 0,
- "Mismatch: Expected transitive_runtime_jars iff (neverlink == False)",
- )
-
- return analysistest.end(env)
-
-_test = analysistest.make(
- impl = _test_impl,
- attrs = dict(
- expected_al_ruleset_names = attr.string_list(
- doc = "Android Lint rule JARs reported as run on the given target",
- default = _DEFAULT_LIST,
- ),
- expected_compile_jar_names = attr.string_list(
- doc = "Names of all JavaInfo::compile_jars for the given target",
- default = _DEFAULT_LIST,
- ),
- expected_exported_processor_jar_names = attr.string_list(
- doc = "Names of all JavaInfo.plugins JARs returned by the given target",
- default = _DEFAULT_LIST,
- ),
- expected_exported_processor_classes = attr.string_list(
- doc = "Annotation processors reported as to be run on depending targets",
- ),
- expected_processor_classes = attr.string_list(
- doc = "Annotation processors reported as run on the given target",
- ),
- expected_friend_jar_names = attr.string_list(
- doc = "Names of all -Xfriend-paths= JARs",
- default = _DEFAULT_LIST,
- ),
- expected_runfile_names = attr.string_list(
- doc = "Names of all runfiles",
- default = _DEFAULT_LIST,
- ),
- expect_processor_classpath = attr.bool(),
- expect_neverlink = attr.bool(),
- ),
-)
-
-jvm_library_test = _test
-
-def _coverage_test_impl(ctx):
- env = analysistest.begin(ctx)
- target_under_test = analysistest.target_under_test(env)
- instrumented_files_info = target_under_test[InstrumentedFilesInfo]
- instrumented_files = instrumented_files_info.instrumented_files.to_list()
- asserts.equals(
- env,
- ctx.attr.expected_instrumented_file_basenames,
- [file.basename for file in instrumented_files],
- )
- return analysistest.end(env)
-
-_coverage_test = analysistest.make(
- impl = _coverage_test_impl,
- attrs = {
- "expected_instrumented_file_basenames": attr.string_list(),
- },
- config_settings = {
- "//command_line_option:collect_code_coverage": "1",
- "//command_line_option:instrument_test_targets": "1",
- "//command_line_option:instrumentation_filter": "+tests/analysis[:/]",
- },
-)
-
-def _test_kt_jvm_library_with_proguard_specs():
- test_name = "kt_jvm_library_with_proguard_specs_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- create_file(
- name = test_name + "/salutations.pgcfg",
- content = """
--keep class * {
- *** greeting();
-}
-""",
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- proguard_specs = [
- test_name + "/salutations.pgcfg",
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_library_with_resources():
- test_name = "kt_jvm_library_with_resources_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- create_file(
- name = test_name + "/salutations.txt",
- content = """
-Hi!
-""",
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- "testinputs/Foo.java",
- ],
- resources = [
- test_name + "/salutations.txt",
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- )
- return test_name
-
-def _test_kt_jvm_library_with_plugin():
- test_name = "kt_jvm_library_with_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
-
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- # Need a working plugin so it can run for the test.
- plugins = ["//bazel:auto_value_plugin"],
- )
-
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_processor_classes = ["com.google.auto.value.processor.AutoValueProcessor"],
- expect_processor_classpath = True,
- )
- return test_name
-
-def _test_kt_jvm_library_no_kt_srcs_with_plugin():
- test_name = "kt_jvm_library_no_kt_srcs_with_plugin_test"
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- srcs = ["testinputs/Foo.java"], # induce processor_classpath
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = ["testinputs/Bar.java"],
- plugins = [":%s_plugin" % test_name],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_processor_classes = [test_name],
- expect_processor_classpath = True,
- )
- return test_name
-
-def _test_kt_jvm_library_with_non_processor_plugin():
- test_name = "kt_jvm_library_with_non_processor_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
-
- native.java_plugin(
- # no processor_class
- name = "%s_plugin" % test_name,
- srcs = ["testinputs/Foo.java"],
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- plugins = [":%s_plugin" % test_name],
- )
-
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_processor_classes = [], # no processor class so no processing
- expect_processor_classpath = True, # expect java_plugin's Jar
- )
- return test_name
-
-def _test_kt_jvm_library_with_exported_plugin():
- test_name = "kt_jvm_library_with_exported_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- exported_plugins = [":%s_plugin" % test_name],
- )
-
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_exported_processor_classes = [test_name],
- expected_processor_classes = [], # exported plugin should *not* run on _tut itself
- )
- return test_name
-
-def _test_kt_jvm_library_dep_on_exported_plugin():
- test_name = "kt_jvm_library_dep_on_exported_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
-
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- srcs = ["testinputs/Foo.java"], # induce processor_classpath
- )
- kt_jvm_library(
- name = "%s_exports_plugin" % test_name,
- srcs = [test_name + "/Salutations.kt"],
- exported_plugins = [":%s_plugin" % test_name],
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- deps = [":%s_exports_plugin" % test_name],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
-
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_processor_classes = [test_name],
- expect_processor_classpath = True,
- )
- return test_name
-
-def _test_kt_jvm_library_java_dep_on_exported_plugin():
- test_name = "kt_jvm_library_java_dep_on_exported_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- srcs = ["testinputs/Foo.java"], # induce processor_classpath
- )
- native.java_library(
- name = "%s_exports_plugin" % test_name,
- exported_plugins = [":%s_plugin" % test_name],
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- deps = [":%s_exports_plugin" % test_name],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- )
-
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_processor_classes = [test_name],
- expect_processor_classpath = True,
- )
- return test_name
-
-def _test_kt_jvm_library_with_exports():
- test_name = "kt_jvm_library_with_exports_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- kt_jvm_library(
- name = test_name + "_exp",
- srcs = [test_name + "/Salutations.kt"],
- )
- native.java_library(
- name = test_name + "_javaexp",
- srcs = ["testinputs/Foo.java"], # need file here so we get a Jar
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- exports = [
- ":%s_exp" % test_name,
- ":%s_javaexp" % test_name,
- ],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_compile_jar_names = [
- "lib%s_tut-compile.jar" % test_name,
- "lib%s_exp-compile.jar" % test_name,
- "lib%s_javaexp-hjar.jar" % test_name,
- ],
- )
- return test_name
-
-def _test_kt_jvm_library_with_export_that_exports_plugin():
- test_name = "kt_jvm_library_with_export_that_exports_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- srcs = ["testinputs/Foo.java"], # induce processor_classpath
- )
- kt_jvm_library(
- name = "%s_exports_plugin" % test_name,
- exported_plugins = [":%s_plugin" % test_name],
- srcs = [test_name + "/Salutations.kt"],
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- exports = [":%s_exports_plugin" % test_name],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_compile_jar_names = [
- "lib%s_tut-compile.jar" % test_name,
- "lib%s_exports_plugin-compile.jar" % test_name,
- ],
- expected_exported_processor_classes = [test_name],
- )
- return test_name
-
-def _test_kt_jvm_library_with_java_export_that_exports_plugin():
- test_name = "kt_jvm_library_with_java_export_that_exports_plugin_test"
- create_file(
- name = test_name + "/Salutations.kt",
- content = """
-package test
-
-fun greeting(): String = "Hello World!"
-""",
- )
- native.java_plugin(
- name = "%s_plugin" % test_name,
- processor_class = test_name,
- srcs = ["testinputs/Foo.java"], # induce processor_classpath
- )
- native.java_library(
- name = "%s_exports_plugin" % test_name,
- exported_plugins = [":%s_plugin" % test_name],
- )
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [
- test_name + "/Salutations.kt",
- ],
- exports = [":%s_exports_plugin" % test_name],
- )
- _test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_compile_jar_names = [
- # _exports_plugin has no compile/runtime Jars
- "lib%s_tut-compile.jar" % test_name,
- ],
- expected_exported_processor_classes = [test_name],
- )
- return test_name
-
-def _test_forbidden_nano_dep():
- test_name = "kt_jvm_library_forbidden_nano_test"
-
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [test_name + "/Ignored.kt"],
- deps = [test_name + "_fake_nano_proto_lib"],
- tags = [
- "manual",
- "nobuilder",
- ],
- )
- native.java_library(
- name = test_name + "_fake_nano_proto_lib",
- srcs = [],
- tags = ["nano_proto_library"],
- )
- assert_failure_test(
- name = test_name,
- target_under_test = test_name + "_tut",
- msg_contains = test_name + "_fake_nano_proto_lib : nano_proto_library",
- )
- return test_name
-
-def _test_forbidden_nano_export():
- test_name = "kt_jvm_library_forbidden_nano_export_test"
-
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = [test_name + "/Ignored.kt"],
- deps = [test_name + "_export"],
- tags = [
- "manual",
- "nobuilder",
- ],
- )
- native.java_library(
- name = test_name + "_export",
- exports = [test_name + "_fake_nano_proto_lib"],
- )
- native.java_library(
- name = test_name + "_fake_nano_proto_lib",
- srcs = [],
- tags = ["nano_proto_library"],
- )
- assert_failure_test(
- name = test_name,
- target_under_test = test_name + "_tut",
- msg_contains = test_name + "_fake_nano_proto_lib : nano_proto_library",
- )
- return test_name
-
-def _test_kt_jvm_library_with_no_sources():
- test_name = "kt_jvm_library_with_no_sources_test"
-
- kt_jvm_library(
- name = test_name + "_tut",
- tags = [
- "manual",
- "nobuilder",
- ],
- )
- tut_label = str(Label("//tests/analysis:kt_jvm_library_with_no_sources_test_tut"))
- assert_failure_test(
- name = test_name,
- target_under_test = test_name + "_tut",
- msg_contains = "One of {srcs, common_srcs, exports, exported_plugins} of target " + tut_label + " must be non empty",
- )
- return test_name
-
-def _test_kt_jvm_library_coverage():
- test_name = "kt_jvm_library_coverage"
- kt_jvm_library(
- name = test_name + "_tut",
- srcs = ["testinputs/Srcs.kt"],
- common_srcs = ["testinputs/CommonSrcs.kt"],
- deps = [":{}_deps".format(test_name)],
- runtime_deps = [":{}_runtime_deps".format(test_name)],
- data = [":{}_data".format(test_name)],
- resources = [":{}_resources".format(test_name)],
- testonly = True,
- )
- native.java_library(
- name = test_name + "_deps",
- srcs = ["testinputs/Deps.java"],
- testonly = True,
- )
- native.java_library(
- name = test_name + "_runtime_deps",
- srcs = ["testinputs/RuntimeDeps.java"],
- testonly = True,
- )
- native.java_binary(
- name = test_name + "_data",
- main_class = "Data",
- srcs = ["testinputs/Data.java"],
- testonly = True,
- )
- native.java_binary(
- name = test_name + "_resources",
- main_class = "Resources",
- srcs = ["testinputs/Resources.java"],
- testonly = True,
- )
- _coverage_test(
- name = test_name,
- target_under_test = test_name + "_tut",
- expected_instrumented_file_basenames = [
- "Data.java",
- "Deps.java",
- "Resources.java",
- "RuntimeDeps.java",
- "Srcs.kt",
- "CommonSrcs.kt",
- ],
- )
- return test_name
-
-def test_suite(name):
- native.test_suite(
- name = name,
- tests = [
- _test_forbidden_nano_dep(),
- _test_forbidden_nano_export(),
- _test_kt_jvm_library_dep_on_exported_plugin(),
- _test_kt_jvm_library_java_dep_on_exported_plugin(),
- _test_kt_jvm_library_no_kt_srcs_with_plugin(),
- _test_kt_jvm_library_with_export_that_exports_plugin(),
- _test_kt_jvm_library_with_exported_plugin(),
- _test_kt_jvm_library_with_exports(),
- _test_kt_jvm_library_with_java_export_that_exports_plugin(),
- _test_kt_jvm_library_with_no_sources(),
- _test_kt_jvm_library_with_non_processor_plugin(),
- _test_kt_jvm_library_with_plugin(),
- _test_kt_jvm_library_with_proguard_specs(),
- _test_kt_jvm_library_with_resources(),
- _test_kt_jvm_library_coverage(),
- ],
- )
diff --git a/tests/analysis/testinputs/Bar.java b/tests/analysis/testinputs/Bar.java
deleted file mode 100644
index c69a114..0000000
--- a/tests/analysis/testinputs/Bar.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-public class Bar {
- public Bar() {}
-}
diff --git a/tests/analysis/testinputs/CommonSrcs.kt b/tests/analysis/testinputs/CommonSrcs.kt
deleted file mode 100644
index 932e704..0000000
--- a/tests/analysis/testinputs/CommonSrcs.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * * 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 testinputs
-
-class CommonSrcs
diff --git a/tests/analysis/testinputs/Data.java b/tests/analysis/testinputs/Data.java
deleted file mode 100644
index d8e161f..0000000
--- a/tests/analysis/testinputs/Data.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-final class Data {
- private Data() {}
-}
diff --git a/tests/analysis/testinputs/Deps.java b/tests/analysis/testinputs/Deps.java
deleted file mode 100644
index 7f5237f..0000000
--- a/tests/analysis/testinputs/Deps.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-final class Deps {
- private Deps() {}
-}
diff --git a/tests/analysis/testinputs/Foo.java b/tests/analysis/testinputs/Foo.java
deleted file mode 100644
index 249811a..0000000
--- a/tests/analysis/testinputs/Foo.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-public class Foo {
- public Foo() {}
-}
diff --git a/tests/analysis/testinputs/Resources.java b/tests/analysis/testinputs/Resources.java
deleted file mode 100644
index cbf6e7c..0000000
--- a/tests/analysis/testinputs/Resources.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-final class Resources {
- private Resources() {}
-}
diff --git a/tests/analysis/testinputs/RuntimeDeps.java b/tests/analysis/testinputs/RuntimeDeps.java
deleted file mode 100644
index 5515a7a..0000000
--- a/tests/analysis/testinputs/RuntimeDeps.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * * 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 testinputs;
-
-final class RuntimeDeps {
- private RuntimeDeps() {}
-}
diff --git a/tests/analysis/testinputs/Srcs.kt b/tests/analysis/testinputs/Srcs.kt
deleted file mode 100644
index 89ca40c..0000000
--- a/tests/analysis/testinputs/Srcs.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * * 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 testinputs
-
-class Srcs
diff --git a/tests/analysis/util.bzl b/tests/analysis/util.bzl
deleted file mode 100644
index 653843b..0000000
--- a/tests/analysis/util.bzl
+++ /dev/null
@@ -1,125 +0,0 @@
-# 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.
-
-"""Some utils"""
-
-load("//:visibility.bzl", "RULES_KOTLIN")
-
-# Mark targets that's aren't expected to build, but are needed for analysis test assertions.
-ONLY_FOR_ANALYSIS_TEST_TAGS = ["manual", "nobuilder", "only_for_analysis_test"]
-
-def create_file(name, content):
- if content.startswith("\n"):
- content = content[1:-1]
-
- native.genrule(
- name = "gen_" + name,
- outs = [name],
- cmd = """
-cat > $@ <<EOF
-%s
-EOF
-""" % content,
- )
-
- return name
-
-def _create_dir_impl(ctx):
- dir = ctx.actions.declare_directory(ctx.attr.name)
-
- command = "mkdir -p {0} " + ("&& cp {1} {0}" if ctx.files.srcs else "# {1}")
- ctx.actions.run_shell(
- command = command.format(
- dir.path + "/" + ctx.attr.subdir,
- " ".join([s.path for s in ctx.files.srcs]),
- ),
- inputs = ctx.files.srcs,
- outputs = [dir],
- )
-
- return [DefaultInfo(files = depset([dir]))]
-
-_create_dir = rule(
- implementation = _create_dir_impl,
- attrs = dict(
- subdir = attr.string(),
- srcs = attr.label_list(allow_files = True),
- ),
-)
-
-def create_dir(
- name,
- subdir = None,
- srcs = None):
- _create_dir(
- name = name,
- subdir = subdir,
- srcs = srcs,
- )
- return name
-
-def get_action(actions, mnemonic):
- """Get a specific action
-
- Args:
- actions: [List[Action]]
- mnemonic: [string] Identify the action whose args to search
-
- Returns:
- [Optional[action]] The arg value, or None if it couldn't be found
- """
- menmonic_actions = [a for a in actions if a.mnemonic == mnemonic]
- if len(menmonic_actions) == 0:
- return None
- elif len(menmonic_actions) > 1:
- fail("Expected a single '%s' action" % mnemonic)
-
- return menmonic_actions[0]
-
-def get_arg(action, arg_name, style = "trim"):
- """Get a named arg from a specific action
-
- Args:
- action: [Optional[Action]]
- arg_name: [string]
- style: [Optional[string]] The style of commandline arg
-
- Returns:
- [Optional[string]] The arg value, or None if it couldn't be found
- """
- if not action:
- return None
-
- args = action.argv
- matches = [(i, a) for (i, a) in enumerate(args) if a.startswith(arg_name)]
- if len(matches) == 0:
- return None
- elif len(matches) > 1:
- fail("Expected a single '%s' arg" % arg_name)
- (index, arg) = matches[0]
-
- if style == "trim":
- return arg[len(arg_name):]
- elif style == "next":
- return args[index + 1]
- elif style == "list":
- result = []
- for i in range(index + 1, len(args)):
- if args[i].startswith("--"):
- break
- result.append(args[i])
- return result
-
- else:
- fail("Unrecognized arg style '%s" % style)
diff --git a/tests/analysis/jvm_library/no_kt_srcs/BUILD b/tests/common/testing/unittest_suites/BUILD
index d5aafcd..ace4d76 100644
--- a/tests/analysis/jvm_library/no_kt_srcs/BUILD
+++ b/tests/common/testing/unittest_suites/BUILD
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+load(":unittests.bzl", "unittests")
package(
default_testonly = True,
@@ -21,12 +21,12 @@ package(
licenses(["notice"])
-jvm_library_test(
- name = "no_kt_srcs_test",
- target_under_test = rules_for_test.kt_jvm_library(
- name = "no_kt_srcs",
- srcs = [
- "Input.java",
- ],
- ),
+unittests.render(
+ name = "unittests",
+)
+
+bzl_library(
+ name = "unittests_bzl",
+ srcs = ["unittests.bzl"],
+ deps = ["//kotlin/common/testing:testing_bzl"],
)
diff --git a/tests/common/testing/unittest_suites/unittests.bzl b/tests/common/testing/unittest_suites/unittests.bzl
new file mode 100644
index 0000000..6fae083
--- /dev/null
+++ b/tests/common/testing/unittest_suites/unittests.bzl
@@ -0,0 +1,97 @@
+# 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.
+
+"""unittests"""
+
+load("//:visibility.bzl", "RULES_KOTLIN")
+load("//kotlin/common/testing:unittest_suites.bzl", "kt_unittest_suites")
+
+visibility(RULES_KOTLIN)
+
+unittests = kt_unittest_suites.create()
+
+def _add_private_test_case(_ctx, _env):
+ under_test = kt_unittest_suites.create()
+
+ def _some_test():
+ pass
+
+ under_test.expect_finish(_some_test)
+
+unittests.expect_finish(_add_private_test_case)
+
+def _add_private_fail_case(_ctx, _env):
+ under_test = kt_unittest_suites.create()
+
+ def _some_test():
+ pass
+
+ under_test.expect_fail(_some_test, "")
+
+unittests.expect_finish(_add_private_fail_case)
+
+def _add_public_test_case(_ctx):
+ under_test = kt_unittest_suites.create()
+
+ def some_test():
+ pass
+
+ under_test.expect_finish(some_test)
+
+unittests.expect_fail(_add_public_test_case, "private")
+
+def _add_public_fail_case(_ctx):
+ under_test = kt_unittest_suites.create()
+
+ def some_test():
+ pass
+
+ under_test.expect_fail(some_test, "")
+
+unittests.expect_fail(_add_public_fail_case, "private")
+
+def _add_duplicate_test_case(_ctx):
+ under_test = kt_unittest_suites.create()
+
+ def _some_test():
+ pass
+
+ under_test.expect_finish(_some_test)
+ under_test.expect_finish(_some_test)
+
+unittests.expect_fail(_add_duplicate_test_case, "Existing")
+
+def _add_duplicate_fail_case(_ctx):
+ under_test = kt_unittest_suites.create()
+
+ def _some_test():
+ pass
+
+ under_test.expect_fail(_some_test, "")
+ under_test.expect_fail(_some_test, "")
+
+unittests.expect_fail(_add_duplicate_fail_case, "Existing")
+
+def _add_duplicate_test_fail_case(_ctx):
+ under_test = kt_unittest_suites.create()
+
+ def _some_test():
+ pass
+
+ under_test.expect_finish(_some_test)
+ under_test.expect_fail(_some_test, "")
+
+unittests.expect_fail(_add_duplicate_test_fail_case, "Existing")
+
+_test, _fail = unittests.close() # @unused
diff --git a/tests/analysis/compiler_plugin/provider_ctor/BUILD b/tests/jvm/analysis/compiler_plugin/forbidden_target/BUILD
index fb5acbc..d21f27c 100644
--- a/tests/analysis/compiler_plugin/provider_ctor/BUILD
+++ b/tests/jvm/analysis/compiler_plugin/forbidden_target/BUILD
@@ -12,8 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:assert_failure_test.bzl", "assert_failure_test")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
-load(":fake_compiler_plugin.bzl", "kt_fake_compiler_plugin")
+load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/internal_do_not_use/util/file_factory/sub/BUILD b/tests/jvm/analysis/compiler_plugin/provider_ctor/BUILD
index db873cf..0ba8b21 100644
--- a/tests/analysis/internal_do_not_use/util/file_factory/sub/BUILD
+++ b/tests/jvm/analysis/compiler_plugin/provider_ctor/BUILD
@@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-licenses(["notice"])
+load(":unittests.bzl", "unittests")
-genrule(
- name = "sub",
- outs = ["sub.txt"],
- cmd = "touch $(OUTS)",
- visibility = ["//tests/analysis/internal_do_not_use/util/file_factory:__pkg__"],
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
)
+
+licenses(["notice"])
+
+unittests.render(name = "unittests")
diff --git a/tests/analysis/compiler_plugin/provider_ctor/fake_compiler_plugin.bzl b/tests/jvm/analysis/compiler_plugin/provider_ctor/unittests.bzl
index 194025d..e43744f 100644
--- a/tests/analysis/compiler_plugin/provider_ctor/fake_compiler_plugin.bzl
+++ b/tests/jvm/analysis/compiler_plugin/provider_ctor/unittests.bzl
@@ -12,27 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""A fake impl of kt_compiler_plugin."""
+"""unittests"""
-load("//kotlin:compiler_plugin.bzl", "KtCompilerPluginInfo")
load("//:visibility.bzl", "RULES_KOTLIN")
+load("//kotlin:compiler_plugin.bzl", "KtCompilerPluginInfo")
+load("//kotlin/common/testing:unittest_suites.bzl", "kt_unittest_suites")
+
+visibility(RULES_KOTLIN)
+
+unittests = kt_unittest_suites.create()
+
+def _cannot_construct_provider(ctx):
+ KtCompilerPluginInfo(
+ plugin_id = "fake",
+ jar = ctx.actions.declare_file("fake.jar"),
+ args = [],
+ )
-def _kt_fake_compiler_plugin_impl(ctx):
- return [
- KtCompilerPluginInfo(
- plugin_id = "fake",
- jar = ctx.file._jar,
- args = [],
- ),
- ]
+unittests.expect_fail(_cannot_construct_provider, "Error in fail")
-kt_fake_compiler_plugin = rule(
- implementation = _kt_fake_compiler_plugin_impl,
- attrs = dict(
- _jar = attr.label(
- allow_single_file = True,
- default = "//tests/analysis/compiler_plugin:empty_jar",
- ),
- ),
- provides = [KtCompilerPluginInfo],
-)
+_test, _fail = unittests.close() # @unused
diff --git a/tests/jvm/analysis/jvm_compile/no_srcs/BUILD b/tests/jvm/analysis/jvm_compile/no_srcs/BUILD
new file mode 100644
index 0000000..6de9ffb
--- /dev/null
+++ b/tests/jvm/analysis/jvm_compile/no_srcs/BUILD
@@ -0,0 +1,63 @@
+# 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:common.bzl", "common")
+load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_compile_stubs.bzl", "kt_jvm_compile_stubs")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_compile_stubs.analysis_test(
+ name = "no_srcs_android_family_test",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "no_srcs_android_family",
+ srcs = [],
+ common_srcs = [],
+ rule_family = common.RULE_FAMILY.ANDROID_LIBRARY,
+ ),
+)
+
+kt_testing_rules.assert_failure_test(
+ name = "no_srcs_jvm_family_test",
+ msg_contains = "Expected one of (srcs, common_srcs, exports) is not empty",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "no_srcs_jvm_family",
+ srcs = [],
+ common_srcs = [],
+ rule_family = common.RULE_FAMILY.JVM_LIBRARY,
+ exports = [],
+ ),
+)
+
+kt_jvm_compile_stubs.analysis_test(
+ name = "no_srcs_jvm_family_with_exports_test",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "no_srcs_jvm_family_with_exports",
+ srcs = [],
+ common_srcs = [],
+ rule_family = common.RULE_FAMILY.ANDROID_LIBRARY,
+ exports = [
+ ktfa.java_library(
+ name = "no_srcs_jvm_family_export",
+ srcs = [],
+ ),
+ ],
+ ),
+)
diff --git a/tests/jvm/analysis/jvm_compile/r_java/BUILD b/tests/jvm/analysis/jvm_compile/r_java/BUILD
new file mode 100644
index 0000000..70ef77c
--- /dev/null
+++ b/tests/jvm/analysis/jvm_compile/r_java/BUILD
@@ -0,0 +1,61 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_compile_stubs.bzl", "kt_jvm_compile_stubs")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_compile_stubs.analysis_test(
+ name = "has_r_java_named_resources_test",
+ expected_kotlinc_classpath_names = [
+ "platformclasspath.jar", # bootclasspath
+ "libjava_library_resources-hjar.jar", # r_java
+ "libjava_library-hjar.jar", # deps
+ "kotlin-stdlib-ijar.jar", # stdlibs
+ "annotations-13.0-ijar.jar", # stdlibs
+ ],
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "has_r_java_named_resources",
+ srcs = ["Input.kt"],
+ r_java = ":java_library_resources",
+ deps = [":java_library"],
+ ),
+)
+
+kt_testing_rules.assert_failure_test(
+ name = "has_r_java_not_named_resources_test",
+ msg_contains = "illegal dependency provided for r_java",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "has_r_java_not_named_resources",
+ srcs = ["Input.kt"],
+ r_java = ":java_library",
+ ),
+)
+
+ktfa.java_library(
+ name = "java_library_resources",
+ srcs = ["Input.java"],
+)
+
+ktfa.java_library(
+ name = "java_library",
+ srcs = ["Input.java"],
+)
diff --git a/tests/analysis/jvm_library/deps/Input.java b/tests/jvm/analysis/jvm_compile/r_java/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/deps/Input.java
+++ b/tests/jvm/analysis/jvm_compile/r_java/Input.java
diff --git a/tests/jvm/analysis/jvm_compile/r_java/Input.kt b/tests/jvm/analysis/jvm_compile/r_java/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_compile/r_java/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/jvm/analysis/jvm_compile/src_artifacts/BUILD b/tests/jvm/analysis/jvm_compile/src_artifacts/BUILD
new file mode 100644
index 0000000..348c629
--- /dev/null
+++ b/tests/jvm/analysis/jvm_compile/src_artifacts/BUILD
@@ -0,0 +1,61 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:jvm_compile_stubs.bzl", "kt_jvm_compile_stubs")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_compile_stubs.analysis_test(
+ name = "has_allowed_aritfacts_test",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "has_allowed_artifacts",
+ srcs = [
+ # go/keep-sorted start
+ kt_testing_rules.create_dir(name = "has_allowed_artifacts/java"),
+ kt_testing_rules.create_dir(name = "has_allowed_artifacts/kotlin"),
+ kt_testing_rules.create_file(name = "has_allowed_artifacts/java.srcjar"),
+ kt_testing_rules.create_file(name = "has_allowed_artifacts/src.java"),
+ kt_testing_rules.create_file(name = "has_allowed_artifacts/src.kt"),
+ # go/keep-sorted end
+ ],
+ ),
+)
+
+kt_testing_rules.assert_failure_test(
+ name = "has_unexpected_file_type_test",
+ msg_contains = "/src.unexpected",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "has_unexpected_file_type",
+ srcs = [
+ kt_testing_rules.create_file(name = "has_unexpected_file_type/src.unexpected"),
+ ],
+ ),
+)
+
+kt_testing_rules.assert_failure_test(
+ name = "has_unexpected_dir_ending_test",
+ msg_contains = "/kotlin/unexpected",
+ target_under_test = kt_jvm_compile_stubs.rule(
+ name = "has_unexpected_dir_ending",
+ srcs = [
+ kt_testing_rules.create_dir(name = "has_unexpected_dir_ending_test/kotlin/unexpected"),
+ ],
+ ),
+)
diff --git a/tests/jvm/analysis/jvm_import/jars/BUILD b/tests/jvm/analysis/jvm_import/jars/BUILD
new file mode 100644
index 0000000..38b0b62
--- /dev/null
+++ b/tests/jvm/analysis/jvm_import/jars/BUILD
@@ -0,0 +1,45 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_import_analysis_test.bzl", "kt_jvm_import_analysis_test")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_import_analysis_test(
+ name = "one_jar_test",
+ target_under_test = kt_for_analysis.kt_jvm_import(
+ name = "one_jar",
+ jars = [
+ kt_testing_rules.create_file(name = "one_jar.jar"),
+ ],
+ ),
+)
+
+kt_jvm_import_analysis_test(
+ name = "many_jar_test",
+ target_under_test = kt_for_analysis.kt_jvm_import(
+ name = "many_jar",
+ jars = [
+ kt_testing_rules.create_file(name = "many_jar_0.jar"),
+ kt_testing_rules.create_file(name = "many_jar_2.jar"),
+ ],
+ ),
+)
diff --git a/tests/jvm/analysis/jvm_import/runtime_deps/BUILD b/tests/jvm/analysis/jvm_import/runtime_deps/BUILD
new file mode 100644
index 0000000..a6692cc
--- /dev/null
+++ b/tests/jvm/analysis/jvm_import/runtime_deps/BUILD
@@ -0,0 +1,42 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_import_analysis_test.bzl", "kt_jvm_import_analysis_test")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_import_analysis_test(
+ name = "runtime_deps_test",
+ target_under_test = kt_for_analysis.kt_jvm_import(
+ name = "runtime_deps",
+ jars = [
+ kt_testing_rules.create_file(name = "runtime_deps.jar"),
+ ],
+ runtime_deps = [
+ ":runtime_deps_test_dep",
+ ],
+ ),
+)
+
+kt_for_analysis.java_library(
+ name = "runtime_deps_test_dep",
+ srcs = [],
+)
diff --git a/tests/analysis/jvm_library/no_java_srcs/BUILD b/tests/jvm/analysis/jvm_import/srcjar/BUILD
index f149c73..ea1b23c 100644
--- a/tests/analysis/jvm_library/no_java_srcs/BUILD
+++ b/tests/jvm/analysis/jvm_import/srcjar/BUILD
@@ -12,21 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_import_analysis_test.bzl", "kt_jvm_import_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-jvm_library_test(
- name = "no_java_srcs_test",
- target_under_test = rules_for_test.kt_jvm_library(
- name = "no_java_srcs",
- srcs = [
- "Input.kt",
+kt_jvm_import_analysis_test(
+ name = "has_srcjar_test",
+ target_under_test = kt_for_analysis.kt_jvm_import(
+ name = "has_srcjar",
+ jars = [
+ kt_testing_rules.create_file(name = "has_srcjar.jar"),
],
+ srcjar = kt_testing_rules.create_file(name = "has_srcjar.srcjar"),
),
)
diff --git a/tests/jvm/analysis/jvm_library/coverage/BUILD b/tests/jvm/analysis/jvm_library/coverage/BUILD
new file mode 100644
index 0000000..284a7a8
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/coverage/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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_testing_rules.coverage_instrumentation_test(
+ name = "has_coverage_test",
+ expected_instrumented_file_names = [
+ "Data.java",
+ "Dep.java",
+ "Resource.java",
+ "RuntimeDep.java",
+ "Src.kt",
+ "CommonSrc.kt",
+ ],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_coverage",
+ srcs = ["Src.kt"],
+ common_srcs = ["CommonSrc.kt"],
+ data = [":data"],
+ resources = [":resource"],
+ runtime_deps = [":runtime_dep"],
+ deps = [":dep"],
+ ),
+)
+
+ktfa.java_library(
+ name = "dep",
+ srcs = ["Dep.java"],
+)
+
+ktfa.java_library(
+ name = "runtime_dep",
+ srcs = ["RuntimeDep.java"],
+)
+
+ktfa.java_binary(
+ name = "data",
+ srcs = ["Data.java"],
+ main_class = "Data",
+)
+
+ktfa.java_binary(
+ name = "resource",
+ srcs = ["Resource.java"],
+ main_class = "Resources",
+)
diff --git a/tests/jvm/analysis/jvm_library/coverage/CommonSrc.kt b/tests/jvm/analysis/jvm_library/coverage/CommonSrc.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/coverage/CommonSrc.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/data/Input.kt b/tests/jvm/analysis/jvm_library/coverage/Data.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/data/Input.kt
+++ b/tests/jvm/analysis/jvm_library/coverage/Data.java
diff --git a/tests/analysis/jvm_library/deps/Foo.java b/tests/jvm/analysis/jvm_library/coverage/Dep.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/deps/Foo.java
+++ b/tests/jvm/analysis/jvm_library/coverage/Dep.java
diff --git a/tests/analysis/jvm_library/deps/Input.kt b/tests/jvm/analysis/jvm_library/coverage/Resource.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/deps/Input.kt
+++ b/tests/jvm/analysis/jvm_library/coverage/Resource.java
diff --git a/tests/analysis/jvm_library/no_java_srcs/Input.kt b/tests/jvm/analysis/jvm_library/coverage/RuntimeDep.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/no_java_srcs/Input.kt
+++ b/tests/jvm/analysis/jvm_library/coverage/RuntimeDep.java
diff --git a/tests/jvm/analysis/jvm_library/coverage/Src.kt b/tests/jvm/analysis/jvm_library/coverage/Src.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/coverage/Src.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/data/BUILD b/tests/jvm/analysis/jvm_library/data/BUILD
index e92a2e8..92350c0 100644
--- a/tests/analysis/jvm_library/data/BUILD
+++ b/tests/jvm/analysis/jvm_library/data/BUILD
@@ -12,23 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "data_test",
expected_runfile_names = [
"data.txt",
# libX.jar is always in data_runfiles as well - just append it.
"libdata.jar",
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = kt_for_analysis.kt_jvm_library(
name = "data",
srcs = [
"Input.kt",
diff --git a/tests/jvm/analysis/jvm_library/data/Input.kt b/tests/jvm/analysis/jvm_library/data/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/data/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/BUILD b/tests/jvm/analysis/jvm_library/data/data.txt
index 0533e13..d146a73 100644
--- a/tests/analysis/BUILD
+++ b/tests/jvm/analysis/jvm_library/data/data.txt
@@ -12,17 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Analysis Tests
-
-load("//tests/analysis:jvm_compile_test.bzl", jvm_compile_test_suite = "test_suite")
-load("//tests/analysis:jvm_import_test.bzl", jvm_import_test_suite = "test_suite")
-load("//tests/analysis:jvm_library_test.bzl", jvm_library_test_suite = "test_suite")
-load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-
-licenses(["notice"])
-
-jvm_compile_test_suite(name = "jvm_compile_tests")
-
-jvm_library_test_suite(name = "jvm_library_tests")
-
-jvm_import_test_suite(name = "jvm_import_tests")
+# 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. \ No newline at end of file
diff --git a/tests/analysis/jvm_library/deps/BUILD b/tests/jvm/analysis/jvm_library/deps/BUILD
index 6db53bd..fb01c01 100644
--- a/tests/analysis/jvm_library/deps/BUILD
+++ b/tests/jvm/analysis/jvm_library/deps/BUILD
@@ -12,35 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-rules_for_test.kt_jvm_library(
- name = "deps_test_kt_dep",
- srcs = [
- "Input.kt",
- ],
-)
-
-rules_for_test.java_library(
- name = "deps_test_java_dep",
- srcs = [
- "Input.java",
- ],
+kt_jvm_library_analysis_test(
+ name = "no_deps_test",
+ target_under_test = kt_for_analysis.kt_jvm_library(
+ name = "no_deps",
+ srcs = [
+ "Input.java",
+ "Input.kt",
+ ],
+ ),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "deps_test",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = kt_for_analysis.kt_jvm_library(
name = "deps",
srcs = [
- "Foo.java",
+ "Input.java",
],
deps = [
":deps_test_java_dep",
@@ -48,3 +46,17 @@ jvm_library_test(
],
),
)
+
+kt_for_analysis.kt_jvm_library(
+ name = "deps_test_kt_dep",
+ srcs = [
+ "Input.kt",
+ ],
+)
+
+kt_for_analysis.java_library(
+ name = "deps_test_java_dep",
+ srcs = [
+ "Input.java",
+ ],
+)
diff --git a/tests/analysis/jvm_library/no_kt_srcs/Input.java b/tests/jvm/analysis/jvm_library/deps/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/no_kt_srcs/Input.java
+++ b/tests/jvm/analysis/jvm_library/deps/Input.java
diff --git a/tests/jvm/analysis/jvm_library/deps/Input.kt b/tests/jvm/analysis/jvm_library/deps/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/deps/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/jvm/analysis/jvm_library/exports/BUILD b/tests/jvm/analysis/jvm_library/exports/BUILD
new file mode 100644
index 0000000..b2bb9c7
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/exports/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/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_jvm_library_analysis_test(
+ name = "has_exports_test",
+ expected_compile_jar_names = [
+ # go/keep-sorted start
+ "libexports_transitive-compile.jar",
+ "libhas_exports-compile.jar",
+ "libjava_library-hjar.jar",
+ "libkt_jvm_library-compile.jar",
+ "libtransitive-compile.jar",
+ # go/keep-sorted end
+ ],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_exports",
+ srcs = ["Input.kt"],
+ exports = [
+ ":exports_transitive",
+ ":java_library",
+ ":kt_jvm_library",
+ ],
+ ),
+)
+
+ktfa.kt_jvm_library(
+ name = "exports_transitive",
+ srcs = ["Input.kt"],
+ exports = [
+ ktfa.kt_jvm_library(
+ name = "transitive",
+ srcs = ["Input.kt"],
+ ),
+ ],
+)
+
+ktfa.kt_jvm_library(
+ name = "kt_jvm_library",
+ srcs = ["Input.kt"],
+)
+
+ktfa.java_library(
+ name = "java_library",
+ srcs = ["Input.java"], # need file here so we get a Jar
+)
diff --git a/tests/analysis/jvm_library/nodeps/Input.java b/tests/jvm/analysis/jvm_library/exports/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/nodeps/Input.java
+++ b/tests/jvm/analysis/jvm_library/exports/Input.java
diff --git a/tests/jvm/analysis/jvm_library/exports/Input.kt b/tests/jvm/analysis/jvm_library/exports/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/exports/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/jvm/analysis/jvm_library/forbidden_deps/BUILD b/tests/jvm/analysis/jvm_library/forbidden_deps/BUILD
new file mode 100644
index 0000000..5fcc02f
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/forbidden_deps/BUILD
@@ -0,0 +1,54 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_testing_rules.assert_failure_test(
+ name = "has_forbidden_nano_dep_test",
+ msg_contains = "fake_nano_proto_lib",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_forbidden_nano_dep",
+ srcs = ["Inputs.kt"],
+ deps = [":fake_nano_proto_lib"],
+ ),
+)
+
+kt_testing_rules.assert_failure_test(
+ name = "dep_on_has_forbidden_nano_export_test",
+ msg_contains = "fake_nano_proto_lib",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "dep_on_has_forbidden_nano_export",
+ srcs = ["Input.kt"],
+ deps = [
+ ktfa.java_library(
+ name = "has_forbidden_nano_export",
+ exports = [":fake_nano_proto_lib"],
+ ),
+ ],
+ ),
+)
+
+ktfa.java_library(
+ name = "fake_nano_proto_lib",
+ srcs = [],
+ tags = ["nano_proto_library"],
+)
diff --git a/tests/jvm/analysis/jvm_library/forbidden_deps/Input.kt b/tests/jvm/analysis/jvm_library/forbidden_deps/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/forbidden_deps/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/friends/BUILD b/tests/jvm/analysis/jvm_library/friends/BUILD
index 538bdce..f2454f4 100644
--- a/tests/analysis/jvm_library/friends/BUILD
+++ b/tests/jvm/analysis/jvm_library/friends/BUILD
@@ -12,103 +12,99 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//kotlin:rules.bzl", "kt_jvm_library")
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
- default_visibility = ["//tests/analysis/jvm_library/friends:__subpackages__"],
+ default_visibility = ["//tests/jvm/analysis/jvm_library/friends:__subpackages__"],
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_kt_exported_friend_cross_package_test",
expected_friend_jar_names = [],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_kt_exported_friend_cross_package",
srcs = ["Input.kt"],
deps = [
# Exports :friend from this package
- "//tests/analysis/jvm_library/friends/sub:kt_exports_friend",
+ "//tests/jvm/analysis/jvm_library/friends/sub:kt_exports_friend",
],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "has_java_exported_friend_in_package_test",
expected_friend_jar_names = [
"libjava_exports_friend-hjar.jar",
"libfriend-compile.jar",
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "has_java_exported_friend_in_package",
srcs = ["Input.kt"],
deps = [":java_exports_friend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "has_kt_exported_friend_in_package_test",
expected_friend_jar_names = [
"libkt_exports_friend-compile.jar",
"libfriend-compile.jar",
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "has_kt_exported_friend_in_package",
srcs = ["Input.kt"],
deps = [":kt_exports_friend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_direct_friend_testing_package_test",
expected_friend_jar_names = [],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_direct_friend_testing_package",
srcs = ["Input.kt"],
- deps = ["//tests/analysis/jvm_library/friends/testing:testingfriend"],
+ deps = ["//tests/jvm/analysis/jvm_library/friends/testing:testingfriend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_direct_friend_subpackage_test",
expected_friend_jar_names = [],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_direct_friend_subpackage",
srcs = ["Input.kt"],
- deps = ["//tests/analysis/jvm_library/friends/sub:subfriend"],
+ deps = ["//tests/jvm/analysis/jvm_library/friends/sub:subfriend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "has_direct_friend_in_package_test",
expected_friend_jar_names = ["libfriend-compile.jar"],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "has_direct_friend_in_package",
srcs = ["Input.kt"],
deps = [":friend"],
),
)
-java_library(
+ktfa.java_library(
name = "java_exports_friend",
srcs = ["Input.java"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
exports = [":friend"],
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "kt_exports_friend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
exports = [":friend"],
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "friend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
)
diff --git a/tests/analysis/jvm_library/friends/Input.java b/tests/jvm/analysis/jvm_library/friends/Input.java
index 5bf1d18..5bf1d18 100644
--- a/tests/analysis/jvm_library/friends/Input.java
+++ b/tests/jvm/analysis/jvm_library/friends/Input.java
diff --git a/tests/analysis/jvm_library/friends/Input.kt b/tests/jvm/analysis/jvm_library/friends/Input.kt
index b1a99cb..b1a99cb 100644
--- a/tests/analysis/jvm_library/friends/Input.kt
+++ b/tests/jvm/analysis/jvm_library/friends/Input.kt
diff --git a/tests/analysis/jvm_library/friends/sub/BUILD b/tests/jvm/analysis/jvm_library/friends/sub/BUILD
index e7c619f..7f4a38e 100644
--- a/tests/analysis/jvm_library/friends/sub/BUILD
+++ b/tests/jvm/analysis/jvm_library/friends/sub/BUILD
@@ -12,50 +12,47 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//kotlin:rules.bzl", "kt_jvm_library")
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
- default_visibility = ["//tests/analysis/jvm_library/friends:__subpackages__"],
+ default_visibility = ["//tests/jvm/analysis/jvm_library/friends:__subpackages__"],
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_kt_exported_friend_cross_package_test",
expected_friend_jar_names = [
"libkt_exports_friend-compile.jar",
# Absent # "libfriend-compile.jar"
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_kt_exported_friend_cross_package",
srcs = ["Input.kt"],
deps = [":kt_exports_friend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_direct_friend_cross_package_test",
expected_friend_jar_names = [],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_direct_friend_cross_package",
srcs = ["Input.kt"],
- deps = ["//tests/analysis/jvm_library/friends:friend"],
+ deps = ["//tests/jvm/analysis/jvm_library/friends:friend"],
),
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "kt_exports_friend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- exports = ["//tests/analysis/jvm_library/friends:friend"],
+ exports = ["//tests/jvm/analysis/jvm_library/friends:friend"],
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "subfriend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
)
diff --git a/tests/analysis/jvm_library/friends/sub/Input.kt b/tests/jvm/analysis/jvm_library/friends/sub/Input.kt
index 4c87a1e..4c87a1e 100644
--- a/tests/analysis/jvm_library/friends/sub/Input.kt
+++ b/tests/jvm/analysis/jvm_library/friends/sub/Input.kt
diff --git a/tests/analysis/jvm_library/friends/testing/BUILD b/tests/jvm/analysis/jvm_library/friends/testing/BUILD
index 827aa30..0ab1bba 100644
--- a/tests/analysis/jvm_library/friends/testing/BUILD
+++ b/tests/jvm/analysis/jvm_library/friends/testing/BUILD
@@ -12,82 +12,78 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//kotlin:rules.bzl", "kt_jvm_library")
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
- default_visibility = ["//tests/analysis/jvm_library/friends:__subpackages__"],
+ default_visibility = ["//tests/jvm/analysis/jvm_library/friends:__subpackages__"],
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "has_kt_exported_friend_impl_package_test",
expected_friend_jar_names = [
"libkt_exports_friend-compile.jar",
"libfriend-compile.jar",
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "has_kt_exported_friend_impl_package",
srcs = ["Input.kt"],
deps = [":kt_exports_friend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "has_direct_friend_impl_package_test",
expected_friend_jar_names = [
"libfriend-compile.jar",
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "has_direct_friend_impl_package",
srcs = ["Input.kt"],
- deps = ["//tests/analysis/jvm_library/friends:friend"],
+ deps = ["//tests/jvm/analysis/jvm_library/friends:friend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_kt_exported_friend_sibling_package_test",
expected_friend_jar_names = [
"libkt_exports_subfriend-compile.jar",
# Absent # "subfriend-compile.jar"
],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_kt_exported_friend_sibling_package",
srcs = ["Input.kt"],
deps = [":kt_exports_subfriend"],
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "no_direct_friend_sibling_package_test",
expected_friend_jar_names = [],
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "no_direct_friend_sibling_package",
srcs = ["Input.kt"],
- deps = ["//tests/analysis/jvm_library/friends/sub:subfriend"],
+ deps = ["//tests/jvm/analysis/jvm_library/friends/sub:subfriend"],
),
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "kt_exports_subfriend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- exports = ["//tests/analysis/jvm_library/friends/sub:subfriend"],
+ exports = ["//tests/jvm/analysis/jvm_library/friends/sub:subfriend"],
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "kt_exports_friend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
- exports = ["//tests/analysis/jvm_library/friends:friend"],
+ exports = ["//tests/jvm/analysis/jvm_library/friends:friend"],
)
-kt_jvm_library(
+ktfa.kt_jvm_library(
name = "testingfriend",
srcs = ["Input.kt"],
- tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
)
diff --git a/tests/analysis/jvm_library/friends/testing/Input.kt b/tests/jvm/analysis/jvm_library/friends/testing/Input.kt
index 2c65124..2c65124 100644
--- a/tests/analysis/jvm_library/friends/testing/Input.kt
+++ b/tests/jvm/analysis/jvm_library/friends/testing/Input.kt
diff --git a/tests/jvm/analysis/jvm_library/no_srcs/BUILD b/tests/jvm/analysis/jvm_library/no_srcs/BUILD
new file mode 100644
index 0000000..004d160
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/no_srcs/BUILD
@@ -0,0 +1,69 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+kt_testing_rules.assert_failure_test(
+ name = "no_srcs_test",
+ msg_contains = "Expected a source-bearing or an export-oriented target",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "no_srcs",
+ srcs = [],
+ ),
+)
+
+kt_jvm_library_analysis_test(
+ name = "no_srcs_with_exports_test",
+ expect_jdeps = False,
+ required_mnemonic_counts = {"KtAndroidLint": "0"},
+ target_under_test = ktfa.kt_jvm_library(
+ name = "no_srcs_with_exports",
+ srcs = [],
+ exports = [
+ ktfa.kt_jvm_library(
+ name = "no_srcs_with_exports_export",
+ srcs = ["Input.kt"],
+ ),
+ ],
+ ),
+)
+
+kt_jvm_library_analysis_test(
+ name = "only_kt_srcs_test",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "only_kt_srcs",
+ srcs = [
+ "Input.kt",
+ ],
+ ),
+)
+
+kt_jvm_library_analysis_test(
+ name = "only_java_srcs_test",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "only_java_srcs",
+ srcs = [
+ "Input.java",
+ ],
+ ),
+)
diff --git a/tests/analysis/jvm_library/runtime_deps/Input.java b/tests/jvm/analysis/jvm_library/no_srcs/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/runtime_deps/Input.java
+++ b/tests/jvm/analysis/jvm_library/no_srcs/Input.java
diff --git a/tests/jvm/analysis/jvm_library/no_srcs/Input.kt b/tests/jvm/analysis/jvm_library/no_srcs/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/no_srcs/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/only_common_srcs/BUILD b/tests/jvm/analysis/jvm_library/only_common_srcs/BUILD
index aae3068..a91cff7 100644
--- a/tests/analysis/jvm_library/only_common_srcs/BUILD
+++ b/tests/jvm/analysis/jvm_library/only_common_srcs/BUILD
@@ -12,18 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "only_common_srcs_test",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = kt_for_analysis.kt_jvm_library(
name = "only_common_srcs",
common_srcs = [
"Input.kt",
diff --git a/tests/jvm/analysis/jvm_library/only_common_srcs/Input.kt b/tests/jvm/analysis/jvm_library/only_common_srcs/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/only_common_srcs/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/jvm/analysis/jvm_library/plugins/BUILD b/tests/jvm/analysis/jvm_library/plugins/BUILD
new file mode 100644
index 0000000..3694233
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/plugins/BUILD
@@ -0,0 +1,153 @@
+# 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/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_testonly = True,
+)
+
+licenses(["notice"])
+
+DEFAULT_KOTLINC_PLUGINS = [
+ "jvm-abi-gen.jar",
+]
+
+kt_jvm_library_analysis_test(
+ name = "has_plugin_and_only_kt_srcs_test",
+ expect_processor_classpath = True,
+ expected_exported_processor_classes = [],
+ expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS + ["kt_compiler_plugin.jar"],
+ expected_processor_classes = ["java.plugin.class"],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_plugin_and_only_kt_srcs",
+ srcs = ["Input.kt"],
+ plugins = [
+ ":java_plugin",
+ ":kt_compiler_plugin",
+ ],
+ ),
+)
+
+kt_jvm_library_analysis_test(
+ name = "has_plugin_and_only_java_srcs_test",
+ expect_processor_classpath = True,
+ expected_exported_processor_classes = [],
+ expected_kotlinc_plugin_jar_names = [], # No kotlinc action
+ expected_processor_classes = ["java.plugin.class"],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_plugin_and_only_java_srcs",
+ srcs = ["Input.java"],
+ plugins = [
+ ":java_plugin",
+ ":kt_compiler_plugin",
+ ],
+ ),
+)
+
+kt_jvm_library_analysis_test(
+ name = "has_plugin_without_processor_class_test",
+ expect_processor_classpath = True,
+ expected_exported_processor_classes = [],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_plugin_without_processor_class",
+ srcs = ["Input.java"],
+ plugins = [
+ ktfa.java_plugin(
+ name = "java_plugin_without_processor_class",
+ srcs = ["Input.java"],
+ ),
+ ],
+ ),
+)
+
+[
+ kt_jvm_library_analysis_test(
+ name = "dep_on_" + exporter + "_test",
+ expect_processor_classpath = True,
+ expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS + ["kt_compiler_plugin.jar"],
+ expected_processor_classes = ["java.plugin.class"],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "dep_on_" + exporter,
+ srcs = ["Input.kt"],
+ deps = [exporter],
+ ),
+ )
+ for exporter in [
+ "java_library_with_exported_plugin",
+ "kt_jvm_library_with_exported_plugin",
+ ] + [
+ "kt_jvm_library_exporting_java_library_with_exported_plugin",
+ "kt_jvm_library_exporting_kt_jvm_library_with_exported_plugin",
+ ]
+]
+
+[
+ kt_jvm_library_analysis_test(
+ name = "kt_jvm_library_exporting_" + export + "_test",
+ expect_processor_classpath = False,
+ expected_exported_processor_classes = ["java.plugin.class"],
+ expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS,
+ expected_processor_classes = [],
+ target_under_test = ktfa.kt_jvm_library(
+ name = "kt_jvm_library_exporting_" + export,
+ srcs = ["Input.kt"],
+ exports = [export],
+ ),
+ )
+ for export in [
+ "java_library_with_exported_plugin",
+ "kt_jvm_library_with_exported_plugin",
+ ]
+]
+
+ktfa.java_library(
+ name = "java_library_with_exported_plugin",
+ srcs = ["Input.java"],
+ exported_plugins = [
+ ":java_plugin",
+ ":kt_compiler_plugin",
+ ],
+)
+
+kt_jvm_library_analysis_test(
+ name = "kt_jvm_library_with_exported_plugin_test",
+ expect_processor_classpath = False,
+ expected_exported_processor_classes = ["java.plugin.class"],
+ expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS,
+ expected_processor_classes = [], # exported plugin should *not* run on exporter itself
+ target_under_test = ktfa.kt_jvm_library(
+ name = "kt_jvm_library_with_exported_plugin",
+ srcs = ["Input.kt"],
+ exported_plugins = [
+ ":java_plugin",
+ ":kt_compiler_plugin",
+ ],
+ ),
+)
+
+ktfa.java_plugin(
+ name = "java_plugin",
+ srcs = ["Input.java"],
+ processor_class = "java.plugin.class",
+)
+
+ktfa.kt_compiler_plugin(
+ name = "kt_compiler_plugin",
+ jar = kt_testing_rules.create_file(name = "kt_compiler_plugin.jar"),
+ plugin_id = "kt.plugin",
+)
diff --git a/tests/analysis/jvm_library/treeartifacts_srcs/Input.java b/tests/jvm/analysis/jvm_library/plugins/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/treeartifacts_srcs/Input.java
+++ b/tests/jvm/analysis/jvm_library/plugins/Input.java
diff --git a/tests/jvm/analysis/jvm_library/plugins/Input.kt b/tests/jvm/analysis/jvm_library/plugins/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/plugins/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/nodeps/BUILD b/tests/jvm/analysis/jvm_library/resources/BUILD
index f2ae73b..1c4797f 100644
--- a/tests/analysis/jvm_library/nodeps/BUILD
+++ b/tests/jvm/analysis/jvm_library/resources/BUILD
@@ -12,22 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-jvm_library_test(
- name = "nodeps_test",
- target_under_test = rules_for_test.kt_jvm_library(
- name = "nodeps",
- srcs = [
- "Input.java",
- "Input.kt",
- ],
+kt_jvm_library_analysis_test(
+ name = "has_resources_test",
+ target_under_test = ktfa.kt_jvm_library(
+ name = "has_resources",
+ srcs = ["Input.kt"],
+ resources = ["resource.txt"],
),
)
diff --git a/tests/jvm/analysis/jvm_library/resources/Input.kt b/tests/jvm/analysis/jvm_library/resources/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/resources/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/data/data.txt b/tests/jvm/analysis/jvm_library/resources/resource.txt
index e3ba5e8..b986da2 100644
--- a/tests/analysis/jvm_library/data/data.txt
+++ b/tests/jvm/analysis/jvm_library/resources/resource.txt
@@ -10,4 +10,5 @@
# 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. \ No newline at end of file
+# limitations under the License.
+
diff --git a/tests/analysis/jvm_library/runtime_deps/BUILD b/tests/jvm/analysis/jvm_library/runtime_deps/BUILD
index 85f8b55..aaea117 100644
--- a/tests/analysis/jvm_library/runtime_deps/BUILD
+++ b/tests/jvm/analysis/jvm_library/runtime_deps/BUILD
@@ -12,23 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-rules_for_test.java_library(
+kt_for_analysis.java_library(
name = "runtime_deps_test_dep",
srcs = [],
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "runtime_deps_test",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = kt_for_analysis.kt_jvm_library(
name = "runtime_deps",
srcs = [
"Input.kt",
diff --git a/tests/analysis/jvm_library/nodeps/Input.kt b/tests/jvm/analysis/jvm_library/runtime_deps/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/nodeps/Input.kt
+++ b/tests/jvm/analysis/jvm_library/runtime_deps/Input.java
diff --git a/tests/jvm/analysis/jvm_library/runtime_deps/Input.kt b/tests/jvm/analysis/jvm_library/runtime_deps/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/runtime_deps/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/jvm_library/treeartifacts_srcs/BUILD b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/BUILD
index 2ba8ecf..6151a43 100644
--- a/tests/analysis/jvm_library/treeartifacts_srcs/BUILD
+++ b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/BUILD
@@ -12,23 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:assert_failure_test.bzl", "assert_failure_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-load("//tests/analysis:util.bzl", "create_dir")
+load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules")
+load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = True,
)
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "treeartifact_basename_kotlin_test",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_basename_kotlin",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_extension/kotlin",
srcs = [
"Input.java", # TODO: Reject this source
@@ -38,12 +38,12 @@ jvm_library_test(
),
)
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "treeartifact_basename_java_test",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_basename_java",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_extension/java",
srcs = [
"Input.kt", # TODO: Reject this source
@@ -53,52 +53,52 @@ jvm_library_test(
),
)
-assert_failure_test(
+kt_testing_rules.assert_failure_test(
name = "treeartifact_extension_kt_test",
msg_contains = "/treeartifact_extension.kt",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_extension_kt",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_extension.kt",
),
],
),
)
-assert_failure_test(
+kt_testing_rules.assert_failure_test(
name = "treeartifact_extension_java_test",
msg_contains = "/treeartifact_extension.java",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_extension_java",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_extension.java",
),
],
),
)
-assert_failure_test(
+kt_testing_rules.assert_failure_test(
name = "treeartifact_extension_srcjar_test",
msg_contains = "/treeartifact_extension.srcjar",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_extension_srcjar",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_extension.srcjar",
),
],
),
)
-assert_failure_test(
+kt_testing_rules.assert_failure_test(
name = "treeartifact_no_extension_test",
msg_contains = "/treeartifact_no_extension",
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = ktfa.kt_jvm_library(
name = "treeartifact_no_extension",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "treeartifact_no_extension_dir",
),
],
diff --git a/tests/analysis/jvm_library/only_common_srcs/Input.kt b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.java
index e675bc1..e675bc1 100644
--- a/tests/analysis/jvm_library/only_common_srcs/Input.kt
+++ b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.java
diff --git a/tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.kt b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.kt
new file mode 100644
index 0000000..963d749
--- /dev/null
+++ b/tests/jvm/analysis/jvm_library/treeartifacts_srcs/Input.kt
@@ -0,0 +1,17 @@
+/*
+ * * 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.
+ */
+
+
diff --git a/tests/analysis/compiler_plugin/forbidden_target/BUILD b/tests/jvm/analysis/util/file_factory/BUILD
index 9f751fa..3a0b592 100644
--- a/tests/analysis/compiler_plugin/forbidden_target/BUILD
+++ b/tests/jvm/analysis/util/file_factory/BUILD
@@ -12,8 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//kotlin:compiler_plugin.bzl", "kt_compiler_plugin")
-load("//tests/analysis:assert_failure_test.bzl", "assert_failure_test")
-load("//tests/analysis:util.bzl", "ONLY_FOR_ANALYSIS_TEST_TAGS")
+load(":unittests.bzl", "unittests")
+
+package(
+ default_testonly = True,
+)
licenses(["notice"])
+
+unittests.render(
+ name = "unittests",
+)
diff --git a/tests/jvm/analysis/util/file_factory/unittests.bzl b/tests/jvm/analysis/util/file_factory/unittests.bzl
new file mode 100644
index 0000000..cf7a2a4
--- /dev/null
+++ b/tests/jvm/analysis/util/file_factory/unittests.bzl
@@ -0,0 +1,85 @@
+# 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.
+
+"""unittests"""
+
+load("//:visibility.bzl", "RULES_KOTLIN")
+load("//kotlin/common/testing:unittest_suites.bzl", "kt_unittest_suites")
+load("//kotlin/jvm/util:file_factory.bzl", "FileFactory")
+load("@bazel_skylib//lib:unittest.bzl", "asserts")
+
+visibility(RULES_KOTLIN)
+
+unittests = kt_unittest_suites.create()
+
+def _base_from_file(ctx, env):
+ base_file = ctx.actions.declare_file("file/base.txt")
+ factory = FileFactory(ctx, base_file)
+
+ _assert_path_equals(ctx, env, "/file/base", factory.base_as_path)
+
+ return [base_file]
+
+unittests.expect_finish(_base_from_file)
+
+def _declare(ctx, env):
+ factory = FileFactory(ctx, "string/base")
+
+ _assert_path_equals(ctx, env, "/string/base", factory.base_as_path)
+
+ a_file = factory.declare_file("a.txt")
+ _assert_path_equals(ctx, env, "/string/basea.txt", a_file.path)
+
+ b_dir = factory.declare_directory("b_dir")
+ _assert_path_equals(ctx, env, "/string/baseb_dir", b_dir.path)
+
+ return [a_file, b_dir]
+
+unittests.expect_finish(_declare)
+
+def _derive(ctx, env):
+ factory = FileFactory(ctx, "")
+
+ # Once
+ factory_once = factory.derive("once")
+ _assert_path_equals(ctx, env, "/once", factory_once.base_as_path)
+
+ # Twice
+ factory_twice = factory_once.derive("/twice")
+ _assert_path_equals(ctx, env, "/once/twice", factory_twice.base_as_path)
+
+unittests.expect_finish(_derive)
+
+def _base_file_without_extension(ctx):
+ base_file = ctx.actions.declare_file(ctx.label.name + "/BUILD")
+ FileFactory(ctx, base_file)
+
+unittests.expect_fail(_base_file_without_extension, "file must have an extension")
+
+def _base_file_from_different_pkg(ctx):
+ mock_file = struct(owner = struct(package = ctx.label.package + "/sub"), extension = "txt")
+ FileFactory(ctx, mock_file)
+
+unittests.expect_fail(_base_file_from_different_pkg, "file must be from ctx package")
+
+def _assert_path_equals(ctx, env, expected, actual):
+ pkg_path = ctx.bin_dir.path + "/" + ctx.label.package
+
+ asserts.equals(
+ env,
+ pkg_path + expected,
+ actual,
+ )
+
+_test, _fail = unittests.close() # @unused
diff --git a/tests/jvm/java/neverlink/BUILD b/tests/jvm/java/neverlink/BUILD
index c6daa08..a25ac73 100644
--- a/tests/jvm/java/neverlink/BUILD
+++ b/tests/jvm/java/neverlink/BUILD
@@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//tests/analysis:for_test.bzl", "rules_for_test")
-load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
+load("//kotlin/jvm/testing:for_analysis.bzl", "kt_for_analysis")
+load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test")
licenses(["notice"])
-jvm_library_test(
+kt_jvm_library_analysis_test(
name = "neverlinked_input_library_test",
expect_neverlink = True,
- target_under_test = rules_for_test.kt_jvm_library(
+ target_under_test = kt_for_analysis.kt_jvm_library(
name = "neverlinked_input_library",
srcs = ["Input.kt"],
neverlink = True,
diff --git a/tests/jvm/java/srcartifacts/BUILD b/tests/jvm/java/srcartifacts/BUILD
index 9d51c82..e974d73 100644
--- a/tests/jvm/java/srcartifacts/BUILD
+++ b/tests/jvm/java/srcartifacts/BUILD
@@ -13,10 +13,11 @@
# limitations under the License.
load("//kotlin:rules.bzl", "kt_jvm_library", "kt_jvm_test")
-load("//tests/analysis:util.bzl", "create_dir", "create_file")
+load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
package(
+ default_applicable_licenses = ["//:license"],
default_testonly = 1,
)
@@ -43,7 +44,7 @@ kt_jvm_test(
],
)
-create_dir(
+kt_testing_rules.create_dir(
name = "dir/java",
srcs = [
"JavaInJavaDir.java",
@@ -51,7 +52,7 @@ create_dir(
subdir = "srcartifacts",
)
-create_dir(
+kt_testing_rules.create_dir(
name = "dir/kotlin",
srcs = [
"KtInKotlinDir.kt",
@@ -59,16 +60,16 @@ create_dir(
subdir = "srcartifacts",
)
-create_dir(
+kt_testing_rules.create_dir(
name = "dir/empty",
srcs = [],
subdir = "srcartifacts/empty",
)
-create_dir(
+kt_testing_rules.create_dir(
name = "dir/resources",
srcs = [
- create_file(
+ kt_testing_rules.create_file(
name = "resources_in_resources_dir.txt",
content = "Test resource content.",
),
@@ -92,7 +93,7 @@ java_library(
kt_jvm_library(
name = "empty_java_tree_artifact",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "dir/empty_java/java",
srcs = [],
subdir = "srcartifacts",
@@ -103,7 +104,7 @@ kt_jvm_library(
kt_jvm_library(
name = "empty_kotlin_tree_artifact",
srcs = [
- create_dir(
+ kt_testing_rules.create_dir(
name = "dir/empty_kotlin/kotlin",
srcs = [],
subdir = "srcartifacts",