summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 16:40:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-17 16:40:52 +0000
commitede5a1f9cb549d56ff1f3b2a3f5437d13bd14444 (patch)
tree4cdbdc6bb5e78080f2c0a6e049b2146afeebd362 /tests
parentAdding upstream version 0.1.36. (diff)
downloaddebputy-ede5a1f9cb549d56ff1f3b2a3f5437d13bd14444.tar.xz
debputy-ede5a1f9cb549d56ff1f3b2a3f5437d13bd14444.zip
Adding upstream version 0.1.37.upstream/0.1.37
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/lint_tests/test_lint_dcpy.py26
-rw-r--r--tests/lint_tests/test_lint_dctrl.py143
-rw-r--r--tests/tutil.py12
3 files changed, 180 insertions, 1 deletions
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 <noone@example.com>
+ 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 <jane@example.com>
+ 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 <jane@example.com>
+ 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 <jane@example.com>
+ 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
diff --git a/tests/tutil.py b/tests/tutil.py
index 9b622b9..9c98d09 100644
--- a/tests/tutil.py
+++ b/tests/tutil.py
@@ -1,4 +1,6 @@
-from typing import Tuple, Mapping
+import pytest
+
+from typing import Tuple, Mapping, Any
from debian.deb822 import Deb822
from debian.debian_support import DpkgArchTable
@@ -8,6 +10,7 @@ from debputy.architecture_support import (
DpkgArchitectureBuildProcessValuesTable,
)
from debputy.packages import BinaryPackage
+from debputy.plugin.api.test_api import DEBPUTY_TEST_AGAINST_INSTALLED_PLUGINS
_DPKG_ARCHITECTURE_TABLE_NATIVE_AMD64 = None
_DPKG_ARCH_QUERY_TABLE = None
@@ -64,3 +67,10 @@ def _arch_data_tables_loaded() -> (
# TODO: Make a faked table instead, so we do not have data dependencies in the test.
_DPKG_ARCH_QUERY_TABLE = DpkgArchTable.load_arch_table()
return _DPKG_ARCHITECTURE_TABLE_NATIVE_AMD64, _DPKG_ARCH_QUERY_TABLE
+
+
+def build_time_only(func: Any) -> Any:
+ return pytest.mark.skipif(
+ DEBPUTY_TEST_AGAINST_INSTALLED_PLUGINS,
+ reason="Test makes assumptions only valid during build time tests",
+ )(func)