forked from semgrep/semgrep
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Speed up QA tests a bit (semgrep#5526)
* ci: Clean up public repos list * ci: Refactor test_semgrep_rules * Restore public repo cache only for public repo tests * Unify pipenv versions * Remove build-core dependency from test-core
- Loading branch information
Showing
9 changed files
with
63 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,68 +1,61 @@ | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
|
||
def _fail_subprocess_on_error(cmd): | ||
output = subprocess.run( | ||
cmd, | ||
capture_output=True, | ||
encoding="utf-8", | ||
) | ||
|
||
if output.returncode != 0: | ||
pytest.fail(f"Failed running cmd={cmd}" + output.stdout + output.stderr) | ||
from semgrep.cli import cli | ||
|
||
|
||
@pytest.mark.slow | ||
def test_semgrep_rules_repo(run_semgrep_in_tmp): | ||
@pytest.fixture(scope="session", autouse=True) | ||
def in_semgrep_rules_repo(tmpdir_factory): | ||
monkeypatch = pytest.MonkeyPatch() | ||
repo_dir = tmpdir_factory.mktemp("semgrep-rules") | ||
subprocess.check_output( | ||
["git", "clone", "--depth=1", "https://github.com/returntocorp/semgrep-rules"] | ||
) | ||
|
||
# Remove subdir that doesnt contain rules | ||
shutil.rmtree("./semgrep-rules/stats") | ||
|
||
_fail_subprocess_on_error( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"semgrep", | ||
"--generate-config", | ||
"--disable-version-check", | ||
"--metrics", | ||
"off", | ||
"git", | ||
"clone", | ||
"--depth=1", | ||
"https://github.com/returntocorp/semgrep-rules", | ||
repo_dir, | ||
] | ||
) | ||
# Remove subdir that doesnt contain rules | ||
shutil.rmtree(repo_dir / "stats") | ||
monkeypatch.chdir(repo_dir) | ||
yield | ||
monkeypatch.undo() | ||
|
||
|
||
_fail_subprocess_on_error( | ||
@pytest.mark.slow | ||
def test_semgrep_rules_repo__test(in_semgrep_rules_repo): | ||
runner = CliRunner() | ||
results = runner.invoke( | ||
cli, | ||
[ | ||
sys.executable, | ||
"-m", | ||
"semgrep", | ||
"--disable-version-check", | ||
"--metrics", | ||
"off", | ||
"--dangerously-allow-arbitrary-code-execution-from-rules", | ||
"--metrics=off", | ||
"--strict", | ||
"--test", | ||
"--test-ignore-todo", | ||
"semgrep-rules", | ||
], | ||
) | ||
print(results.output) | ||
assert results.exit_code == 0 | ||
|
||
|
||
_fail_subprocess_on_error( | ||
@pytest.mark.slow | ||
def test_semgrep_rules_repo__validate(in_semgrep_rules_repo): | ||
runner = CliRunner() | ||
results = runner.invoke( | ||
cli, | ||
[ | ||
sys.executable, | ||
"-m", | ||
"semgrep", | ||
"--disable-version-check", | ||
"--metrics", | ||
"off", | ||
"--metrics=off", | ||
"--strict", | ||
"--validate", | ||
"--config", | ||
"semgrep-rules", | ||
] | ||
"--config=.", | ||
], | ||
) | ||
print(results.output) | ||
assert results.exit_code == 0 |