|
40 | 40 | import sys |
41 | 41 | import tempfile |
42 | 42 | from distutils.version import LooseVersion |
43 | | -from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered |
| 43 | +from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config |
44 | 44 | from test.framework.package import mock_fpm |
45 | 45 | from unittest import TextTestRunner |
46 | 46 |
|
@@ -2854,6 +2854,47 @@ def test_fix_shebang(self): |
2854 | 2854 | self.assertTrue(bash_shebang_regex.match(bashbin_txt), |
2855 | 2855 | "Pattern '%s' found in %s: %s" % (bash_shebang_regex.pattern, bashbin_path, bashbin_txt)) |
2856 | 2856 |
|
| 2857 | + # now test with a custom env command |
| 2858 | + init_config(build_options={'env_for_shebang': "/usr/bin/env -S"}) |
| 2859 | + |
| 2860 | + self.test_toy_build(ec_file=test_ec, raise_error=True) |
| 2861 | + |
| 2862 | + toy_bindir = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'bin') |
| 2863 | + |
| 2864 | + # bin/toy and bin/toy2 should *not* be patched, since they're binary files |
| 2865 | + toy_txt = read_file(os.path.join(toy_bindir, 'toy'), mode='rb') |
| 2866 | + for fn in ['toy.perl', 'toy.python']: |
| 2867 | + fn_txt = read_file(os.path.join(toy_bindir, fn), mode='rb') |
| 2868 | + # no shebang added |
| 2869 | + self.assertFalse(fn_txt.startswith(b"#!/")) |
| 2870 | + # exact same file as original binary (untouched) |
| 2871 | + self.assertEqual(toy_txt, fn_txt) |
| 2872 | + |
| 2873 | + # no re.M, this should match at start of file! |
| 2874 | + py_shebang_regex = re.compile(r'^#!/usr/bin/env -S python\n# test$') |
| 2875 | + for pybin in ['t1.py', 't2.py', 't3.py', 't4.py', 't5.py', 't6.py', 't7.py']: |
| 2876 | + pybin_path = os.path.join(toy_bindir, pybin) |
| 2877 | + pybin_txt = read_file(pybin_path) |
| 2878 | + self.assertTrue(py_shebang_regex.match(pybin_txt), |
| 2879 | + "Pattern '%s' found in %s: %s" % (py_shebang_regex.pattern, pybin_path, pybin_txt)) |
| 2880 | + |
| 2881 | + # no re.M, this should match at start of file! |
| 2882 | + perl_shebang_regex = re.compile(r'^#!/usr/bin/env -S perl\n# test$') |
| 2883 | + for perlbin in ['t1.pl', 't2.pl', 't3.pl', 't4.pl', 't5.pl', 't6.pl', 't7.pl']: |
| 2884 | + perlbin_path = os.path.join(toy_bindir, perlbin) |
| 2885 | + perlbin_txt = read_file(perlbin_path) |
| 2886 | + self.assertTrue(perl_shebang_regex.match(perlbin_txt), |
| 2887 | + "Pattern '%s' found in %s: %s" % (perl_shebang_regex.pattern, perlbin_path, perlbin_txt)) |
| 2888 | + |
| 2889 | + # There are 2 bash files which shouldn't be influenced by fix_shebang |
| 2890 | + bash_shebang_regex = re.compile(r'^#!/usr/bin/env bash\n# test$') |
| 2891 | + for bashbin in ['b1.sh', 'b2.sh']: |
| 2892 | + bashbin_path = os.path.join(toy_bindir, bashbin) |
| 2893 | + bashbin_txt = read_file(bashbin_path) |
| 2894 | + self.assertTrue(bash_shebang_regex.match(bashbin_txt), |
| 2895 | + "Pattern '%s' found in %s: %s" % (bash_shebang_regex.pattern, bashbin_path, bashbin_txt)) |
| 2896 | + |
| 2897 | + |
2857 | 2898 | def test_toy_system_toolchain_alias(self): |
2858 | 2899 | """Test use of 'system' toolchain alias.""" |
2859 | 2900 | toy_ec = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb') |
|
0 commit comments