summaryrefslogtreecommitdiffstats
path: root/tests/lint_tests/test_lint_dctrl.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lint_tests/test_lint_dctrl.py')
-rw-r--r--tests/lint_tests/test_lint_dctrl.py143
1 files changed, 127 insertions, 16 deletions
diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py
index cc2758e..e9a5756 100644
--- a/tests/lint_tests/test_lint_dctrl.py
+++ b/tests/lint_tests/test_lint_dctrl.py
@@ -1,14 +1,15 @@
import textwrap
-from typing import List, Optional, Callable
+from typing import List, Optional
import pytest
from debputy.lsp.lsp_debian_control import _lint_debian_control
+from debputy.packages import DctrlParser
+from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
from lint_tests.lint_tutil import (
- run_linter,
group_diagnostics_by_severity,
requires_levenshtein,
- exactly_one_diagnostic,
+ LintWrapper,
)
try:
@@ -17,20 +18,30 @@ except ImportError:
pass
-TestLinter = Callable[[List[str]], Optional[List["Diagnostic"]]]
+class DctrlLintWrapper(LintWrapper):
+ def __call__(self, lines: List[str]) -> Optional[List["Diagnostic"]]:
+ try:
+ self.dctrl_lines = lines
+ return super().__call__(lines)
+ finally:
+ self.dctrl_lines = None
-@pytest.fixture
-def line_linter() -> TestLinter:
- path = "/nowhere/debian/control"
-
- def _linter(lines: List[str]) -> Optional[List["Diagnostic"]]:
- return run_linter(path, lines, _lint_debian_control)
-
- return _linter
-
-def test_dctrl_lint(line_linter: TestLinter) -> None:
+@pytest.fixture
+def line_linter(
+ debputy_plugin_feature_set: PluginProvidedFeatureSet,
+ lint_dctrl_parser: DctrlParser,
+) -> LintWrapper:
+ return DctrlLintWrapper(
+ "/nowhere/debian/control",
+ _lint_debian_control,
+ debputy_plugin_feature_set,
+ lint_dctrl_parser,
+ )
+
+
+def test_dctrl_lint(line_linter: LintWrapper) -> None:
lines = textwrap.dedent(
"""\
Source: foo
@@ -86,7 +97,7 @@ def test_dctrl_lint(line_linter: TestLinter) -> None:
@requires_levenshtein
-def test_dctrl_lint_typos(line_linter: TestLinter) -> None:
+def test_dctrl_lint_typos(line_linter: LintWrapper) -> None:
lines = textwrap.dedent(
"""\
Source: foo
@@ -109,9 +120,109 @@ def test_dctrl_lint_typos(line_linter: TestLinter) -> None:
diagnostics = line_linter(lines)
print(diagnostics)
- diag = exactly_one_diagnostic(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ diag = diagnostics[0]
msg = 'The "Build-Dpends" looks like a typo of "Build-Depends".'
assert diag.message == msg
assert diag.severity == DiagnosticSeverity.Warning
assert f"{diag.range}" == "6:0-6:12"
+
+
+@requires_levenshtein
+def test_dctrl_lint_mx_value_with_typo(line_linter: LintWrapper) -> None:
+ lines = textwrap.dedent(
+ """\
+ Source: foo
+ Standards-Version: 4.5.2
+ Priority: optional
+ Section: devel
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ # Typo of `all`
+ Architecture: linux-any alle
+ Description: Some very interesting synopsis
+ A very interesting description
+ that spans multiple lines
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert len(diagnostics) == 2
+ by_severity = group_diagnostics_by_severity(diagnostics)
+ assert DiagnosticSeverity.Error in by_severity
+ assert DiagnosticSeverity.Warning in by_severity
+
+ typo_diag = by_severity[DiagnosticSeverity.Warning][0]
+ mx_diag = by_severity[DiagnosticSeverity.Error][0]
+ mx_msg = 'The value "all" cannot be used with other values.'
+ typo_msg = 'It is possible that the value is a typo of "all".'
+ assert mx_diag.message == mx_msg
+ assert typo_diag.message == typo_msg
+ assert f"{mx_diag.range}" == "10:24-10:28"
+ assert f"{typo_diag.range}" == "10:24-10:28"
+
+
+def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None:
+ lines = textwrap.dedent(
+ """\
+ Source: foo
+ Standards-Version: 4.5.2
+ Priority: optional
+ Section: devel
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all linux-any
+ Description: Some very interesting synopsis
+ A very interesting description
+ that spans multiple lines
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ diag = diagnostics[0]
+
+ msg = 'The value "all" cannot be used with other values.'
+ assert diag.message == msg
+ assert diag.severity == DiagnosticSeverity.Error
+ assert f"{diag.range}" == "8:14-8:17"
+
+ lines = textwrap.dedent(
+ """\
+ Source: foo
+ Standards-Version: 4.5.2
+ Priority: optional
+ Section: devel
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: linux-any any
+ Description: Some very interesting synopsis
+ A very interesting description
+ that spans multiple lines
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ diag = diagnostics[0]
+
+ msg = 'The value "any" cannot be used with other values.'
+ assert diag.message == msg
+ assert diag.severity == DiagnosticSeverity.Error
+ assert f"{diag.range}" == "8:24-8:27"