-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add query suite integration tests for swift, actions, csharp, go, javascript, ruby, rust #19355
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c9aee2
Add query suite tests for swift with shared logic
tamasvajk 522dd51
Improve query suite test based on feedback
tamasvajk a4a2447
Add query suite inclusion tests for actions, csharp, go, javascript, …
tamasvajk c54b684
Apply suggestions from code review - code quality improvements
tamasvajk 998e64b
Fix failing C# test
tamasvajk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve query suite test based on feedback
- Loading branch information
commit 522dd51416ec33b5be635a864d1c84e287c6fed3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
import runs_on | ||
import pytest | ||
import sys | ||
|
||
def get_test_module(semmle_code_dir): | ||
import importlib.util | ||
spec = importlib.util.spec_from_file_location('test-module', semmle_code_dir / 'ql' / 'misc' / 'pytest' / 'lib' / 'query-suite-test.py') | ||
mod = importlib.util.module_from_spec(spec) | ||
sys.modules["test-module"] = mod | ||
spec.loader.exec_module(mod) | ||
return mod | ||
from query_suites import * | ||
|
||
well_known_query_suites = ['java-code-quality.qls', 'java-security-and-quality.qls', 'java-security-extended.qls', 'java-code-scanning.qls'] | ||
|
||
@runs_on.posix | ||
@pytest.mark.parametrize("query_suite", well_known_query_suites) | ||
def test(codeql, java, cwd, expected_files, semmle_code_dir, query_suite): | ||
get_test_module(semmle_code_dir).test(codeql, cwd, expected_files, semmle_code_dir, query_suite) | ||
|
||
def test(codeql, java, check_query_suite, query_suite): | ||
check_query_suite(query_suite) | ||
|
||
@runs_on.posix | ||
def test_not_included_queries(codeql, java, cwd, expected_files, semmle_code_dir): | ||
get_test_module(semmle_code_dir).test_not_included_queries(codeql, 'java', cwd, expected_files, semmle_code_dir, well_known_query_suites) | ||
def test_not_included_queries(codeql, java, check_queries_not_included): | ||
check_queries_not_included('java', well_known_query_suites) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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).strip() | ||
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') | ||
tamasvajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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).strip().splitlines() | ||
tamasvajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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') | ||
tamasvajk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
import runs_on | ||
import pytest | ||
import sys | ||
|
||
def get_test_module(semmle_code_dir): | ||
import importlib.util | ||
spec = importlib.util.spec_from_file_location('test-module', semmle_code_dir / 'ql' / 'misc' / 'pytest' / 'lib' / 'query-suite-test.py') | ||
mod = importlib.util.module_from_spec(spec) | ||
sys.modules["test-module"] = mod | ||
spec.loader.exec_module(mod) | ||
return mod | ||
|
||
from query_suites import * | ||
|
||
well_known_query_suites = ['swift-code-quality.qls', 'swift-security-and-quality.qls', 'swift-security-extended.qls', 'swift-code-scanning.qls'] | ||
|
||
@runs_on.posix | ||
@pytest.mark.parametrize("query_suite", well_known_query_suites) | ||
def test(codeql, swift, cwd, expected_files, semmle_code_dir, query_suite): | ||
get_test_module(semmle_code_dir).test(codeql, cwd, expected_files, semmle_code_dir, query_suite) | ||
def test(codeql, swift, check_query_suite, query_suite): | ||
check_query_suite(query_suite) | ||
|
||
@runs_on.posix | ||
def test_not_included_queries(codeql, swift, cwd, expected_files, semmle_code_dir): | ||
get_test_module(semmle_code_dir).test_not_included_queries(codeql, 'swift', cwd, expected_files, semmle_code_dir, well_known_query_suites) | ||
def test_not_included_queries(codeql, swift, check_queries_not_included): | ||
check_queries_not_included('swift', well_known_query_suites) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.