diff --git a/changelogs/fragments/79700-test-shebang.yml b/changelogs/fragments/79700-test-shebang.yml new file mode 100644 index 00000000000..1ede53e5d65 --- /dev/null +++ b/changelogs/fragments/79700-test-shebang.yml @@ -0,0 +1,2 @@ +minor_changes: + - "ansible-test shebang sanity test - ignore files in ``files/`` and ``templates/`` in collection roles and integration test targets (https://github.com/ansible/ansible/pull/79700)." diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh new file mode 100644 index 00000000000..ff302fe9bdd --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file (inside the collection). diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh new file mode 100644 index 00000000000..ff302fe9bdd --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file (inside the collection). diff --git a/test/integration/targets/ansible-test-sanity-shebang/files/test.py b/test/integration/targets/ansible-test-sanity-shebang/files/test.py new file mode 100644 index 00000000000..5f43ddf2368 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/files/test.py @@ -0,0 +1,7 @@ +#!/pyth + +# Python file with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/integration/targets/ansible-test-sanity-shebang/files/test.sh b/test/integration/targets/ansible-test-sanity-shebang/files/test.sh new file mode 100644 index 00000000000..98bc38d64df --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-shebang/files/test.sh @@ -0,0 +1,7 @@ +#!/bin/foo + +# Shell script with non-standard shebang. + +# Since it appears in a files/ or templates/ directory inside an integration test, +# the 'shebang' sanity test should ignore it. This "test" is successful when no +# ignore.txt entry is needed for this file. diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py index 8922c8be111..9db73a3d5cf 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py @@ -61,6 +61,7 @@ def main(): is_module = False is_integration = False + is_role_file = False dirname = os.path.dirname(path) @@ -84,6 +85,10 @@ def main(): print('%s:%d:%d: should not have a shebang' % (path, 0, 0)) continue + elif re.search('^roles/[^/]+/(?:files|templates)/', path): + is_role_file = True + elif re.search('^tests/integration/targets/[^/]+/(?:files|templates)/', path): + is_role_file = True elif path.startswith('test/integration/targets/') or path.startswith('tests/integration/targets/'): is_integration = True @@ -111,6 +116,8 @@ def main(): print('%s:%d:%d: expected module shebang "%s" but found: %s' % (path, 1, 1, expected_shebang, shebang)) else: print('%s:%d:%d: expected module extension %s but found: %s' % (path, 0, 0, expected_ext, ext)) + elif is_role_file: + continue else: if is_integration: allowed = integration_shebangs diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index bb296a812d9..9b4dcd053f7 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -75,6 +75,15 @@ test/integration/targets/ansible-test-docker/ansible_collections/ns/col/plugins/ test/integration/targets/ansible-test-docker/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py pylint:relative-beyond-top-level test/integration/targets/ansible-test-docker/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py pylint:relative-beyond-top-level test/integration/targets/ansible-test-no-tty/ansible_collections/ns/col/vendored_pty.py pep8!skip # vendored code +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/roles/foo/files/test.sh shellcheck:SC1008 +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/ansible_collections/ns/col/tests/integration/targets/valid/files/test.sh shellcheck:SC1008 +test/integration/targets/ansible-test-sanity-shebang/files/test.py shebang +test/integration/targets/ansible-test-sanity-shebang/files/test.sh shebang +test/integration/targets/ansible-test-sanity-shebang/files/test.sh shellcheck:SC1008 test/integration/targets/collections_relative_imports/collection_root/ansible_collections/my_ns/my_col/plugins/modules/my_module.py pylint:relative-beyond-top-level test/integration/targets/collections_relative_imports/collection_root/ansible_collections/my_ns/my_col/plugins/module_utils/my_util2.py pylint:relative-beyond-top-level test/integration/targets/fork_safe_stdio/vendored_pty.py pep8!skip # vendored code