Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77b5611

Browse filesBrowse files
committed
Add unit test for guideline recategorization report generation
1 parent 30a47e0 commit 77b5611
Copy full SHA for 77b5611

File tree

Expand file treeCollapse file tree

7 files changed

+88
-1
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+88
-1
lines changed
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from pathlib import Path
3+
import sys
4+
from guideline_recategorizations import generate_guideline_recategorizations_report
5+
6+
script_path = Path(__file__)
7+
# Add the shared modules to the path so we can import them.
8+
sys.path.append(str(script_path.parent.parent / 'shared'))
9+
from codeql import CodeQL, CodeQLError
10+
11+
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
12+
SCRIPTS_DIR = REPO_ROOT / 'scripts'
13+
TEST_DATA_DIR = Path(__file__).resolve().parent / 'test-data'
14+
15+
def test_guideline_recategorizations_report(tmp_path):
16+
17+
db_path = tmp_path / 'test-db'
18+
src_root = TEST_DATA_DIR / 'guideline-recategorizations'
19+
codeql = CodeQL()
20+
21+
compile_src_command = "clang -fsyntax-only test.cpp"
22+
index_coding_standards_config_command = f"python3 {SCRIPTS_DIR}/configuration/process_coding_standards_config.py"
23+
24+
try:
25+
codeql.create_database(src_root, 'cpp', db_path, compile_src_command, index_coding_standards_config_command)
26+
except CodeQLError as err:
27+
print(err.stdout)
28+
print(err.stderr)
29+
raise err
30+
31+
generate_guideline_recategorizations_report(db_path, REPO_ROOT, tmp_path)
32+
33+
expected = (TEST_DATA_DIR / 'guideline-recategorizations' / 'guideline_recategorizations_report.md.expected').read_text()
34+
expected = expected.replace("$codeql-version$", codeql.version).replace("$database-path$", str(db_path))
35+
actual = (tmp_path / "guideline_recategorizations_report.md").read_text()
36+
37+
assert(expected == actual)

‎scripts/reports/requirements.txt

Copy file name to clipboard
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pyyaml==5.4
1+
pyyaml==5.4
2+
pytest==7.2.0

‎scripts/reports/test-data/guideline-recategorizations/coding-standards.yml

Copy file name to clipboardExpand all lines: scripts/reports/test-data/guideline-recategorizations/coding-standards.yml
Whitespace-only changes.
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Guideline recategorizations report
2+
3+
## Overview
4+
5+
- Report generated with supported CodeQL version $codeql-version$
6+
- Database path: $database-path$
7+
- 8 applicable guideline recategorizations and 5 invalid guideline recategorizations found in the database
8+
9+
## Guideline recategorizations
10+
11+
| Rule ID | Category | Recategorized category
12+
| --- | --- | --- |
13+
| A0-1-1 | required | advisory |
14+
| A0-1-1 | required | mandatory |
15+
| A0-1-2 | required | disapplied |
16+
| RULE-13-6 | mandatory | required |
17+
| CON50-CPP | rule | required |
18+
| A0-1-6 | advisory | disapplied |
19+
| A10-4-1 | advisory | required |
20+
| A11-0-1 | advisory | mandatory |
21+
22+
## Invalid guideline recategorizations
23+
| Path | Reason |
24+
| --- | --- |
25+
| invalid/coding-standards.xml:5:7:8:43 | 'Invalid recategorization from 'required' to 'advisory'.' for rule A0-1-1. |
26+
| invalid/coding-standards.xml:9:7:12:43 | 'Invalid recategorization from 'required' to 'disapplied'.' for rule A0-1-2. |
27+
| invalid/coding-standards.xml:13:7:16:43 | 'Unknown rule id 'A1-4-3'.' for rule A1-4-3. |
28+
| invalid/coding-standards.xml:17:7:20:43 | 'Invalid recategorization from 'mandatory' to 'required'.' for rule RULE-13-6. |
29+
| invalid/coding-standards.xml:21:7:24:43 | 'Invalid recategorization from 'rule' to 'required'.' for rule CON50-CPP. |
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
guideline-recategorizations:
2+
- rule-id: "A0-1-1"
3+
category: "advisory"
4+
- rule-id: "A0-1-2"
5+
category: "disapplied"
6+
- rule-id: "A1-4-3"
7+
category: "mandatory"
8+
- rule-id: "RULE-13-6"
9+
category: "required"
10+
- rule-id: "CON50-CPP"
11+
category: "required"

‎scripts/reports/test-data/guideline-recategorizations/test.cpp

Copy file name to clipboardExpand all lines: scripts/reports/test-data/guideline-recategorizations/test.cpp
Whitespace-only changes.
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
guideline-recategorizations:
2+
- rule-id: "A0-1-1"
3+
category: "mandatory"
4+
- rule-id: "A0-1-6"
5+
category: "disapplied"
6+
- rule-id: "A10-4-1"
7+
category: "required"
8+
- rule-id: "A11-0-1"
9+
category: "mandatory"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.