From 605f2bff9ccf53b35751a371436d2ee62329b56e Mon Sep 17 00:00:00 2001 From: Taus Date: Fri, 2 May 2025 12:42:23 +0000 Subject: [PATCH] Python: Add integration test --- .../hidden-files/query-default.expected | 5 ++++ .../hidden-files/query-skipped.expected | 4 ++++ .../hidden-files/query.ql | 3 +++ .../.hidden_dir/visible_file_in_hidden_dir.py | 0 .../hidden-files/repo_dir/.hidden_file.py | 0 .../hidden-files/repo_dir/foo.py | 1 + .../cli-integration-test/hidden-files/test.sh | 24 +++++++++++++++++++ 7 files changed, 37 insertions(+) create mode 100644 python/extractor/cli-integration-test/hidden-files/query-default.expected create mode 100644 python/extractor/cli-integration-test/hidden-files/query-skipped.expected create mode 100644 python/extractor/cli-integration-test/hidden-files/query.ql create mode 100644 python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_dir/visible_file_in_hidden_dir.py create mode 100644 python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_file.py create mode 100644 python/extractor/cli-integration-test/hidden-files/repo_dir/foo.py create mode 100755 python/extractor/cli-integration-test/hidden-files/test.sh diff --git a/python/extractor/cli-integration-test/hidden-files/query-default.expected b/python/extractor/cli-integration-test/hidden-files/query-default.expected new file mode 100644 index 00000000000..cc92af624b3 --- /dev/null +++ b/python/extractor/cli-integration-test/hidden-files/query-default.expected @@ -0,0 +1,5 @@ +| name | ++-------------------------------+ +| .hidden_file.py | +| foo.py | +| visible_file_in_hidden_dir.py | diff --git a/python/extractor/cli-integration-test/hidden-files/query-skipped.expected b/python/extractor/cli-integration-test/hidden-files/query-skipped.expected new file mode 100644 index 00000000000..688dbe00d57 --- /dev/null +++ b/python/extractor/cli-integration-test/hidden-files/query-skipped.expected @@ -0,0 +1,4 @@ +| name | ++-----------------+ +| .hidden_file.py | +| foo.py | diff --git a/python/extractor/cli-integration-test/hidden-files/query.ql b/python/extractor/cli-integration-test/hidden-files/query.ql new file mode 100644 index 00000000000..3b1b3c03849 --- /dev/null +++ b/python/extractor/cli-integration-test/hidden-files/query.ql @@ -0,0 +1,3 @@ +import python + +select any(File f).getShortName() as name order by name diff --git a/python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_dir/visible_file_in_hidden_dir.py b/python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_dir/visible_file_in_hidden_dir.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_file.py b/python/extractor/cli-integration-test/hidden-files/repo_dir/.hidden_file.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/extractor/cli-integration-test/hidden-files/repo_dir/foo.py b/python/extractor/cli-integration-test/hidden-files/repo_dir/foo.py new file mode 100644 index 00000000000..517b47df53c --- /dev/null +++ b/python/extractor/cli-integration-test/hidden-files/repo_dir/foo.py @@ -0,0 +1 @@ +print(42) diff --git a/python/extractor/cli-integration-test/hidden-files/test.sh b/python/extractor/cli-integration-test/hidden-files/test.sh new file mode 100755 index 00000000000..77cb12664af --- /dev/null +++ b/python/extractor/cli-integration-test/hidden-files/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -Eeuo pipefail # see https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ + +set -x + +CODEQL=${CODEQL:-codeql} + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$SCRIPTDIR" + +rm -rf db db-skipped + +# Test 1: Default behavior should be to extract files in hidden directories +$CODEQL database create db --language python --source-root repo_dir/ +$CODEQL query run --database db query.ql > query-default.actual +diff query-default.expected query-default.actual + +# Test 2: Setting the relevant extractor option to true skips files in hidden directories +$CODEQL database create db-skipped --language python --source-root repo_dir/ --extractor-option python.skip_hidden_directories=true +$CODEQL query run --database db-skipped query.ql > query-skipped.actual +diff query-skipped.expected query-skipped.actual + +rm -rf db db-skipped