-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathquery_suites.py
More file actions
30 lines (25 loc) · 1.28 KB
/
query_suites.py
File metadata and controls
30 lines (25 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import pytest
@pytest.fixture
def check_query_suite(codeql, cwd, expected_files, semmle_code_dir):
def ret(query_suite):
actual = codeql.resolve.queries(query_suite, _capture=True)
actual = sorted(actual.splitlines())
actual = [os.path.relpath(q, semmle_code_dir) for q in actual]
actual_file_name = query_suite + '.actual'
expected_files.add(actual_file_name)
(cwd / actual_file_name).write_text('\n'.join(actual) + '\n')
return ret
@pytest.fixture
def check_queries_not_included(codeql, cwd, expected_files, semmle_code_dir):
def ret(lang_folder_name, query_suites):
all_queries = codeql.resolve.queries(semmle_code_dir / 'ql' / lang_folder_name / 'ql' / 'src', _capture=True).splitlines()
included_in_qls = set()
for query_suite in query_suites:
included_in_qls |= set(codeql.resolve.queries(query_suite, _capture=True).strip().splitlines())
not_included = sorted(set(all_queries) - included_in_qls)
not_included = [os.path.relpath(q, semmle_code_dir) for q in not_included]
not_included_file_name = 'not_included_in_qls.actual'
expected_files.add(not_included_file_name)
(cwd / not_included_file_name).write_text('\n'.join(not_included) + '\n')
return ret