зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1740799 - Add android-format lint test. r=nalexander,linter-reviewers,sylvestre
To run unit test for android-format lint, we have to add another simple Gradle project. It is runs with specific parameter (`androidFormatLintTest`), so `./mach build` etc doesn't run it. Also `type:global`'s lint doesn't have any test framework, so I will add it. Differential Revision: https://phabricator.services.mozilla.com/D162181
This commit is contained in:
Родитель
1756e8266e
Коммит
fa9e8b41cc
|
@ -64,6 +64,11 @@ project(':test_runner').projectDir = new File("${json.topsrcdir}/mobile/android/
|
|||
project(':exoplayer2').projectDir = new File("${json.topsrcdir}/mobile/android/exoplayer2")
|
||||
project(':omnijar').projectDir = new File("${json.topsrcdir}/mobile/android/app/omnijar")
|
||||
|
||||
if (hasProperty("androidFormatLintTest")) {
|
||||
include ':androidFormatLintTest'
|
||||
project(':androidFormatLintTest').projectDir = new File("${json.topsrcdir}/tools/lint/test/files/android-format")
|
||||
}
|
||||
|
||||
// The Gradle instance is shared between settings.gradle and all the
|
||||
// other build.gradle files (see
|
||||
// http://forums.gradle.org/gradle/topics/define_extension_properties_from_settings_xml).
|
||||
|
|
|
@ -200,6 +200,43 @@ def structuredlog_lint(config, root, logger=None):
|
|||
return wrapper
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def global_lint(config, root, request):
|
||||
try:
|
||||
func = findobject(config["payload"])
|
||||
except (ImportError, ValueError):
|
||||
pytest.fail(
|
||||
"could not resolve a lint function from '{}'".format(config["payload"])
|
||||
)
|
||||
|
||||
ResultSummary.root = root
|
||||
|
||||
def wrapper(config=config, root=root, collapse_results=False, **lintargs):
|
||||
logger.setLevel(logging.DEBUG)
|
||||
lintargs["log"] = logging.LoggerAdapter(
|
||||
logger, {"lintname": config.get("name"), "pid": os.getpid()}
|
||||
)
|
||||
results = func(config, root=root, **lintargs)
|
||||
if hasattr(request.module, "fixed") and isinstance(results, dict):
|
||||
request.module.fixed += results["fixed"]
|
||||
|
||||
if isinstance(results, dict):
|
||||
results = results["results"]
|
||||
|
||||
if isinstance(results, (list, tuple)):
|
||||
results = sorted(results)
|
||||
|
||||
if not collapse_results:
|
||||
return results
|
||||
|
||||
ret = defaultdict(list)
|
||||
for r in results:
|
||||
ret[r.relpath].append(r)
|
||||
return ret
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def create_temp_file(tmpdir):
|
||||
def inner(contents, name=None):
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package org.mozilla.geckoview;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Bad {
|
||||
public static void main() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.mozilla.geckoview
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
fun main() {
|
||||
println("Hello")
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
buildDir "${topobjdir}/gradle/build/tools/lint/test/files/android-format"
|
|
@ -1,6 +1,7 @@
|
|||
[DEFAULT]
|
||||
subsuite = mozlint
|
||||
|
||||
[test_android_format.py]
|
||||
[test_black.py]
|
||||
requirements = tools/lint/python/black_requirements.txt
|
||||
[test_clang_format.py]
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import mozunit
|
||||
from conftest import build
|
||||
|
||||
LINTER = "android-format"
|
||||
|
||||
|
||||
def test_basic(global_lint, config):
|
||||
substs = {
|
||||
"GRADLE_ANDROID_FORMAT_LINT_CHECK_TASKS": [
|
||||
"spotlessJavaCheck",
|
||||
"spotlessKotlinCheck",
|
||||
],
|
||||
"GRADLE_ANDROID_FORMAT_LINT_FIX_TASKS": [
|
||||
"spotlessJavaApply",
|
||||
"spotlessKotlinApply",
|
||||
],
|
||||
"GRADLE_ANDROID_FORMAT_LINT_FOLDERS": ["tools/lint/test/files/android-format"],
|
||||
}
|
||||
results = global_lint(
|
||||
config=config,
|
||||
topobjdir=build.topobjdir,
|
||||
root=build.topsrcdir,
|
||||
substs=substs,
|
||||
extra_args=["-PandroidFormatLintTest"],
|
||||
)
|
||||
print(results)
|
||||
|
||||
# When first task (spotlessJavaCheck) hits error, we won't check next Kotlin error.
|
||||
# So results length will be 1.
|
||||
assert len(results) == 1
|
||||
assert results[0].level == "error"
|
||||
|
||||
# Since android-format is global lint, fix=True overrides repository files directly.
|
||||
# No way to add this test.
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mozunit.main()
|
Загрузка…
Ссылка в новой задаче