Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
e2e/
examples/
2 changes: 0 additions & 2 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ build --disk_cache=~/.cache/bazel
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
test --test_output=errors
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
test --test_env=XDG_CACHE_HOME
7 changes: 4 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
strategy: [local, worker]
bazel_version: ["8.x", "9.x"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -38,13 +39,13 @@ jobs:
- name: "Running tests //..."
env:
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
run: bazel test //...
run: bazel test //... --strategy=AndroidLint=${{ matrix.strategy }}
integration-tests:
strategy:
matrix:
os: [ubuntu-latest]
directory: [examples/simple-android]
strategy: [local, worker]
directory: [e2e/simple-android]
strategy: [worker]
bazel_version: ["8.x", "9.x"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ bazel-*
.idea/
.ijwb/
.aswb
MODULE.bazel.lock
MODULE.bazel.lock
30 changes: 29 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,39 @@ pre-commit install

Otherwise later tooling on CI will yell at you about formatting/linting violations.

## Testing

Run the complete repository test suite with:

```shell
bazel test //...
```

For a focused run of the lightweight unit and analysis tests, use:

```shell
bazel test //tests:unit_tests
```

The rule behavior tests under `tests/integration` are part of the normal suite. Run them directly
with:

```shell
bazel test //tests/integration:tests
```

The broader end-to-end test uses a standalone consumer workspace:

```shell
cd e2e/simple-android
bazel test //...
```

## Using this as a development dependency of other rules

You'll commonly find that you develop in another WORKSPACE, such as
some other ruleset that depends on rules_android_lint, or in a nested
WORKSPACE in the integration_tests folder.
WORKSPACE under the `e2e` directory.

To always tell Bazel to use this directory rather than some release
artifact or a version fetched from the internet, run this from this
Expand Down
12 changes: 1 addition & 11 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf"

bazel_dep(name = "aspect_bazel_lib", version = "2.22.5", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2", dev_dependency = True)
bazel_dep(name = "rules_bazel_integration_test", version = "0.37.1", dev_dependency = True)
bazel_dep(name = "rules_shell", version = "0.6.1", dev_dependency = True)

bazel_binaries = use_extension(
"@rules_bazel_integration_test//:extensions.bzl",
"bazel_binaries",
dev_dependency = True,
)
bazel_binaries.download(version_file = "//:.bazelversion")
use_repo(bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_.bazelversion")

android = use_extension(
"@hermetic_android_toolchains//:extensions.bzl",
Expand Down Expand Up @@ -94,7 +84,7 @@ maven_test.install(
artifacts = [
"org.assertj:assertj-core:3.24.2",
"junit:junit:4.13.2",
# Custom lint check used as a test fixture by //tests/scripts
# Custom lint check used by the top-level integration fixtures.
"com.slack.lint.compose:compose-lint-checks:1.5.2",
],
lock_file = "//:maven_install_test.json",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module(
name = "examples_simple",
name = "e2e_simple_android",
version = "TODO",
)

Expand Down
9 changes: 9 additions & 0 deletions e2e/simple-android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Simple Android end-to-end test

This standalone Bazel workspace verifies that a consumer can register the Android lint toolchain and use `android_lint` and `android_lint_test` with a real Android dependency. CI runs it with both local and worker execution strategies.

Run it from this directory:

```sh
bazel test //...
```
File renamed without changes.
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
],
"packageRules": [
{
"matchFileNames": [
"MODULE.bazel"
],
"matchFileNames": ["MODULE.bazel"],
"enabled": false
}
]
Expand Down
8 changes: 7 additions & 1 deletion src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")

py_library(
name = "android_lint_output_validator_lib",
srcs = ["android_lint_output_validator.py"],
visibility = ["//tests:__subpackages__"],
)

py_binary(
name = "android_lint_output_validator",
Expand Down
34 changes: 21 additions & 13 deletions src/android_lint_output_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
from typing import List
from xml.etree import ElementTree

def __validate_output(lint_baseline) -> int:

def validate_output(lint_baseline: str) -> int:
# Read in the lint baseline file
with open(lint_baseline, "r") as f:
output = f.read()

# Parse it into an actual array of issues
output_parsed = __parse_android_lint(output)
# Parse it into an actual array of issues. A missing or malformed report must
# fail the test rather than being mistaken for a clean lint result.
try:
output_parsed = parse_android_lint(output)
except (ElementTree.ParseError, ValueError) as error:
print(f"Unable to parse Android lint report {lint_baseline}: {error}", file=sys.stderr)
return 1

# Look at the flagged issues and categorize them
# issues - valid issues that need to be fixed or baselined
Expand All @@ -35,22 +41,24 @@ def __validate_output(lint_baseline) -> int:
return 0


def __parse_android_lint(input: str) -> List[Dict[str, Any]]:
def parse_android_lint(report: str) -> List[Dict[str, Any]]:
results = [] # type: List[Dict[str, Any]]

try:
root = ElementTree.fromstring(input)
except ElementTree.ParseError:
return results
root = ElementTree.fromstring(report)
if root.tag != "issues":
raise ValueError(f"expected <issues> root element, found <{root.tag}>")

for issue in root.findall("issue"):
issues = {"id": issue.get("id", None), "message": issue.get("message", None)}
results.append({k: v for k, v in issues.items() if v})
issue_id = issue.get("id")
message = issue.get("message")
if not issue_id or message is None:
raise ValueError("expected each <issue> to have id and message attributes")
results.append({"id": issue_id, "message": message})
return results


def __main(lint_baseline):
return __validate_output(lint_baseline=lint_baseline)
def main(lint_baseline: str) -> int:
return validate_output(lint_baseline=lint_baseline)


if __name__ == "__main__":
Expand All @@ -60,7 +68,7 @@ def __main(lint_baseline):
args = parser.parse_args(sys.argv[1:])

# Run it and exit with the proper exit code
exit_code = __main(
exit_code = main(
lint_baseline=args.lint_baseline,
)
sys.exit(exit_code)
19 changes: 16 additions & 3 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@ load(":versions_test.bzl", "versions_test_suite")
versions_test_suite(name = "versions_test")

test_suite(
name = "tests",
name = "unit_tests",
tests = [
":versions_test",
"//tests/scripts:android_lint_aar_scenarios_test",
"//tests/scripts:android_lint_scenarios_test",
"//tests/rules:tests",
"//tests/src:tests",
"//tests/src/cli:tests",
"//tests/src/worker:tests",
],
)

test_suite(
name = "rule_tests",
tests = ["//tests/integration:tests"],
)

test_suite(
name = "tests",
tests = [
":rule_tests",
":unit_tests",
],
)
13 changes: 0 additions & 13 deletions tests/bashunit/BUILD

This file was deleted.

Loading
Loading