From 8b8344c3982326d9c9b99e7bca8e667746b77691 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 17 Jun 2024 18:40:52 +0200 Subject: Merging upstream version 0.1.37. Signed-off-by: Daniel Baumann --- tests/lint_tests/test_lint_dcpy.py | 26 +++++++ tests/lint_tests/test_lint_dctrl.py | 143 ++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) (limited to 'tests/lint_tests') diff --git a/tests/lint_tests/test_lint_dcpy.py b/tests/lint_tests/test_lint_dcpy.py index 9b89b67..ac16022 100644 --- a/tests/lint_tests/test_lint_dcpy.py +++ b/tests/lint_tests/test_lint_dcpy.py @@ -5,6 +5,7 @@ import pytest from debputy.lsp.lsp_debian_copyright import _lint_debian_copyright from debputy.packages import DctrlParser from debputy.plugin.api.feature_set import PluginProvidedFeatureSet +from debputy.plugin.api.test_api import build_virtual_file_system from lint_tests.lint_tutil import ( group_diagnostics_by_severity, LintWrapper, @@ -59,3 +60,28 @@ def test_dcpy_files_lint(line_linter: LintWrapper) -> None: msg = 'Simplify to a single "/"' assert second_warn.message == msg assert f"{second_warn.range}" == "2:25-2:28" + + +def test_dcpy_files_matches_dir_lint(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + """\ + Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ + + Files: foo + Copyright: Noone + License: something + yada yada yada + """ + ).splitlines(keepends=True) + + source_root = build_virtual_file_system(["./foo/bar"]) + line_linter.source_root = source_root + + diagnostics = line_linter(lines) + assert len(diagnostics) == 1 + issue = diagnostics[0] + + msg = "Directories cannot be a match. Use `dir/*` to match everything in it" + assert issue.message == msg + assert f"{issue.range}" == "2:7-2:10" + assert issue.severity == DiagnosticSeverity.Warning diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py index 6479886..745c323 100644 --- a/tests/lint_tests/test_lint_dctrl.py +++ b/tests/lint_tests/test_lint_dctrl.py @@ -6,7 +6,9 @@ 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 import virtual_path_def from debputy.plugin.api.feature_set import PluginProvidedFeatureSet +from debputy.plugin.api.test_api import build_virtual_file_system from lint_tests.lint_tutil import ( group_diagnostics_by_severity, requires_levenshtein, @@ -14,6 +16,7 @@ from lint_tests.lint_tutil import ( ) from debputy.lsprotocol.types import Diagnostic, DiagnosticSeverity +from tutil import build_time_only class DctrlLintWrapper(LintWrapper): @@ -703,3 +706,143 @@ def test_dctrl_lint_synopsis_too_short(line_linter: LintWrapper) -> None: assert issue.message == msg assert f"{issue.range}" == "10:13-10:18" assert issue.severity == DiagnosticSeverity.Warning + + +@build_time_only +def test_dctrl_lint_ambiguous_pkgfile(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: some short synopsis + A very interesting description + with a valid synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + # FIXME: This relies on "cwd" being a valid debian directory using debhelper. Fix and + # remove the `build_time_only` restriction + line_linter.source_root = build_virtual_file_system(["./debian/bar.install"]) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 1 + issue = diagnostics[0] + + msg = ( + 'Possible typo in "./debian/bar.install". Consider renaming the file to "debian/foo.bar.install"' + ' or "debian/foo.install if it is intended for foo' + ) + assert issue.message == msg + assert f"{issue.range}" == "7:0-8:0" + assert issue.severity == DiagnosticSeverity.Warning + diag_data = issue.data + assert isinstance(diag_data, dict) + assert diag_data.get("report_for_related_file") in ( + "./debian/bar.install", + "debian/bar.install", + ) + + +@requires_levenshtein +@build_time_only +def test_dctrl_lint_stem_typo_pkgfile(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: some short synopsis + A very interesting description + with a valid synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + # FIXME: This relies on "cwd" being a valid debian directory using debhelper. Fix and + # remove the `build_time_only` restriction + line_linter.source_root = build_virtual_file_system(["./debian/foo.intsall"]) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 1 + issue = diagnostics[0] + + msg = 'The file "./debian/foo.intsall" is likely a typo of "./debian/foo.install"' + assert issue.message == msg + assert f"{issue.range}" == "7:0-8:0" + assert issue.severity == DiagnosticSeverity.Warning + diag_data = issue.data + assert isinstance(diag_data, dict) + assert diag_data.get("report_for_related_file") in ( + "./debian/foo.intsall", + "debian/foo.intsall", + ) + + +@build_time_only +def test_dctrl_lint_stem_inactive_pkgfile_fp(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer + Build-Depends: debhelper-compat (= 13), dh-sequence-zz-debputy, + + Package: foo + Architecture: all + Depends: bar, baz + Description: some short synopsis + A very interesting description + with a valid synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + # FIXME: This relies on "cwd" being a valid debian directory using debhelper. Fix and + # remove the `build_time_only` restriction + # + # Note: The "positive" test of this one is missing; suspect because it cannot (reliably) + # load the `zz-debputy` sequence. + line_linter.source_root = build_virtual_file_system( + [ + "./debian/foo.install", + virtual_path_def( + "./debian/rules", + content=textwrap.dedent( + """\ + #! /usr/bin/make -f + + binary binary-arch binary-indep build build-arch build-indep clean: + foo $@ + """ + ), + ), + ] + ) + + diagnostics = line_linter(lines) + print(diagnostics) + # We should not emit diagnostics when the package is not using dh! + assert not diagnostics -- cgit v1.2.3