From 1e5c28f36b0fd2d5ac1683c88d48e3d7c243e993 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 22:18:22 +0200 Subject: Adding upstream version 0.1.28. Signed-off-by: Daniel Baumann --- tests/lint_tests/test_lint_changelog.py | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/lint_tests/test_lint_changelog.py (limited to 'tests/lint_tests/test_lint_changelog.py') diff --git a/tests/lint_tests/test_lint_changelog.py b/tests/lint_tests/test_lint_changelog.py new file mode 100644 index 0000000..25dac0e --- /dev/null +++ b/tests/lint_tests/test_lint_changelog.py @@ -0,0 +1,90 @@ +import textwrap +from typing import List, Optional + +import pytest + +from debputy.lsp.lsp_debian_changelog import _lint_debian_changelog +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 ( + group_diagnostics_by_severity, + requires_levenshtein, + LintWrapper, +) + +try: + from lsprotocol.types import Diagnostic, DiagnosticSeverity +except ImportError: + pass + + +@pytest.fixture +def line_linter( + debputy_plugin_feature_set: PluginProvidedFeatureSet, + lint_dctrl_parser: DctrlParser, +) -> LintWrapper: + return LintWrapper( + "/nowhere/debian/changelog", + _lint_debian_changelog, + debputy_plugin_feature_set, + lint_dctrl_parser, + ) + + +def test_dctrl_lint(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + """\ + foo (0.2) unstable; urgency=medium + + * Renamed to foo + + -- Niels Thykier Mon, 08 Apr 2024 16:00:00 +0000 + + bar (0.2) unstable; urgency=medium + + * Initial release + + -- Niels Thykier Mon, 01 Apr 2024 00:00:00 +0000 + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + # Without a control file, this is fine + assert not diagnostics + + line_linter.dctrl_lines = textwrap.dedent( + """\ + Source: foo + + Package: something-else + """ + ) + + diagnostics = line_linter(lines) + print(diagnostics) + # Also fine, because d/control and d/changelog agrees + assert not diagnostics + + line_linter.dctrl_lines = textwrap.dedent( + """\ + Source: bar + + Package: something-else + """ + ) + + diagnostics = line_linter(lines) + print(diagnostics) + # This should be problematic though + assert diagnostics and len(diagnostics) == 1 + diag = diagnostics[0] + + msg = ( + "The first entry must use the same source name as debian/control." + ' Changelog uses: "foo" while d/control uses: "bar"' + ) + assert diag.severity == DiagnosticSeverity.Error + assert diag.message == msg + assert f"{diag.range}" == "0:0-0:3" -- cgit v1.2.3