diff options
Diffstat (limited to 'tests/lint_tests/test_lint_dctrl.py')
-rw-r--r-- | tests/lint_tests/test_lint_dctrl.py | 265 |
1 files changed, 255 insertions, 10 deletions
diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py index bcb1613..7e9477e 100644 --- a/tests/lint_tests/test_lint_dctrl.py +++ b/tests/lint_tests/test_lint_dctrl.py @@ -4,6 +4,7 @@ from typing import List, Optional import pytest from debputy.lsp.lsp_debian_control import _lint_debian_control +from debputy.lsp.lsp_debian_control_reference_data import CURRENT_STANDARDS_VERSION from debputy.packages import DctrlParser from debputy.plugin.api.feature_set import PluginProvidedFeatureSet from lint_tests.lint_tutil import ( @@ -18,9 +19,6 @@ except ImportError: pass -STANDARDS_VERSION = "4.7.0" - - class DctrlLintWrapper(LintWrapper): def __call__(self, lines: List[str]) -> Optional[List["Diagnostic"]]: @@ -104,7 +102,7 @@ def test_dctrl_lint_typos(line_linter: LintWrapper) -> None: lines = textwrap.dedent( f"""\ Source: foo - Standards-Version: {STANDARDS_VERSION} + Standards-Version: {CURRENT_STANDARDS_VERSION} Priority: optional Section: devel Maintainer: Jane Developer <jane@example.com> @@ -137,7 +135,7 @@ def test_dctrl_lint_mx_value_with_typo(line_linter: LintWrapper) -> None: lines = textwrap.dedent( f"""\ Source: foo - Standards-Version: {STANDARDS_VERSION} + Standards-Version: {CURRENT_STANDARDS_VERSION} Priority: optional Section: devel Maintainer: Jane Developer <jane@example.com> @@ -176,7 +174,7 @@ def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None: lines = textwrap.dedent( f"""\ Source: foo - Standards-Version: {STANDARDS_VERSION} + Standards-Version: {CURRENT_STANDARDS_VERSION} Priority: optional Section: devel Maintainer: Jane Developer <jane@example.com> @@ -205,7 +203,7 @@ def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None: lines = textwrap.dedent( f"""\ Source: foo - Standards-Version: {STANDARDS_VERSION} + Standards-Version: {CURRENT_STANDARDS_VERSION} Priority: optional Section: devel Maintainer: Jane Developer <jane@example.com> @@ -238,14 +236,14 @@ def test_dctrl_lint_dup_sep(line_linter: LintWrapper) -> None: Source: foo Section: devel Priority: optional - Standards-Version: {STANDARDS_VERSION} + Standards-Version: {CURRENT_STANDARDS_VERSION} Maintainer: Jane Developer <jane@example.com> Build-Depends: debhelper-compat (= 13) Package: foo Architecture: all - Depends: foo, - , bar + Depends: bar, + , baz Description: Some very interesting synopsis A very interesting description that spans multiple lines @@ -263,3 +261,250 @@ def test_dctrl_lint_dup_sep(line_linter: LintWrapper) -> None: assert error.message == msg assert f"{error.range}" == "10:1-10:2" assert error.severity == DiagnosticSeverity.Error + + +def test_dctrl_lint_ma(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 + Multi-Arch: same + Depends: bar, baz + 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 + error = diagnostics[0] + + msg = "Multi-Arch: same is not valid for Architecture: all packages. Maybe you want foreign?" + assert error.message == msg + assert f"{error.range}" == "9:12-9:16" + assert error.severity == DiagnosticSeverity.Error + + +def test_dctrl_lint_udeb(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 + XB-Installer-Menu-Item: 1234 + Depends: bar, baz + Description: Some very interesting synopsis + A very interesting description + that spans multiple lines + . + Just so be clear, this is for a test. + + Package: bar-udeb + Architecture: all + Section: debian-installer + Package-Type: udeb + XB-Installer-Menu-Item: golf + 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) == 2 + first, second = diagnostics + + msg = "The XB-Installer-Menu-Item field is only applicable to udeb packages (`Package-Type: udeb`)" + assert first.message == msg + assert f"{first.range}" == "9:0-9:22" + assert first.severity == DiagnosticSeverity.Warning + + msg = r'The value "golf" does not match the regex ^[1-9]\d{3,4}$.' + assert second.message == msg + assert f"{second.range}" == "21:24-21:28" + assert second.severity == DiagnosticSeverity.Error + + +def test_dctrl_lint_arch_only_fields(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 + X-DH-Build-For-Type: target + Depends: bar, baz + 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 + issue = diagnostics[0] + + msg = "The X-DH-Build-For-Type field is not applicable to arch:all packages (`Architecture: all`)" + assert issue.message == msg + assert f"{issue.range}" == "9:0-9:19" + assert issue.severity == DiagnosticSeverity.Warning + + +def test_dctrl_lint_sv(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: 4.6.2 + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + 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 + issue = diagnostics[0] + + msg = f"Latest Standards-Version is {CURRENT_STANDARDS_VERSION}" + assert issue.message == msg + assert f"{issue.range}" == "3:19-3:24" + assert issue.severity == DiagnosticSeverity.Information + + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: Golf + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + 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 + issue = diagnostics[0] + + msg = f'Not a valid version. Current version is "{CURRENT_STANDARDS_VERSION}"' + assert issue.message == msg + assert f"{issue.range}" == "3:19-3:23" + assert issue.severity == DiagnosticSeverity.Warning + + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION}.0 + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + 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 + issue = diagnostics[0] + + msg = "Unnecessary version segment. This part of the version is only used for editorial changes" + assert issue.message == msg + assert f"{issue.range}" == "3:24-3:26" + assert issue.severity == DiagnosticSeverity.Information + + +def test_dctrl_lint_multiple_vcs(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) + Vcs-Git: https://salsa.debian.org/debian/foo + Vcs-Svn: https://svn.debian.org/debian/foo + Vcs-Browser: https://salsa.debian.org/debian/foo + + Package: foo + Architecture: all + Depends: bar, baz + 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) == 2 + first_issue, second_issue = diagnostics + + msg = f'Multiple Version Control fields defined ("Vcs-Git")' + assert first_issue.message == msg + assert f"{first_issue.range}" == "6:0-7:0" + assert first_issue.severity == DiagnosticSeverity.Warning + + msg = f'Multiple Version Control fields defined ("Vcs-Svn")' + assert second_issue.message == msg + assert f"{second_issue.range}" == "7:0-8:0" + assert second_issue.severity == DiagnosticSeverity.Warning |