Skip to content

Commit bdd4656

Browse files
authored
Add more integration tests (#117)
1 parent a9753c9 commit bdd4656

7 files changed

Lines changed: 341 additions & 4 deletions

File tree

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ maven_test.install(
6565
artifacts = [
6666
"org.assertj:assertj-core:3.24.2",
6767
"junit:junit:4.13.2",
68+
# Custom lint check used as a test fixture by //tests/scripts
69+
"com.slack.lint.compose:compose-lint-checks:1.5.2",
6870
],
6971
lock_file = "//:maven_install_test.json",
7072
repositories = [

maven_install_test.json

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": 278678914,
4-
"__RESOLVED_ARTIFACTS_HASH": 428393146,
3+
"__INPUT_ARTIFACTS_HASH": 1988574746,
4+
"__RESOLVED_ARTIFACTS_HASH": -626215935,
55
"artifacts": {
6+
"com.google.auto.service:auto-service-annotations": {
7+
"shasums": {
8+
"jar": "16a76dd00a2650568447f5d6e3a9e2c809d9a42367d56b45215cfb89731f4d24"
9+
},
10+
"version": "1.1.1"
11+
},
12+
"com.slack.lint.compose:compose-lint-checks": {
13+
"shasums": {
14+
"jar": "1ad367bbf4794c3b2f90420bc3dc97ba9a7fbbe5f7a4f995811071daca44bb0b"
15+
},
16+
"version": "1.5.2"
17+
},
618
"junit:junit": {
719
"shasums": {
820
"jar": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3"
@@ -29,6 +41,9 @@
2941
}
3042
},
3143
"dependencies": {
44+
"com.slack.lint.compose:compose-lint-checks": [
45+
"com.google.auto.service:auto-service-annotations"
46+
],
3247
"junit:junit": [
3348
"org.hamcrest:hamcrest-core"
3449
],
@@ -37,6 +52,27 @@
3752
]
3853
},
3954
"packages": {
55+
"com.google.auto.service:auto-service-annotations": [
56+
"com.google.auto.service"
57+
],
58+
"com.slack.lint.compose:compose-lint-checks": [
59+
"slack.lint.compose",
60+
"slack.lint.compose.shaded.kotlin.metadata",
61+
"slack.lint.compose.shaded.kotlin.metadata.internal",
62+
"slack.lint.compose.shaded.kotlin.metadata.internal.common",
63+
"slack.lint.compose.shaded.kotlin.metadata.internal.extensions",
64+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata",
65+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.builtins",
66+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.deserialization",
67+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm",
68+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm.deserialization",
69+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm.serialization",
70+
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.serialization",
71+
"slack.lint.compose.shaded.kotlin.metadata.internal.protobuf",
72+
"slack.lint.compose.shaded.kotlin.metadata.jvm",
73+
"slack.lint.compose.shaded.kotlin.metadata.jvm.internal",
74+
"slack.lint.compose.util"
75+
],
4076
"junit:junit": [
4177
"junit.extensions",
4278
"junit.framework",
@@ -148,18 +184,31 @@
148184
},
149185
"repositories": {
150186
"https://maven.google.com/": [
187+
"com.google.auto.service:auto-service-annotations",
188+
"com.slack.lint.compose:compose-lint-checks",
151189
"junit:junit",
152190
"net.bytebuddy:byte-buddy",
153191
"org.assertj:assertj-core",
154192
"org.hamcrest:hamcrest-core"
155193
],
156194
"https://repo1.maven.org/maven2/": [
195+
"com.google.auto.service:auto-service-annotations",
196+
"com.slack.lint.compose:compose-lint-checks",
157197
"junit:junit",
158198
"net.bytebuddy:byte-buddy",
159199
"org.assertj:assertj-core",
160200
"org.hamcrest:hamcrest-core"
161201
]
162202
},
163-
"services": {},
203+
"services": {
204+
"com.slack.lint.compose:compose-lint-checks": {
205+
"com.android.tools.lint.client.api.IssueRegistry": [
206+
"slack.lint.compose.ComposeLintsIssueRegistry"
207+
],
208+
"slack.lint.compose.shaded.kotlin.metadata.internal.extensions.MetadataExtensions": [
209+
"slack.lint.compose.shaded.kotlin.metadata.jvm.internal.JvmMetadataExtensions"
210+
]
211+
}
212+
},
164213
"version": "2"
165214
}

src/cli/AndroidLintRunner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class AndroidLintRunner(
2727
val aarLintRuleJars =
2828
args.classpathAarPairs
2929
.asSequence()
30-
.map { it.first.resolve("lint.jar") }
30+
.map { it.second.resolve("lint.jar") }
3131
.filter { it.exists() && it.isRegularFile() }
3232

3333
// Create the project configuration file for lint

tests/scripts/BUILD

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ load("@bazel_binaries//:defs.bzl", "bazel_binaries")
22
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "script_test")
33
load("@rules_shell//shell:sh_library.bzl", "sh_library")
44

5+
# Copies the compose-lint-checks jar to a stable runfiles path so the helper can
6+
# rlocation it without depending on rules_jvm_external's repository layout.
7+
genrule(
8+
name = "compose_lint_checks_jar",
9+
testonly = True,
10+
srcs = ["@rules_android_lint_test_deps//:com_slack_lint_compose_compose_lint_checks"],
11+
outs = ["compose_lint_checks.jar"],
12+
cmd = "cp $$(echo '$(SRCS)' | tr ' ' '\\n' | grep 'compose-lint-checks' | head -1) $@",
13+
)
14+
515
sh_library(
616
name = "lint_helper",
717
testonly = True,
818
srcs = ["lint_helper.sh"],
919
data = [
20+
":compose_lint_checks_jar",
1021
"//rules:all_files",
1122
"//src:all_files",
1223
"//src/cli:cli_deploy.jar",
@@ -27,3 +38,17 @@ script_test(
2738
"//tests/bashunit",
2839
],
2940
)
41+
42+
script_test(
43+
name = "android_lint_aar_scenarios_test",
44+
size = "enormous",
45+
srcs = ["android_lint_aar_scenarios_test.sh"],
46+
additional_env_inherit = ["ANDROID_HOME"],
47+
bazel_binaries = bazel_binaries,
48+
bazel_version = bazel_binaries.versions.current,
49+
tags = ["exclusive"],
50+
deps = [
51+
":lint_helper",
52+
"//tests/bashunit",
53+
],
54+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
#
3+
# Scenarios for custom lint checks embedded in AAR dependencies (lint.jar), exercising the
4+
# collect_aar_outputs_aspect extraction and auto-discovery path. Requires ANDROID_HOME.
5+
6+
# --- begin runfiles.bash initialization v2 ---
7+
# Copy-pasted from the Bazel Bash runfiles library v2.
8+
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
9+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
10+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
11+
source "$0.runfiles/$f" 2>/dev/null || \
12+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
13+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
14+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
15+
# --- end runfiles.bash initialization v2 ---
16+
17+
source "$(rlocation rules_android_lint/tests/bashunit/unittest.bash)" || \
18+
(echo >&2 "Failed to locate unittest.bash" && exit 1)
19+
20+
source "$(rlocation rules_android_lint/tests/scripts/lint_helper.sh)" || \
21+
(echo >&2 "Failed to locate lint_helper.sh" && exit 1)
22+
23+
function set_up() {
24+
rm -rf -- * .bazelrc 2>/dev/null || true
25+
set_up_lint_workspace
26+
enable_android_in_workspace
27+
}
28+
29+
function test_aar_embedded_lint_jar_flags_issue() {
30+
write_composable_annotation_stub
31+
write_dirty_composable
32+
write_fixture_aar
33+
write_aar_dep_lint_targets
34+
35+
"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
36+
&& fail "Expected lint test with AAR-embedded checks to fail" || true
37+
expect_log "ComposeNamingUppercase"
38+
}
39+
40+
function test_aar_embedded_lint_jar_accepts_clean_composable() {
41+
write_composable_annotation_stub
42+
write_clean_composable
43+
write_fixture_aar
44+
write_aar_dep_lint_targets
45+
46+
"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
47+
|| fail "Expected lint test with AAR-embedded checks to pass"
48+
}
49+
50+
run_suite "android_lint AAR lint.jar discovery scenarios"

tests/scripts/android_lint_scenarios_test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,25 @@ function test_worker_and_local_strategies_agree() {
116116
expect_log "DefaultLocale"
117117
}
118118

119+
function test_custom_rules_jar_flags_compose_issue() {
120+
write_composable_annotation_stub
121+
write_dirty_composable
122+
copy_compose_lint_checks
123+
write_custom_rules_lint_targets
124+
125+
"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
126+
&& fail "Expected lint test with custom compose-lints rules to fail" || true
127+
expect_log "ComposeNamingUppercase"
128+
}
129+
130+
function test_custom_rules_jar_accepts_clean_composable() {
131+
write_composable_annotation_stub
132+
write_clean_composable
133+
copy_compose_lint_checks
134+
write_custom_rules_lint_targets
135+
136+
"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
137+
|| fail "Expected lint test with custom compose-lints rules to pass"
138+
}
139+
119140
run_suite "android_lint rule behavior scenarios"

0 commit comments

Comments
 (0)