summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lint_tests/lint_tutil.py19
-rw-r--r--tests/lint_tests/test_lint_dctrl.py244
2 files changed, 261 insertions, 2 deletions
diff --git a/tests/lint_tests/lint_tutil.py b/tests/lint_tests/lint_tutil.py
index 267f669..74e08db 100644
--- a/tests/lint_tests/lint_tutil.py
+++ b/tests/lint_tests/lint_tutil.py
@@ -1,5 +1,5 @@
import collections
-from typing import List, Optional, Mapping, Any, Callable
+from typing import List, Optional, Mapping, Any, Callable, Sequence
import pytest
@@ -13,7 +13,7 @@ from debputy.lsp.style_prefs import StylePreferenceTable, EffectivePreference
from debputy.packages import DctrlParser
from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
-from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity
+from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity, Range
try:
@@ -108,3 +108,18 @@ def group_diagnostics_by_severity(
by_severity[severity].append(diagnostic)
return by_severity
+
+
+def diag_range_to_text(lines: Sequence[str], range_: "Range") -> str:
+ parts = []
+ for line_no in range(range_.start.line, range_.end.line + 1):
+ line = lines[line_no]
+ chunk = line
+ if line_no == range_.start.line and line_no == range_.end.line:
+ chunk = line[range_.start.character : range_.end.character]
+ elif line_no == range_.start.line:
+ chunk = line[range_.start.character :]
+ elif line_no == range_.end.line:
+ chunk = line[: range_.end.character]
+ parts.append(chunk)
+ return "".join(parts)
diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py
index 840fabe..80d7525 100644
--- a/tests/lint_tests/test_lint_dctrl.py
+++ b/tests/lint_tests/test_lint_dctrl.py
@@ -13,6 +13,7 @@ from lint_tests.lint_tutil import (
group_diagnostics_by_severity,
requires_levenshtein,
LintWrapper,
+ diag_range_to_text,
)
from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity
@@ -965,3 +966,246 @@ def test_dctrl_lint_stem_typo_pkgfile_ignored_exts_or_files(
"./debian/foo.intsall",
"debian/foo.intsall",
)
+
+
+def test_dctrl_lint_dep_field_missing_sep(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ Depends: bar, baz
+ # Missing separator between baz and libfubar1
+ libfubar1,
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ issue = diagnostics[0]
+ msg = (
+ "Trailing data after a relationship that might be a second relationship."
+ " Is a separator missing before this part?"
+ )
+ problem_text = diag_range_to_text(lines, issue.range)
+ assert issue.message == msg
+ assert problem_text == "libfubar1"
+ assert f"{issue.range}" == "11:1-11:10"
+ assert issue.severity == DiagnosticSeverity.Error
+
+
+def test_dctrl_lint_dep_field_missing_sep_or_syntax_error(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ Depends: bar, baz
+ # Missing separator between baz and libfubar1
+ _libfubar1,
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ issue = diagnostics[0]
+ msg = "Parse error of the relationship. Either a syntax error or a missing separator somewhere."
+ problem_text = diag_range_to_text(lines, issue.range)
+ assert issue.message == msg
+ assert problem_text == "_libfubar1"
+ assert f"{issue.range}" == "11:1-11:11"
+ assert issue.severity == DiagnosticSeverity.Error
+
+
+def test_dctrl_lint_dep_field_completely_busted(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ Depends: bar, baz, _asd
+ # This is just busted
+ _libfubar1,
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ issue = diagnostics[0]
+ msg = 'Could not parse "_asd _libfubar1" as a dependency relation.'
+ problem_text = diag_range_to_text(lines, issue.range)
+ expected_problem_text = "\n".join((" _asd", "# This is just busted", " _libfubar1"))
+ assert issue.message == msg
+ assert problem_text == expected_problem_text
+ assert f"{issue.range}" == "9:18-11:11"
+ assert issue.severity == DiagnosticSeverity.Error
+
+
+def test_dctrl_lint_dep_field_completely_busted_first_line(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ # A wild field comment appeared!
+ Depends: _bar,
+ asd,
+ # This is fine (but the _bar part is not)
+ libfubar1,
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ issue = diagnostics[0]
+ msg = 'Could not parse "_bar" as a dependency relation.'
+ problem_text = diag_range_to_text(lines, issue.range)
+ assert issue.message == msg
+ assert problem_text == " _bar"
+ assert f"{issue.range}" == "10:8-10:13"
+ assert issue.severity == DiagnosticSeverity.Error
+
+
+def test_dctrl_lint_dep_field_restricted_operator(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ # Some random field comment
+ Provides: bar (>= 2),
+ bar
+ # Inline comment to spice up things
+ (<= 1),
+ # This one is valid
+ fubar (= 2),
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 2
+ first_issue, second_issue = diagnostics
+
+ msg = 'The version operator ">=" is not allowed in Provides'
+ problem_text = diag_range_to_text(lines, first_issue.range)
+ assert first_issue.message == msg
+ assert problem_text == ">="
+ assert f"{first_issue.range}" == "10:15-10:17"
+ assert first_issue.severity == DiagnosticSeverity.Error
+
+ msg = 'The version operator "<=" is not allowed in Provides'
+ problem_text = diag_range_to_text(lines, second_issue.range)
+ assert second_issue.message == msg
+ assert problem_text == "<="
+ assert f"{second_issue.range}" == "13:2-13:4"
+ assert second_issue.severity == DiagnosticSeverity.Error
+
+
+def test_dctrl_lint_dep_field_restricted_or_relations(
+ line_linter: LintWrapper,
+) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {CURRENT_STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ Depends: pkg-a
+ | pkg-b
+ # What goes in Depends do not always work in Provides
+ Provides: foo-a
+ | foo-b
+ Description: some short synopsis
+ A very interesting description
+ with a valid synopsis
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ issue = diagnostics[0]
+
+ msg = 'The field Provides does not support "|" (OR) in relations.'
+ problem_text = diag_range_to_text(lines, issue.range)
+ assert issue.message == msg
+ assert problem_text == "|"
+ assert f"{issue.range}" == "13:1-13:2"
+ assert issue.severity == DiagnosticSeverity.Error