Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/linter/reports/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_gitlab_report(self, rule, rule2, config, tmp_path):
report = GitlabReport(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics(issues)
# content of 1 and 2 file. 2 file use the same lines to check if fingerprint will be different
# content of 1 and 2 file. 2 files use the same lines to check if the fingerprint will be different
content = [["line1", "line2"], ["line1", "line1"]]
with mock.patch.object(report, "_get_source_lines", side_effect=content):
report.generate_report(diagnostics)
Expand All @@ -74,3 +74,17 @@ def test_configure_output_path(self, config):
report = GitlabReport(config)
report.configure("output_path", output_path)
assert report.output_path == output_path

def test_empty_results(self, config, tmp_path):
# Arrange
output_file = tmp_path / "report.json"
report = GitlabReport(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics([])

# Act
report.generate_report(diagnostics)

# Assert
assert output_file.exists()
assert output_file.read_text() == "[]"
14 changes: 14 additions & 0 deletions tests/linter/reports/test_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ def test_json_reports_saved_to_file(self, rule, rule2, tmp_path, config):
with open(output_file) as fp:
json_report = json.load(fp)
assert json_report == expected_report

def test_empty_results(self, config, tmp_path):
# Arrange
output_file = tmp_path / "report.json"
report = JsonReport(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics([])

# Act
report.generate_report(diagnostics)

# Assert
assert output_file.exists()
assert output_file.read_text() == "[]"
11 changes: 11 additions & 0 deletions tests/linter/reports/test_return_status_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ def test_return_status_with_quality_gates(
)
report.generate_report(Diagnostics(issues))
assert report.return_status == return_status

def test_empty_results(self, config):
# Arrange
report = ReturnStatusReport(config)
diagnostics = Diagnostics([])

# Act
report.generate_report(diagnostics)

# Assert
assert report.return_status == 0
34 changes: 34 additions & 0 deletions tests/linter/reports/test_sarif_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,37 @@ def get_expected_result(diagnostic: Diagnostic, level, source):
with open(output_file) as fp:
sarif_report = json.load(fp)
assert expected_report == sarif_report

def test_empty_results(self, config, tmp_path):
# Arrange
output_file = tmp_path / "report.json"
report = SarifReport(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics([])
config_manager = Mock()
config_manager.root = Path.cwd()
config_manager.default_config.linter.rules = {}

# Act
report.generate_report(diagnostics, config_manager)

# Assert
assert output_file.exists()
assert json.loads(output_file.read_text()) == {
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
"runs": [
{
"automationDetails": {"id": "robocop/"},
"results": [],
"tool": {
"driver": {
"informationUri": "https://robocop.dev/",
"name": "Robocop",
"rules": [],
"semanticVersion": __version__,
}
},
}
],
"version": "2.1.0",
}
16 changes: 16 additions & 0 deletions tests/linter/reports/test_sonar_qube.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,19 @@ def test_configure_output_path(self, config):
report = SonarQubeReport(config)
report.configure("output_path", output_path)
assert report.output_path == output_path

def test_empty_results(self, config, tmp_path):
# Arrange
output_file = tmp_path / "report.json"
report = SonarQubeReport(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics([])
config_manager = Mock()
config_manager.root = Path.cwd()

# Act
report.generate_report(diagnostics, config_manager)

# Assert
assert output_file.exists()
assert json.loads(output_file.read_text()) == {"rules": [], "issues": []}
14 changes: 14 additions & 0 deletions tests/linter/reports/test_text_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ def test_text_file_report(self, rule, rule2, tmp_path, config):
# assert
actual_report = (tmp_path / "robocop.txt").read_text()
assert actual_report == expected_report

def test_empty_results(self, config, tmp_path):
# Arrange
output_file = tmp_path / "report.txt"
report = TextFile(config)
report.configure("output_path", str(output_file))
diagnostics = Diagnostics([])

# Act
report.generate_report(diagnostics)

# Assert
assert output_file.exists()
assert output_file.read_text() == ""