def test_shebang_handling(script_dir, sbang_line): assert sbang.shebang_too_long(script_dir.lua_shebang) assert sbang.shebang_too_long(script_dir.long_shebang) assert sbang.shebang_too_long(script_dir.nonexec_long_shebang) assert not sbang.shebang_too_long(script_dir.short_shebang) assert not sbang.shebang_too_long(script_dir.has_sbang) assert not sbang.shebang_too_long(script_dir.binary) assert not sbang.shebang_too_long(script_dir.directory) sbang.filter_shebangs_in_directory(script_dir.tempdir) # Make sure this is untouched with open(script_dir.short_shebang, 'r') as f: assert f.readline() == short_line assert f.readline() == last_line # Make sure this got patched. with open(script_dir.long_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == long_line assert f.readline() == last_line # Make sure this is untouched with open(script_dir.nonexec_long_shebang, 'r') as f: assert f.readline() == long_line assert f.readline() == last_line # Make sure this got patched. with open(script_dir.lua_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == lua_line_patched assert f.readline() == last_line # Make sure this got patched. with open(script_dir.node_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == node_line_patched assert f.readline() == last_line assert filecmp.cmp(script_dir.lua_textbang, os.path.join(script_dir.tempdir, 'lua_in_text')) assert filecmp.cmp(script_dir.node_textbang, os.path.join(script_dir.tempdir, 'node_in_text')) # Make sure this is untouched with open(script_dir.has_sbang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == long_line assert f.readline() == last_line
def test_shebang_handling(script_dir): assert shebang_too_long(script_dir.lua_shebang) assert shebang_too_long(script_dir.long_shebang) assert not shebang_too_long(script_dir.short_shebang) assert not shebang_too_long(script_dir.has_sbang) assert not shebang_too_long(script_dir.binary) assert not shebang_too_long(script_dir.directory) filter_shebangs_in_directory(script_dir.tempdir) # Make sure this is untouched with open(script_dir.short_shebang, 'r') as f: assert f.readline() == short_line assert f.readline() == last_line # Make sure this got patched. with open(script_dir.long_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == long_line assert f.readline() == last_line # Make sure this got patched. with open(script_dir.lua_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == lua_line_patched assert f.readline() == last_line # Make sure this got patched. with open(script_dir.node_shebang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == node_line_patched assert f.readline() == last_line assert filecmp.cmp(script_dir.lua_textbang, os.path.join(script_dir.tempdir, 'lua_in_text')) assert filecmp.cmp(script_dir.node_textbang, os.path.join(script_dir.tempdir, 'node_in_text')) # Make sure this is untouched with open(script_dir.has_sbang, 'r') as f: assert f.readline() == sbang_line assert f.readline() == long_line assert f.readline() == last_line