Skip to content

Enhance test db generation #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
22 changes: 22 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@
},
"problemMatcher": []
},
{
"label": "🧪 Standards Automation: Build Case Test DB from test file",
"type": "shell",
"windows": {
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}Scripts${pathSeparator}python.exe scripts${pathSeparator}build_test_database.py ${file}"
},
"linux": {
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}bin${pathSeparator}python3 scripts${pathSeparator}build_test_database.py ${file}"
},
"osx": {
"command": ".${pathSeparator}scripts${pathSeparator}.venv${pathSeparator}bin${pathSeparator}python3 scripts${pathSeparator}build_test_database.py ${file}"
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
},
"runOptions": {
"reevaluateOnRerun": false
},
"problemMatcher": []
},
{
"label": "📝 Standards Automation: Format CodeQL",
"type": "shell",
Expand Down
38 changes: 33 additions & 5 deletions scripts/build_test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@
import os
import subprocess
import json
from pathlib import Path

if len(sys.argv) < 4:
print ("Usage: build_test_database.py LANGUAGE STANDARD RULE", file=sys.stderr)
if len(sys.argv) != 4 and len(sys.argv) != 2:
print ("Usage: build_test_database.py TEST_FILE | LANGUAGE STANDARD RULE", file=sys.stderr)
exit(1)

LANGUAGE=sys.argv[1]
STANDARD=sys.argv[2]
RULE=sys.argv[3]
if len(sys.argv) == 4:
LANGUAGE=sys.argv[1]
STANDARD=sys.argv[2]
RULE=sys.argv[3]

if len(sys.argv) == 2:
TEST_FILE_PATH=Path(sys.argv[1])
if not TEST_FILE_PATH.exists():
print(f"The test file {TEST_FILE_PATH} does not exist!", file=sys.stderr)
exit(1)
RULE_PATH=TEST_FILE_PATH.parent
while True:
if len(list(RULE_PATH.glob("*.expected"))) > 0:
break
if RULE_PATH.parent != RULE_PATH:
RULE_PATH = RULE_PATH.parent
else:
print(f"The test file {TEST_FILE_PATH} is not a test because we couldn't find an expected file!", file=sys.stderr)
exit(1)
RULE=RULE_PATH.name
TESTS_PATH=RULE_PATH.parent.parent
if TESTS_PATH.name != "test":
print(f"The test file {TEST_FILE_PATH} is not in the expected test layout, cannot determine standard or language!", file=sys.stderr)
exit(1)

STANDARD_PATH=TESTS_PATH.parent
STANDARD=STANDARD_PATH.name

LANGUAGE_PATH=STANDARD_PATH.parent
LANGUAGE=LANGUAGE_PATH.name

if shutil.which("codeql") is None:
print ("Please install codeql.", file=sys.stderr)
Expand Down