Coverage for tests / integration / tools / shellcheck / test_check.py: 100%
40 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 check command.
3These tests verify the check command works correctly on various inputs.
4"""
6from __future__ import annotations
8import shutil
9from collections.abc import Callable
10from pathlib import Path
11from typing import TYPE_CHECKING
13import pytest
14from assertpy import assert_that
16if TYPE_CHECKING:
17 from lintro.plugins.base import BaseToolPlugin
19pytestmark = pytest.mark.skipif(
20 shutil.which("shellcheck") is None,
21 reason="shellcheck not installed",
22)
25def test_check_file_with_issues(
26 get_plugin: Callable[[str], BaseToolPlugin],
27 shellcheck_violation_file: str,
28) -> None:
29 """Verify ShellCheck check detects lint issues in problematic files.
31 Args:
32 get_plugin: Fixture factory to get plugin instances.
33 shellcheck_violation_file: Path to file with lint issues.
34 """
35 shellcheck_plugin = get_plugin("shellcheck")
36 result = shellcheck_plugin.check([shellcheck_violation_file], {})
38 assert_that(result).is_not_none()
39 assert_that(result.name).is_equal_to("shellcheck")
40 assert_that(result.issues_count).is_greater_than(0)
43def test_check_clean_file(
44 get_plugin: Callable[[str], BaseToolPlugin],
45 shellcheck_clean_file: str,
46) -> None:
47 """Verify ShellCheck check passes on clean files.
49 Args:
50 get_plugin: Fixture factory to get plugin instances.
51 shellcheck_clean_file: Path to clean file.
52 """
53 shellcheck_plugin = get_plugin("shellcheck")
54 result = shellcheck_plugin.check([shellcheck_clean_file], {})
56 assert_that(result).is_not_none()
57 assert_that(result.name).is_equal_to("shellcheck")
58 assert_that(result.success).is_true()
61def test_check_empty_directory(
62 get_plugin: Callable[[str], BaseToolPlugin],
63 tmp_path: Path,
64) -> None:
65 """Verify ShellCheck check handles empty directories gracefully.
67 Args:
68 get_plugin: Fixture factory to get plugin instances.
69 tmp_path: Pytest fixture providing a temporary directory.
70 """
71 shellcheck_plugin = get_plugin("shellcheck")
72 result = shellcheck_plugin.check([str(tmp_path)], {})
74 assert_that(result).is_not_none()
75 assert_that(result.issues_count).is_equal_to(0)
78def test_check_severity_filters_issues(
79 get_plugin: Callable[[str], BaseToolPlugin],
80 shellcheck_style_issues_file: str,
81) -> None:
82 """Verify ShellCheck severity option filters issues appropriately.
84 Runs ShellCheck with error severity (strictest) and verifies fewer
85 issues are found than with style severity (least strict).
87 Args:
88 get_plugin: Fixture factory to get plugin instances.
89 shellcheck_style_issues_file: Path to file with style-level issues.
90 """
91 shellcheck_plugin = get_plugin("shellcheck")
93 # Check with style severity (default, reports all issues)
94 shellcheck_plugin.set_options(severity="style")
95 style_result = shellcheck_plugin.check([shellcheck_style_issues_file], {})
97 # Precondition: ensure we have issues to filter
98 assert_that(style_result.issues_count).is_greater_than(0)
100 # Check with error severity (strictest, reports only errors)
101 shellcheck_plugin.set_options(severity="error")
102 error_result = shellcheck_plugin.check([shellcheck_style_issues_file], {})
104 # Error severity should report fewer or equal issues than style
105 assert_that(error_result.issues_count).is_less_than_or_equal_to(
106 style_result.issues_count,
107 )
110def test_check_exclude_filters_issues(
111 get_plugin: Callable[[str], BaseToolPlugin],
112 shellcheck_violation_file: str,
113) -> None:
114 """Verify ShellCheck exclude option filters out specific codes.
116 Args:
117 get_plugin: Fixture factory to get plugin instances.
118 shellcheck_violation_file: Path to file with lint issues.
119 """
120 shellcheck_plugin = get_plugin("shellcheck")
122 # Check without exclusions
123 result_without_exclude = shellcheck_plugin.check([shellcheck_violation_file], {})
125 # Precondition: ensure we have issues to exclude
126 assert_that(result_without_exclude.issues_count).is_greater_than(0)
128 # Check with common codes excluded
129 shellcheck_plugin.set_options(exclude=["SC2086", "SC2002", "SC2206"])
130 result_with_exclude = shellcheck_plugin.check([shellcheck_violation_file], {})
132 # With exclusions should report fewer or equal issues
133 assert_that(result_with_exclude.issues_count).is_less_than_or_equal_to(
134 result_without_exclude.issues_count,
135 )