From b0bba1aec080c9872958b23b5b69d56830d87afd Mon Sep 17 00:00:00 2001 From: nickreid Date: Tue, 17 Oct 2023 19:20:39 -0700 Subject: Expand jvm_compile_test.bzl into BUILD files PiperOrigin-RevId: 574329035 --- kotlin/jvm/testing/jvm_compile_stubs.bzl | 128 +++++++ tests/analysis/BUILD | 3 - tests/analysis/jvm_compile_test.bzl | 393 --------------------- tests/jvm/analysis/jvm_compile/no_srcs/BUILD | 63 ++++ tests/jvm/analysis/jvm_compile/r_java/BUILD | 61 ++++ tests/jvm/analysis/jvm_compile/r_java/Input.java | 16 + tests/jvm/analysis/jvm_compile/r_java/Input.kt | 17 + tests/jvm/analysis/jvm_compile/src_artifacts/BUILD | 61 ++++ 8 files changed, 346 insertions(+), 396 deletions(-) create mode 100644 kotlin/jvm/testing/jvm_compile_stubs.bzl delete mode 100644 tests/analysis/jvm_compile_test.bzl create mode 100644 tests/jvm/analysis/jvm_compile/no_srcs/BUILD create mode 100644 tests/jvm/analysis/jvm_compile/r_java/BUILD create mode 100644 tests/jvm/analysis/jvm_compile/r_java/Input.java create mode 100644 tests/jvm/analysis/jvm_compile/r_java/Input.kt create mode 100644 tests/jvm/analysis/jvm_compile/src_artifacts/BUILD diff --git a/kotlin/jvm/testing/jvm_compile_stubs.bzl b/kotlin/jvm/testing/jvm_compile_stubs.bzl new file mode 100644 index 0000000..0d5a573 --- /dev/null +++ b/kotlin/jvm/testing/jvm_compile_stubs.bzl @@ -0,0 +1,128 @@ +# 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. + +"""kt_jvm_compile_stubs""" + +load("//:visibility.bzl", "RULES_KOTLIN") +load("//kotlin:common.bzl", "common") +load("//kotlin:jvm_compile.bzl", "kt_jvm_compile") +load("//kotlin:traverse_exports.bzl", "kt_traverse_exports") +load("//kotlin/common/testing:analysis.bzl", "kt_analysis") +load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules") +load("//toolchains/kotlin_jvm:java_toolchains.bzl", "java_toolchains") +load("//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "kt_jvm_toolchains") +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") + +visibility(RULES_KOTLIN) + +_kt_jvm_compile_stub_rule = rule( + implementation = lambda ctx: _kt_jvm_compile_stub_rule_impl(ctx), + 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 _kt_jvm_compile_stub_rule_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_stub_analysis_test = analysistest.make( + impl = lambda ctx: _kt_jvm_compile_stub_analysis_test_impl(ctx), + attrs = dict( + expected_kotlinc_classpath_names = attr.string_list(default = kt_analysis.DEFAULT_LIST), + ), +) + +def _kt_jvm_compile_stub_analysis_test_impl(ctx): + kt_analysis.check_endswith_test(ctx) + + env = analysistest.begin(ctx) + + actions = analysistest.target_actions(env) + kotlinc_action = kt_analysis.get_action(actions, "Kt2JavaCompile") + + asserts.true( + env, + JavaInfo in ctx.attr.target_under_test, + "Did not produce JavaInfo provider.", + ) + + if ctx.attr.expected_kotlinc_classpath_names != kt_analysis.DEFAULT_LIST: + kotlinc_classpath = kt_analysis.get_arg(kotlinc_action, "-cp", style = "next").split(":") + asserts.equals( + env, + ctx.attr.expected_kotlinc_classpath_names, + [file.rsplit("/", 1)[1] for file in kotlinc_classpath], + ) + + return analysistest.end(env) + +kt_jvm_compile_stubs = struct( + rule = kt_testing_rules.wrap_for_analysis(_kt_jvm_compile_stub_rule), + analysis_test = _kt_jvm_compile_stub_analysis_test, +) diff --git a/tests/analysis/BUILD b/tests/analysis/BUILD index 5d07dd0..84f96dc 100644 --- a/tests/analysis/BUILD +++ b/tests/analysis/BUILD @@ -14,9 +14,6 @@ # Analysis Tests -load("//tests/analysis:jvm_compile_test.bzl", jvm_compile_test_suite = "test_suite") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") licenses(["notice"]) - -jvm_compile_test_suite(name = "jvm_compile_tests") diff --git a/tests/analysis/jvm_compile_test.bzl b/tests/analysis/jvm_compile_test.bzl deleted file mode 100644 index be69162..0000000 --- a/tests/analysis/jvm_compile_test.bzl +++ /dev/null @@ -1,393 +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("//:visibility.bzl", "RULES_KOTLIN") -load("//kotlin:common.bzl", "common") -load("//kotlin:jvm_compile.bzl", "kt_jvm_compile") -load("//kotlin:traverse_exports.bzl", "kt_traverse_exports") -load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules") -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") - -visibility(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", - ) - kt_testing_rules.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, - ) - kt_testing_rules.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, - ) - - kt_testing_rules.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/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/jvm/analysis/jvm_compile/r_java/Input.java b/tests/jvm/analysis/jvm_compile/r_java/Input.java new file mode 100644 index 0000000..e675bc1 --- /dev/null +++ b/tests/jvm/analysis/jvm_compile/r_java/Input.java @@ -0,0 +1,16 @@ +/* + * * 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/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"), + ], + ), +) -- cgit v1.2.3