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