Make sure Kotlin output is ktlint-compliant
This commit is contained in:
Родитель
7e978ca0ad
Коммит
c49bf7c6b8
|
@ -7,10 +7,14 @@ matrix:
|
|||
dist: xenial
|
||||
sudo: true
|
||||
|
||||
install: pip install -U tox-travis flake8
|
||||
install:
|
||||
- pip install -U tox-travis flake8
|
||||
- curl -sSLO https://github.com/shyiko/ktlint/releases/download/0.29.0/ktlint &&
|
||||
chmod a+x ktlint
|
||||
|
||||
# Command to run tests, e.g. python setup.py test
|
||||
script:
|
||||
- export PATH=.:$PATH
|
||||
- flake8 .
|
||||
- tox
|
||||
|
||||
|
|
|
@ -11,18 +11,17 @@ package GleanMetrics
|
|||
{% for metric_type in metric_types -%}
|
||||
import mozilla.components.service.glean.{{ metric_type|Camelize }}MetricType
|
||||
{% endfor %}
|
||||
|
||||
object {{ category_name|Camelize }} {
|
||||
{% for metric in metrics.values() %}
|
||||
{%- for metric in metrics.values() %}
|
||||
/**
|
||||
* {{ metric.description|wordwrap(wrapstring='\n * ') }}
|
||||
*/
|
||||
val {{ metric.name|camelize }}: {{ metric.type|Camelize }}MetricType by lazy {
|
||||
{{ metric.type|Camelize }}MetricType(
|
||||
{% for arg_name in extra_args if metric[arg_name] is defined -%}
|
||||
{{ arg_name|camelize }}={{ metric[arg_name]|kotlin }}{{ "," if not loop.last }}
|
||||
{{ arg_name|camelize }} = {{ metric[arg_name]|kotlin }}{{ "," if not loop.last }}
|
||||
{% endfor -%}
|
||||
)
|
||||
};
|
||||
{% endfor %}
|
||||
}
|
||||
{% endfor -%}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from glean_parser import kotlin
|
||||
from glean_parser import translate
|
||||
|
@ -15,10 +16,12 @@ ROOT = Path(__file__).parent
|
|||
|
||||
def test_parser(tmpdir):
|
||||
"""Test translating metrics to Kotlin files."""
|
||||
translate.translate(ROOT / "data" / "core.yaml", 'kotlin', Path(tmpdir))
|
||||
tmpdir = Path(tmpdir)
|
||||
|
||||
translate.translate(ROOT / "data" / "core.yaml", 'kotlin', tmpdir)
|
||||
|
||||
assert (
|
||||
set(os.listdir(tmpdir)) ==
|
||||
set(x.name for x in tmpdir.iterdir()) ==
|
||||
set(['CorePing.kt', 'Telemetry.kt', 'Environment.kt'])
|
||||
)
|
||||
|
||||
|
@ -32,6 +35,11 @@ def test_parser(tmpdir):
|
|||
content = fd.read()
|
||||
assert 'جمع 搜集' in content
|
||||
|
||||
# Only run this test if ktlint is on the path
|
||||
if shutil.which('ktlint'):
|
||||
for filepath in tmpdir.glob('*.kt'):
|
||||
subprocess.check_call(['ktlint', filepath])
|
||||
|
||||
|
||||
def test_kotlin_generator():
|
||||
kdf = kotlin.kotlin_datatypes_filter
|
||||
|
|
Загрузка…
Ссылка в новой задаче