Skip to content

Commit 1890534

Browse files
authored
Expand test coverage (#232)
* Expand test coverage * Clean up test function name
1 parent 9648569 commit 1890534

32 files changed

Lines changed: 274 additions & 226 deletions

File tree

.github/workflows/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ jobs:
6161
- name: "Configure Bazel"
6262
run: cp .github/workflows/ci.bazelrc .
6363
- name: "Unit tests"
64-
run: bazel test //...
64+
run: bazel test -- //... -//tests/integration/...
6565
integration-test:
6666
runs-on: ubuntu-latest
67+
strategy:
68+
matrix:
69+
detekt-strategy: [local, worker]
6770
steps:
6871
- name: "Checkout the sources"
6972
uses: actions/checkout@v7
@@ -83,5 +86,5 @@ jobs:
8386
uses: bazelbuild/setup-bazelisk@v3
8487
- name: "Configure Bazel"
8588
run: cp .github/workflows/ci.bazelrc .
86-
- name: "Integration tests"
87-
run: bash tests/integration/suite.sh
89+
- name: "Integration tests (${{ matrix.detekt-strategy }})"
90+
run: bazel test --strategy=Detekt=${{ matrix.detekt-strategy }} --disk_cache= --cache_test_results=no //tests/integration/...

tests/integration/BUILD

Lines changed: 87 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,104 @@
1-
load("//detekt:defs.bzl", "detekt")
1+
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
2+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
3+
load("//detekt:defs.bzl", "detekt_test")
24

3-
filegroup(
4-
name = "detekt_config_lenient",
5-
srcs = ["detekt_config_lenient.yml"],
6-
tags = ["manual"],
5+
detekt_test(
6+
name = "jvm_static_analysis_test",
7+
srcs = ["//tests/integration/testFixtures/basic-jvm:jvm_static_srcs"],
78
)
89

9-
detekt(
10-
name = "detekt_without_config",
11-
srcs = glob(["src/main/kotlin/**/*.kt"]),
12-
tags = ["manual"],
10+
detekt_test(
11+
name = "jvm_classpath_analysis_test",
12+
srcs = ["//tests/integration/testFixtures/basic-jvm:jvm_classpath_srcs"],
13+
base_path = ".",
14+
cfgs = ["detekt_type_resolution.yml"],
15+
max_issues = 2,
16+
xml_report = True,
17+
deps = ["//tests/integration/testFixtures/basic-jvm:jvm_api"],
18+
)
19+
20+
detekt_test(
21+
name = "android_static_analysis_test",
22+
srcs = ["//tests/integration/testFixtures/basic-android:android_static_srcs"],
1323
)
1424

15-
detekt(
16-
name = "detekt_without_config_with_report_html",
17-
srcs = glob(["src/main/kotlin/**/*.kt"]),
18-
html_report = True,
19-
tags = ["manual"],
25+
detekt_test(
26+
name = "android_classpath_analysis_test",
27+
srcs = ["//tests/integration/testFixtures/basic-android:android_classpath_srcs"],
28+
base_path = ".",
29+
cfgs = ["detekt_type_resolution.yml"],
30+
is_android = True,
31+
max_issues = 2,
32+
xml_report = True,
33+
deps = ["//tests/integration/testFixtures/basic-android:android_api"],
2034
)
2135

22-
detekt(
23-
name = "detekt_without_config_with_report_xml",
24-
srcs = glob(["src/main/kotlin/**/*.kt"]),
25-
tags = ["manual"],
36+
detekt_test(
37+
name = "custom_rule_analysis_test",
38+
srcs = ["//tests/integration/testFixtures/custom-rule:custom_rule_violation_srcs"],
39+
base_path = ".",
40+
cfgs = ["//tests/integration/testFixtures/custom-rule:custom_rule_config"],
41+
max_issues = 1,
42+
plugins = ["//tests/integration/testFixtures/custom-rule:custom_rules"],
2643
xml_report = True,
2744
)
2845

29-
detekt(
30-
name = "detekt_without_config_with_baseline",
31-
srcs = glob(["src/main/kotlin/**/*.kt"]),
32-
baseline = "detekt_baseline.xml",
33-
tags = ["manual"],
46+
JVM_CLASSPATH_REPORT_XML = """<?xml version="1.0" encoding="UTF-8"?>
47+
<checkstyle version="4.3">
48+
<file name="tests/integration/testFixtures/basic-jvm/src/jvm/tests/integration/jvm/JvmClasspath.kt">
49+
<error line="4" column="24" severity="warning" message="JvmApi.name()?.length contains an unnecessary safe call operator" source="detekt.UnnecessarySafeCall" />
50+
</file>
51+
</checkstyle>"""
52+
53+
write_file(
54+
name = "jvm_classpath_report",
55+
out = "jvm_classpath_report.xml",
56+
content = JVM_CLASSPATH_REPORT_XML.split("\n"),
57+
newline = "unix",
3458
)
3559

36-
detekt(
37-
name = "detekt_without_config_with_baseline_with_plugin",
38-
srcs = glob(["src/main/kotlin/**/*.kt"]),
39-
baseline = "detekt_baseline.xml",
40-
plugins = ["@rules_detekt_dependencies//:io_gitlab_arturbosch_detekt_detekt_formatting"],
41-
tags = ["manual"],
60+
diff_test(
61+
name = "jvm_classpath_report_test",
62+
file1 = ":jvm_classpath_report",
63+
file2 = ":jvm_classpath_analysis_test",
4264
)
4365

44-
detekt(
45-
name = "detekt_with_config_file_lenient",
46-
srcs = glob(["src/main/kotlin/**/*.kt"]),
47-
cfgs = ["detekt_config_lenient.yml"],
48-
tags = ["manual"],
66+
ANDROID_CLASSPATH_REPORT_XML = """<?xml version="1.0" encoding="UTF-8"?>
67+
<checkstyle version="4.3">
68+
<file name="tests/integration/testFixtures/basic-android/src/android/tests/integration/android/AndroidClasspath.kt">
69+
<error line="6" column="24" severity="warning" message="AndroidApi.packageName(context)?.length contains an unnecessary safe call operator" source="detekt.UnnecessarySafeCall" />
70+
</file>
71+
</checkstyle>"""
72+
73+
write_file(
74+
name = "android_classpath_report",
75+
out = "android_classpath_report.xml",
76+
content = ANDROID_CLASSPATH_REPORT_XML.split("\n"),
77+
newline = "unix",
78+
)
79+
80+
diff_test(
81+
name = "android_classpath_report_test",
82+
file1 = ":android_classpath_report",
83+
file2 = ":android_classpath_analysis_test",
84+
)
85+
86+
CUSTOM_RULE_REPORT_XML = """<?xml version="1.0" encoding="UTF-8"?>
87+
<checkstyle version="4.3">
88+
<file name="tests/integration/testFixtures/custom-rule/src/custom/tests/integration/custom/CustomRuleViolation.kt">
89+
<error line="1" column="1" severity="warning" message="customRuleViolation is forbidden." source="detekt.ForbiddenFunctionName" />
90+
</file>
91+
</checkstyle>"""
92+
93+
write_file(
94+
name = "custom_rule_report",
95+
out = "custom_rule_report.xml",
96+
content = CUSTOM_RULE_REPORT_XML.split("\n"),
97+
newline = "unix",
4998
)
5099

51-
detekt(
52-
name = "detekt_with_config_filegroup_lenient",
53-
srcs = glob(["src/main/kotlin/**/*.kt"]),
54-
cfgs = ["//tests/integration:detekt_config_lenient"],
55-
tags = ["manual"],
100+
diff_test(
101+
name = "custom_rule_report_test",
102+
file1 = ":custom_rule_report",
103+
file2 = ":custom_rule_analysis_test",
56104
)

tests/integration/detekt_baseline.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/integration/detekt_config_lenient.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
potential-bugs:
2+
UnnecessarySafeCall:
3+
active: true

tests/integration/src/main/kotlin/io/buildfoundation/bazel/detekt/A.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/integration/src/main/kotlin/io/buildfoundation/bazel/detekt/B.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/integration/src/main/kotlin/io/buildfoundation/bazel/detekt/C.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/integration/src/main/kotlin/io/buildfoundation/bazel/detekt/main.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/integration/suite.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)