Coverage for tests / integration / tools / shellcheck / test_options.py: 100%
31 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for ShellcheckPlugin options and configuration.
3These tests verify the set_options method and option validation.
4"""
6from __future__ import annotations
8import shutil
9from collections.abc import Callable
10from typing import TYPE_CHECKING
12import pytest
13from assertpy import assert_that
15if TYPE_CHECKING:
16 from lintro.plugins.base import BaseToolPlugin
18pytestmark = pytest.mark.skipif(
19 shutil.which("shellcheck") is None,
20 reason="shellcheck not installed",
21)
24@pytest.mark.parametrize(
25 ("option_name", "option_value"),
26 [
27 ("severity", "error"),
28 ("severity", "warning"),
29 ("severity", "info"),
30 ("severity", "style"),
31 ("shell", "bash"),
32 ("shell", "sh"),
33 ("exclude", ["SC2086"]),
34 ("exclude", ["SC2086", "SC2046"]),
35 ],
36 ids=[
37 "severity_error",
38 "severity_warning",
39 "severity_info",
40 "severity_style",
41 "shell_bash",
42 "shell_sh",
43 "exclude_single",
44 "exclude_multiple",
45 ],
46)
47def test_check_with_options(
48 get_plugin: Callable[[str], BaseToolPlugin],
49 shellcheck_violation_file: str,
50 option_name: str,
51 option_value: object,
52) -> None:
53 """Verify ShellCheck check works with various configuration options.
55 Args:
56 get_plugin: Fixture factory to get plugin instances.
57 shellcheck_violation_file: Path to file with lint issues.
58 option_name: Name of the option to set.
59 option_value: Value to set for the option.
60 """
61 shellcheck_plugin = get_plugin("shellcheck")
62 shellcheck_plugin.set_options(**{option_name: option_value})
63 result = shellcheck_plugin.check([shellcheck_violation_file], {})
65 assert_that(result).is_not_none()
66 assert_that(result.name).is_equal_to("shellcheck")
69@pytest.mark.parametrize(
70 ("option_name", "option_value", "expected"),
71 [
72 ("severity", "error", "error"),
73 ("severity", "warning", "warning"),
74 ("severity", "info", "info"),
75 ("severity", "style", "style"),
76 ("shell", "bash", "bash"),
77 ("shell", "sh", "sh"),
78 ("exclude", ["SC2086"], ["SC2086"]),
79 ("exclude", ["SC2086", "SC2046"], ["SC2086", "SC2046"]),
80 ],
81 ids=[
82 "severity_error",
83 "severity_warning",
84 "severity_info",
85 "severity_style",
86 "shell_bash",
87 "shell_sh",
88 "exclude_single",
89 "exclude_multiple",
90 ],
91)
92def test_set_options(
93 get_plugin: Callable[[str], BaseToolPlugin],
94 option_name: str,
95 option_value: object,
96 expected: object,
97) -> None:
98 """Verify ShellcheckPlugin.set_options correctly sets various options.
100 Args:
101 get_plugin: Fixture factory to get plugin instances.
102 option_name: Name of the option to set.
103 option_value: Value to set for the option.
104 expected: Expected value when retrieving the option.
105 """
106 shellcheck_plugin = get_plugin("shellcheck")
107 shellcheck_plugin.set_options(**{option_name: option_value})
108 assert_that(shellcheck_plugin.options.get(option_name)).is_equal_to(expected)
111def test_invalid_severity(
112 get_plugin: Callable[[str], BaseToolPlugin],
113) -> None:
114 """Verify ShellcheckPlugin.set_options rejects invalid severity values.
116 Args:
117 get_plugin: Fixture factory to get plugin instances.
118 """
119 shellcheck_plugin = get_plugin("shellcheck")
120 with pytest.raises(ValueError, match="Invalid severity level"):
121 shellcheck_plugin.set_options(severity="invalid")
124def test_invalid_shell(
125 get_plugin: Callable[[str], BaseToolPlugin],
126) -> None:
127 """Verify ShellcheckPlugin.set_options rejects invalid shell values.
129 Args:
130 get_plugin: Fixture factory to get plugin instances.
131 """
132 shellcheck_plugin = get_plugin("shellcheck")
133 with pytest.raises(ValueError, match="Invalid shell dialect"):
134 shellcheck_plugin.set_options(shell="invalid") # nosec B604
137def test_fix_raises_not_implemented(
138 get_plugin: Callable[[str], BaseToolPlugin],
139 shellcheck_violation_file: str,
140) -> None:
141 """Verify ShellCheck fix raises NotImplementedError.
143 ShellCheck cannot automatically fix issues, so calling fix should
144 raise NotImplementedError.
146 Args:
147 get_plugin: Fixture factory to get plugin instances.
148 shellcheck_violation_file: Path to file with lint issues.
149 """
150 shellcheck_plugin = get_plugin("shellcheck")
151 with pytest.raises(NotImplementedError, match="cannot automatically fix"):
152 shellcheck_plugin.fix([shellcheck_violation_file], {})