luarocks / hererocks

Python script for installing Lua/LuaJIT and LuaRocks into a local directory
MIT License
71 stars 12 forks source link

Fix activate_posix script to work in Bash POSIX Mode #7

Closed un-def closed 4 years ago

un-def commented 4 years ago

When Bash is run in POSIX mode (using the /bin/sh symlink, the set -o posix command, or the --posix CLI flag), it is still not 100% compatible with ash/dash.

Here are two differences that affect the activate_posix script:

Compare:

$ sh -c '. $HOME/.luambenvs/lua53/bin/activate_posix; command -V deactivate_lua'          
deactivate_lua is a shell function

$ bash --posix -c '. $HOME/.luambenvs/lua53/bin/activate_posix; command -V deactivate_lua'
/home/def/.luambenvs/lua53/bin/activate_posix: line 1: command: deactivate_lua: not found
deactivate_lua is a function
deactivate_lua () 
{ 
    if [ -x '/home/def/.luambenvs/lua53/bin/lua' ]; then
        PATH=`'/home/def/.luambenvs/lua53/bin/lua' '/home/def/.luambenvs/lua53/bin/get_deactivated_path.lua'`;
        export PATH;
        hash -r 2> /dev/null;
    fi;
    unset -f deactivate_lua
}

Here is a new test and the fix. The test result without the fix:

$ nosetests test/cli_test.py:TestCLI.test_activate_posix_script_bash_posix_mode
F
======================================================================
FAIL: test_activate_posix_script_bash_posix_mode (cli_test.TestCLI)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/def/dev/hererocks/test/cli_test.py", line 184, in test_activate_posix_script_bash_posix_mode
    self.check_activate_posix_script(check_cmd)
  File "/home/def/dev/hererocks/test/cli_test.py", line 163, in check_activate_posix_script
    self.assertSuccess(check_cmd, [
  File "/home/def/dev/hererocks/test/cli_test.py", line 52, in assertSuccess
    raise AssertionError("Expected to see '{}' in output of command '{}', got output:\n{}".format(
AssertionError: Expected to see 'b'reactivate 1: /home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'' in output of command 'bash --posix test/check_activate_posix.sh', got output:
b'initial: /home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\ntest/here/bad (dir) 1/bin/activate_posix: line 1: command: deactivate_lua: not found\nactivate 1: /home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\ndeactivate 1: /home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\ntest/here/bad (dir) 1/bin/activate_posix: line 1: command: deactivate_lua: not found\nactivate 1 again: /home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\nreactivate 1: /home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\nactivate 2: /home/def/dev/hererocks/test/here/bad (dir) 2/bin:/home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\ndeactivate 2: /home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/dev/hererocks/test/here/bad (dir) 1/bin:/home/def/.virtualenvs/hererocks/bin:/home/def/.local/bin:/home/def/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\n'
hishamhm commented 4 years ago

@un-def Merged, thank you!!