Skip to content

Commit

Permalink
If /usr/bin is at the front of $PATH, strip it -- attempt 2
Browse files Browse the repository at this point in the history
This is a workaround for a bug in pyenv which is affecting Travis
builds. pyenv is currently adding `/usr/bin` to the front of $PATH for
anything run through python. This screws up emacs version management
with evm which relies on the evm bin directory being earlier in the path
than any other directory containing emacs binaries.

Fixes #399.
  • Loading branch information
davidshepherd7 committed Nov 6, 2017
1 parent bf52c3e commit 02fb473
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bin/cask
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ def main():
"""
try:
# Special handling for emacs on travis with evm and buggy pyenv, see
# cask issue #399.
if ENVB.get(b'TRAVIS', b'') == b'true':
paths = ENVB[b'PATH'].split(b':')
if len(paths) > 0 and paths[0] == b'/usr/bin':
ENVB[b'PATH'] = ':'.join(paths[1:])


if sys.version_info[:2] < (2, 6):
exit_error(
'Python 2.6 required, yours is {0.major}.{0.minor}'.format(
Expand Down
19 changes: 19 additions & 0 deletions features/exec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ Feature: Exec
cask exec: error: Failed to execute does-not-exist: [Errno 2] No such file or directory
Did you run cask install?
"""

Scenario: With Travis' pyenv prepending /usr/bin to path, remove the first instance
Given this Cask file:
"""
"""
When I set environment variable "TRAVIS" to "true"
When "/usr/bin" is prepended to $PATH
When I run cask "exec sh -c 'echo $PATH'"
Then I should not see command output matching "^/usr/bin:"
Then I should see command output matching ":/usr/bin:"

Scenario: With a path starting with /usr/bin, but not on Travis
Given this Cask file:
"""
"""
When I set environment variable "TRAVIS" to "blah"
When "/usr/bin" is prepended to $PATH
When I run cask "exec sh -c 'echo $PATH'"
Then I should see command output matching "^/usr/bin:"
16 changes: 16 additions & 0 deletions features/step-definitions/cask-steps.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
(t
(setq cask-test/stderr content))))))))

(When "^\"\\([^\"]+\\)\" is prepended to $PATH$"
(lambda (path)
(setenv "PATH" (s-concat path ":" (getenv "PATH")))))

(When "I set environment variable \"\\([^\"]+\\)\" to \"\\([^\"]+\\)\""
(lambda (var value)
(setenv var value)))

(Then "^I should see command error:$"
(lambda (output)
(should (s-contains? output cask-test/stderr))))
Expand All @@ -80,6 +88,10 @@
(lambda (output)
(should (s-contains? output cask-test/stdout))))

(Then "^I should see command output matching \"\\([^\"]+\\)\"$"
(lambda (regex)
(should (s-matches? regex cask-test/stdout))))

(Then "^I should not see command error:$"
(lambda (output)
(should-not (s-contains? output cask-test/stderr))))
Expand All @@ -88,6 +100,10 @@
(lambda (output)
(should-not (s-contains? output cask-test/stdout))))

(Then "^I should not see command output matching \"\\(.*\\)\"$"
(lambda (regex)
(should-not (s-matches? regex cask-test/stdout))))

(Then "^I should see usage information$"
(lambda ()
(should (s-contains? "USAGE: cask [COMMAND] [OPTIONS]" cask-test/stdout))))
Expand Down
12 changes: 11 additions & 1 deletion features/support/env.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,28 @@
(defvar cask-test/stderr)
(defvar cask-test/stdout)

(defvar cask-initial-$PATH)
(defvar cask-initial-$TRAVIS)

(add-to-list 'load-path cask-test/root-path)

(unless (require 'ert nil t)
(require 'ert (f-expand "ert" cask-test/vendor-path)))

(Setup
(setq cask-initial-$PATH (getenv "PATH"))
(setq cask-initial-$TRAVIS (getenv "TRAVIS")))

(Before
(setq cask-test/stderr "")
(setq cask-test/stdout "")

(when (f-dir? cask-test/sandbox-path)
(f-delete cask-test/sandbox-path 'force))
(f-mkdir cask-test/sandbox-path))
(f-mkdir cask-test/sandbox-path)

(setenv "PATH" cask-initial-$PATH)
(setenv "TRAVIS" cask-initial-$TRAVIS))

(Fail
(-when-let (stdout (s-presence cask-test/stdout))
Expand Down

0 comments on commit 02fb473

Please sign in to comment.