From 634533208e3d714dc1326513136dad1936a1e6e5 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 15 Jan 2019 13:31:33 -0800 Subject: [PATCH] Fix integration test shebangs and update tests. * Integration tests now have their own list of allowed shebangs. * Use `#!/usr/bin/env bash` instead of `#!/bin/bash` since the location is different on various platforms. --- .../targets/inventory_foreman_script/foreman.sh | 2 +- .../targets/vault/runme_change_pip_installed.sh | 2 +- test/sanity/code-smell/shebang.py | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/test/integration/targets/inventory_foreman_script/foreman.sh b/test/integration/targets/inventory_foreman_script/foreman.sh index 70d7a99811f..18e9e153f8d 100755 --- a/test/integration/targets/inventory_foreman_script/foreman.sh +++ b/test/integration/targets/inventory_foreman_script/foreman.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Wrapper to use the correct Python interpreter and support code coverage. REL_SCRIPT="../../../../contrib/inventory/foreman.py" diff --git a/test/integration/targets/vault/runme_change_pip_installed.sh b/test/integration/targets/vault/runme_change_pip_installed.sh index 986b68ed04e..5ab2a8ec85b 100755 --- a/test/integration/targets/vault/runme_change_pip_installed.sh +++ b/test/integration/targets/vault/runme_change_pip_installed.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # start by removing pycrypto and cryptography diff --git a/test/sanity/code-smell/shebang.py b/test/sanity/code-smell/shebang.py index a3e607e79f2..7a64cf16614 100755 --- a/test/sanity/code-smell/shebang.py +++ b/test/sanity/code-smell/shebang.py @@ -6,10 +6,9 @@ import sys def main(): - allowed = set([ + standard_shebangs = set([ b'#!/bin/bash -eu', b'#!/bin/bash -eux', - b'#!/bin/bash', b'#!/bin/sh', b'#!/usr/bin/env bash', b'#!/usr/bin/env fish', @@ -18,6 +17,12 @@ def main(): b'#!/usr/bin/make -f', ]) + integration_shebangs = set([ + b'#!/bin/sh', + b'#!/usr/bin/env bash', + b'#!/usr/bin/env python', + ]) + module_shebangs = { '': b'#!/usr/bin/python', '.py': b'#!/usr/bin/python', @@ -61,6 +66,7 @@ def main(): continue is_module = False + is_integration = False if path.startswith('lib/ansible/modules/'): is_module = True @@ -73,6 +79,8 @@ def main(): continue elif path.startswith('test/integration/targets/'): + is_integration = True + dirname = os.path.dirname(path) if dirname.endswith('/library') or dirname in ( @@ -98,6 +106,11 @@ def main(): else: print('%s:%d:%d: expected module extension %s but found: %s' % (path, 0, 0, expected_ext, ext)) else: + if is_integration: + allowed = integration_shebangs + else: + allowed = standard_shebangs + if shebang not in allowed: print('%s:%d:%d: unexpected non-module shebang: %s' % (path, 1, 1, shebang))