Imported Upstream version 1.0.0
Christian Hofstaedtler
8 years ago
1 | 1 | /shims |
2 | 2 | /version |
3 | 3 | /versions |
4 | /sources | |
5 | /cache | |
6 | /libexec/*.dylib | |
7 | /src/Makefile | |
8 | /src/*.o | |
9 | /gems |
0 | sudo: false | |
1 | install: git clone --depth 1 https://github.com/sstephenson/bats.git | |
2 | script: PATH="./bats/bin:$PATH" test/run | |
3 | language: c | |
4 | env: | |
5 | - RBENV_NATIVE_EXT= | |
6 | - RBENV_NATIVE_EXT=1 |
1 | 1 | |
2 | 2 | Use rbenv to pick a Ruby version for your application and guarantee |
3 | 3 | that your development environment matches production. Put rbenv to work |
4 | with [Bundler](http://gembundler.com/) for painless Ruby upgrades and | |
4 | with [Bundler](http://bundler.io/) for painless Ruby upgrades and | |
5 | 5 | bulletproof deployments. |
6 | 6 | |
7 | 7 | **Powerful in development.** Specify your app's Ruby version once, |
12 | 12 | |
13 | 13 | **Rock-solid in production.** Your application's executables are its |
14 | 14 | interface with ops. With rbenv and [Bundler |
15 | binstubs](https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs) | |
15 | binstubs](https://github.com/rbenv/rbenv/wiki/Understanding-binstubs) | |
16 | 16 | you'll never again need to `cd` in a cron job or Chef recipe to |
17 | 17 | ensure you've selected the right runtime. The Ruby version |
18 | 18 | dependency lives in one place—your app—so upgrades and rollbacks are |
21 | 21 | **One thing well.** rbenv is concerned solely with switching Ruby |
22 | 22 | versions. It's simple and predictable. A rich plugin ecosystem lets |
23 | 23 | you tailor it to suit your needs. Compile your own Ruby versions, or |
24 | use the [ruby-build](https://github.com/sstephenson/ruby-build) | |
24 | use the [ruby-build][] | |
25 | 25 | plugin to automate the process. Specify per-application environment |
26 | variables with [rbenv-vars](https://github.com/sstephenson/rbenv-vars). | |
26 | variables with [rbenv-vars](https://github.com/rbenv/rbenv-vars). | |
27 | 27 | See more [plugins on the |
28 | wiki](https://github.com/sstephenson/rbenv/wiki/Plugins). | |
28 | wiki](https://github.com/rbenv/rbenv/wiki/Plugins). | |
29 | 29 | |
30 | 30 | [**Why choose rbenv over |
31 | RVM?**](https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F) | |
31 | RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F) | |
32 | 32 | |
33 | 33 | ## Table of Contents |
34 | 34 | |
41 | 41 | * [Basic GitHub Checkout](#basic-github-checkout) |
42 | 42 | * [Upgrading](#upgrading) |
43 | 43 | * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) |
44 | * [Neckbeard Configuration](#neckbeard-configuration) | |
44 | * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) | |
45 | * [Installing Ruby Versions](#installing-ruby-versions) | |
45 | 46 | * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) |
47 | * [Uninstalling rbenv](#uninstalling-rbenv) | |
46 | 48 | * [Command Reference](#command-reference) |
47 | 49 | * [rbenv local](#rbenv-local) |
48 | 50 | * [rbenv global](#rbenv-global) |
52 | 54 | * [rbenv rehash](#rbenv-rehash) |
53 | 55 | * [rbenv which](#rbenv-which) |
54 | 56 | * [rbenv whence](#rbenv-whence) |
57 | * [Environment variables](#environment-variables) | |
55 | 58 | * [Development](#development) |
56 | * [Version History](#version-history) | |
57 | * [License](#license) | |
58 | 59 | |
59 | 60 | ## How It Works |
60 | 61 | |
61 | At at high level, rbenv intercepts Ruby commands using shim | |
62 | At a high level, rbenv intercepts Ruby commands using shim | |
62 | 63 | executables injected into your `PATH`, determines which Ruby version |
63 | 64 | has been specified by your application, and passes your commands along |
64 | 65 | to the correct Ruby installation. |
107 | 108 | the [`rbenv shell`](#rbenv-shell) command to set this environment |
108 | 109 | variable in your current shell session. |
109 | 110 | |
110 | 2. The application-specific `.ruby-version` file in the current | |
111 | directory, if present. You can modify the current directory's | |
112 | `.ruby-version` file with the [`rbenv local`](#rbenv-local) | |
113 | command. | |
114 | ||
115 | 3. The first `.ruby-version` file found by searching each parent | |
116 | directory until reaching the root of your filesystem, if any. | |
111 | 2. The first `.ruby-version` file found by searching the directory of the | |
112 | script you are executing and each of its parent directories until reaching | |
113 | the root of your filesystem. | |
114 | ||
115 | 3. The first `.ruby-version` file found by searching the current working | |
116 | directory and each of its parent directories until reaching the root of your | |
117 | filesystem. You can modify the `.ruby-version` file in the current working | |
118 | directory with the [`rbenv local`](#rbenv-local) command. | |
117 | 119 | |
118 | 120 | 4. The global `~/.rbenv/version` file. You can modify this file using |
119 | 121 | the [`rbenv global`](#rbenv-global) command. If the global version |
155 | 157 | 1. Check out rbenv into `~/.rbenv`. |
156 | 158 | |
157 | 159 | ~~~ sh |
158 | $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv | |
160 | $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv | |
161 | ~~~ | |
162 | ||
163 | Optionally, try to compile dynamic bash extension to speed up rbenv. Don't | |
164 | worry if it fails; rbenv will still work normally: | |
165 | ||
166 | ~~~ | |
167 | $ cd ~/.rbenv && src/configure && make -C src | |
159 | 168 | ~~~ |
160 | 169 | |
161 | 170 | 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` |
165 | 174 | $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile |
166 | 175 | ~~~ |
167 | 176 | |
168 | **Ubuntu note**: Modify your `~/.profile` instead of `~/.bash_profile`. | |
177 | **Ubuntu Desktop note**: Modify your `~/.bashrc` instead of `~/.bash_profile`. | |
169 | 178 | |
170 | 179 | **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. |
171 | 180 | |
175 | 184 | $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile |
176 | 185 | ~~~ |
177 | 186 | |
178 | _Same as in previous step, use `~/.profile` on Ubuntu, `~/.zshrc` for zsh._ | |
179 | ||
180 | 4. Restart your shell as a login shell so the path changes take effect. | |
181 | You can now begin using rbenv. | |
187 | _Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._ | |
188 | ||
189 | 4. Restart your shell so that PATH changes take effect. (Opening a new | |
190 | terminal tab will usually do it.) Now check if rbenv was set up: | |
182 | 191 | |
183 | 192 | ~~~ sh |
184 | $ exec $SHELL -l | |
185 | ~~~ | |
186 | ||
187 | 5. Install [ruby-build](https://github.com/sstephenson/ruby-build), | |
188 | which provides an `rbenv install` command that simplifies the | |
189 | process of installing new Ruby versions. | |
190 | ||
191 | ~~~ | |
192 | $ rbenv install 1.9.3-p327 | |
193 | ~~~ | |
194 | ||
195 | As an alternative, you can download and compile Ruby yourself into | |
196 | `~/.rbenv/versions/`. | |
197 | ||
198 | 6. Rebuild the shim executables. You should do this any time you | |
199 | install a new Ruby executable (for example, when installing a new | |
200 | Ruby version, or when installing a gem that provides a command). | |
201 | ||
202 | ~~~ | |
203 | $ rbenv rehash | |
204 | ~~~ | |
193 | $ type rbenv | |
194 | #=> "rbenv is a function" | |
195 | ~~~ | |
196 | ||
197 | 5. _(Optional)_ Install [ruby-build][], which provides the | |
198 | `rbenv install` command that simplifies the process of | |
199 | [installing new Ruby versions](#installing-ruby-versions). | |
205 | 200 | |
206 | 201 | #### Upgrading |
207 | 202 | |
221 | 216 | $ git checkout v0.3.0 |
222 | 217 | ~~~ |
223 | 218 | |
219 | If you've [installed via Homebrew](#homebrew-on-mac-os-x), then upgrade | |
220 | via its `brew` command: | |
221 | ||
222 | ~~~ sh | |
223 | $ brew update | |
224 | $ brew upgrade rbenv ruby-build | |
225 | ~~~ | |
226 | ||
224 | 227 | ### Homebrew on Mac OS X |
225 | 228 | |
226 | You can also install rbenv using the | |
227 | [Homebrew](http://mxcl.github.com/homebrew/) package manager on Mac OS | |
228 | X. | |
229 | As an alternative to installation via GitHub checkout, you can install | |
230 | rbenv and [ruby-build][] using the [Homebrew](http://brew.sh) package | |
231 | manager on Mac OS X: | |
229 | 232 | |
230 | 233 | ~~~ |
231 | 234 | $ brew update |
232 | $ brew install rbenv | |
233 | $ brew install ruby-build | |
234 | ~~~ | |
235 | ||
236 | To later update these installs, use `upgrade` instead of `install`. | |
235 | $ brew install rbenv ruby-build | |
236 | ~~~ | |
237 | 237 | |
238 | 238 | Afterwards you'll still need to add `eval "$(rbenv init -)"` to your |
239 | 239 | profile as stated in the caveats. You'll only ever have to do this |
240 | 240 | once. |
241 | 241 | |
242 | ### Neckbeard Configuration | |
242 | ### How rbenv hooks into your shell | |
243 | 243 | |
244 | 244 | Skip this section unless you must know what every line in your shell |
245 | 245 | profile is doing. |
246 | 246 | |
247 | 247 | `rbenv init` is the only command that crosses the line of loading |
248 | extra commands into your shell. Coming from rvm, some of you might be | |
248 | extra commands into your shell. Coming from RVM, some of you might be | |
249 | 249 | opposed to this idea. Here's what `rbenv init` actually does: |
250 | 250 | |
251 | 251 | 1. Sets up your shims path. This is the only requirement for rbenv to |
258 | 258 | users. |
259 | 259 | |
260 | 260 | 3. Rehashes shims. From time to time you'll need to rebuild your |
261 | shim files. Doing this on init makes sure everything is up to | |
261 | shim files. Doing this automatically makes sure everything is up to | |
262 | 262 | date. You can always run `rbenv rehash` manually. |
263 | 263 | |
264 | 264 | 4. Installs the sh dispatcher. This bit is also optional, but allows |
271 | 271 | Run `rbenv init -` for yourself to see exactly what happens under the |
272 | 272 | hood. |
273 | 273 | |
274 | ### Installing Ruby Versions | |
275 | ||
276 | The `rbenv install` command doesn't ship with rbenv out of the box, but | |
277 | is provided by the [ruby-build][] project. If you installed it either | |
278 | as part of GitHub checkout process outlined above or via Homebrew, you | |
279 | should be able to: | |
280 | ||
281 | ~~~ sh | |
282 | # list all available versions: | |
283 | $ rbenv install -l | |
284 | ||
285 | # install a Ruby version: | |
286 | $ rbenv install 2.0.0-p247 | |
287 | ~~~ | |
288 | ||
289 | Alternatively to the `install` command, you can download and compile | |
290 | Ruby manually as a subdirectory of `~/.rbenv/versions/`. An entry in | |
291 | that directory can also be a symlink to a Ruby version installed | |
292 | elsewhere on the filesystem. rbenv doesn't care; it will simply treat | |
293 | any entry in the `versions/` directory as a separate Ruby version. | |
294 | ||
295 | #### Installing Ruby Gems | |
296 | ||
297 | Once you've installed some Ruby versions, you'll want to install gems. | |
298 | First, ensure that the target version for your project is the one you want by | |
299 | checking `rbenv version` (see [Command Reference](#command-reference)). Select | |
300 | another version using `rbenv local 2.0.0-p247`, for example. Then, proceed to | |
301 | install gems as you normally would: | |
302 | ||
303 | ```sh | |
304 | $ gem install bundler | |
305 | ``` | |
306 | ||
307 | **You don't need sudo** to install gems. Typically, the Ruby versions will be | |
308 | installed and writeable by your user. No extra privileges are required to | |
309 | install gems. | |
310 | ||
311 | Check the location where gems are being installed with `gem env`: | |
312 | ||
313 | ```sh | |
314 | $ gem env home | |
315 | # => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/... | |
316 | ``` | |
317 | ||
274 | 318 | ### Uninstalling Ruby Versions |
275 | 319 | |
276 | 320 | As time goes on, Ruby versions you install will accumulate in your |
278 | 322 | |
279 | 323 | To remove old Ruby versions, simply `rm -rf` the directory of the |
280 | 324 | version you want to remove. You can find the directory of a particular |
281 | Ruby verison with the `rbenv prefix` command, e.g. `rbenv prefix | |
325 | Ruby version with the `rbenv prefix` command, e.g. `rbenv prefix | |
282 | 326 | 1.8.7-p357`. |
283 | 327 | |
284 | The [ruby-build](https://github.com/sstephenson/ruby-build) plugin | |
285 | provides an `rbenv uninstall` command to automate the removal | |
286 | process. | |
328 | The [ruby-build][] plugin provides an `rbenv uninstall` command to | |
329 | automate the removal process. | |
330 | ||
331 | ### Uninstalling rbenv | |
332 | ||
333 | The simplicity of rbenv makes it easy to temporarily disable it, or | |
334 | uninstall from the system. | |
335 | ||
336 | 1. To **disable** rbenv managing your Ruby versions, simply remove the | |
337 | `rbenv init` line from your shell startup configuration. This will | |
338 | remove rbenv shims directory from PATH, and future invocations like | |
339 | `ruby` will execute the system Ruby version, as before rbenv. | |
340 | ||
341 | `rbenv` will still be accessible on the command line, but your Ruby | |
342 | apps won't be affected by version switching. | |
343 | ||
344 | 2. To completely **uninstall** rbenv, perform step (1) and then remove | |
345 | its root directory. This will **delete all Ruby versions** that were | |
346 | installed under `` `rbenv root`/versions/ `` directory: | |
347 | ||
348 | rm -rf `rbenv root` | |
349 | ||
350 | If you've installed rbenv using a package manager, as a final step | |
351 | perform the rbenv package removal. For instance, for Homebrew: | |
352 | ||
353 | brew uninstall rbenv | |
287 | 354 | |
288 | 355 | ## Command Reference |
289 | 356 | |
364 | 431 | how it was set. |
365 | 432 | |
366 | 433 | $ rbenv version |
367 | 1.8.7-p352 (set by /Volumes/37signals/basecamp/.ruby-version) | |
434 | 1.9.3-p327 (set by /Users/sam/.rbenv/version) | |
368 | 435 | |
369 | 436 | ### rbenv rehash |
370 | 437 | |
391 | 458 | jruby-1.7.1 |
392 | 459 | ree-1.8.7-2011.03 |
393 | 460 | |
461 | ## Environment variables | |
462 | ||
463 | You can affect how rbenv operates with the following settings: | |
464 | ||
465 | name | default | description | |
466 | -----|---------|------------ | |
467 | `RBENV_VERSION` | | Specifies the Ruby version to be used.<br>Also see [`rbenv shell`](#rbenv-shell) | |
468 | `RBENV_ROOT` | `~/.rbenv` | Defines the directory under which Ruby versions and shims reside.<br>Also see `rbenv root` | |
469 | `RBENV_DEBUG` | | Outputs debug information.<br>Also as: `rbenv --debug <subcommand>` | |
470 | `RBENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for rbenv hooks. | |
471 | `RBENV_DIR` | `$PWD` | Directory to start searching for `.ruby-version` files. | |
472 | ||
394 | 473 | ## Development |
395 | 474 | |
396 | 475 | The rbenv source code is [hosted on |
397 | GitHub](https://github.com/sstephenson/rbenv). It's clean, modular, | |
476 | GitHub](https://github.com/rbenv/rbenv). It's clean, modular, | |
398 | 477 | and easy to understand, even if you're not a shell hacker. |
399 | 478 | |
479 | Tests are executed using [Bats](https://github.com/sstephenson/bats): | |
480 | ||
481 | $ bats test | |
482 | $ bats test/<file>.bats | |
483 | ||
400 | 484 | Please feel free to submit pull requests and file bugs on the [issue |
401 | tracker](https://github.com/sstephenson/rbenv/issues). | |
402 | ||
403 | ### Version History | |
404 | ||
405 | **0.4.0** (January 4, 2013) | |
406 | ||
407 | * rbenv now prefers `.ruby-version` files to `.rbenv-version` files | |
408 | for specifying local application-specific versions. The | |
409 | `.ruby-version` file has the same format as `.rbenv-version` but is | |
410 | [compatible with other Ruby version | |
411 | managers](https://gist.github.com/1912050). | |
412 | * Deprecated `ruby-local-exec` and moved its functionality into the | |
413 | standard `ruby` shim. See the [ruby-local-exec wiki | |
414 | page](https://github.com/sstephenson/wiki/ruby-local-exec) for | |
415 | upgrade instructions. | |
416 | * Modified shims to include the full path to rbenv so that they can be | |
417 | invoked without having rbenv's bin directory in the `$PATH`. | |
418 | * Sped up `rbenv init` by avoiding rbenv reinintialization and by | |
419 | using a simpler indexing approach. (Users of | |
420 | [chef-rbenv](https://github.com/fnichol/chef-rbenv) should upgrade | |
421 | to the latest version to fix a [compatibility | |
422 | issue](https://github.com/fnichol/chef-rbenv/pull/26).) | |
423 | * Reworked `rbenv help` so that usage and documentation is stored as a | |
424 | comment in each subcommand, enabling plugin commands to hook into | |
425 | the help system. | |
426 | * Added support for full completion of the command line, not just the | |
427 | first argument. | |
428 | * Updated installation instructions for Zsh and Ubuntu users. | |
429 | * Fixed `rbenv which` and `rbenv prefix` with system Ruby versions. | |
430 | * Changed `rbenv exec` to avoid prepending the system Ruby location to | |
431 | `$PATH` to fix issues running system Ruby commands that invoke other | |
432 | commands. | |
433 | * Changed `rbenv rehash` to ensure it exits with a 0 status code under | |
434 | normal operation, and to ensure outdated shims are removed first | |
435 | when rehashing. | |
436 | * Modified `rbenv rehash` to run `hash -r` afterwards, when shell | |
437 | integration is enabled, to ensure the shell's command cache is | |
438 | cleared. | |
439 | * Removed use of the `+=` operator to support older versions of Bash. | |
440 | * Adjusted non-bare `rbenv versions` output to include `system`, if | |
441 | present. | |
442 | * Improved documentation for installing and uninstalling Ruby | |
443 | versions. | |
444 | * Fixed `rbenv versions` not to display a warning if the currently | |
445 | specified version doesn't exist. | |
446 | * Fixed an instance of local variable leakage in the `rbenv` shell | |
447 | function wrapper. | |
448 | * Changed `rbenv shell` to ensure it exits with a non-zero status on | |
449 | failure. | |
450 | * Added `rbenv --version` for printing the current version of rbenv. | |
451 | * Added `/usr/lib/rbenv/hooks` to the plugin hook search path. | |
452 | * Fixed `rbenv which` to account for path entries with spaces. | |
453 | * Changed `rbenv init` to accept option arguments in any order. | |
454 | ||
455 | **0.3.0** (December 25, 2011) | |
456 | ||
457 | * Added an `rbenv root` command which prints the value of | |
458 | `$RBENV_ROOT`, or the default root directory if it's unset. | |
459 | * Clarified Zsh installation instructions in the readme. | |
460 | * Removed some redundant code in `rbenv rehash`. | |
461 | * Fixed an issue with calling `readlink` for paths with spaces. | |
462 | * Changed Zsh initialization code to install completion hooks only for | |
463 | interactive shells. | |
464 | * Added preliminary support for ksh. | |
465 | * `rbenv rehash` creates or removes shims only when necessary instead | |
466 | of removing and re-creating all shims on each invocation. | |
467 | * Fixed that `RBENV_DIR`, when specified, would be incorrectly | |
468 | expanded to its parent directory. | |
469 | * Removed the deprecated `set-default` and `set-local` commands. | |
470 | * Added a `--no-rehash` option to `rbenv init` for skipping the | |
471 | automatic rehash when opening a new shell. | |
472 | ||
473 | **0.2.1** (October 1, 2011) | |
474 | ||
475 | * Changed the `rbenv` command to ensure that `RBENV_DIR` is always an | |
476 | absolute path. This fixes an issue where Ruby scripts using the | |
477 | `ruby-local-exec` wrapper would go into an infinite loop when | |
478 | invoked with a relative path from the command line. | |
479 | ||
480 | **0.2.0** (September 28, 2011) | |
481 | ||
482 | * Renamed `rbenv set-default` to `rbenv global` and `rbenv set-local` | |
483 | to `rbenv local`. The `set-` commands are deprecated and will be | |
484 | removed in the next major release. | |
485 | * rbenv now uses `greadlink` on Solaris. | |
486 | * Added a `ruby-local-exec` command which can be used in shebangs in | |
487 | place of `#!/usr/bin/env ruby` to properly set the project-specific | |
488 | Ruby version regardless of current working directory. | |
489 | * Fixed an issue with `rbenv rehash` when no binaries are present. | |
490 | * Added support for `rbenv-sh-*` commands, which run inside the | |
491 | current shell instead of in a child process. | |
492 | * Added an `rbenv shell` command for conveniently setting the | |
493 | `$RBENV_VERSION` environment variable. | |
494 | * Added support for storing rbenv versions and shims in directories | |
495 | other than `~/.rbenv` with the `$RBENV_ROOT` environment variable. | |
496 | * Added support for debugging rbenv via `set -x` when the | |
497 | `$RBENV_DEBUG` environment variable is set. | |
498 | * Refactored the autocompletion system so that completions are now | |
499 | built-in to each command and shared between bash and Zsh. | |
500 | * Added support for plugin bundles in `~/.rbenv/plugins` as documented | |
501 | in [issue #102](https://github.com/sstephenson/rbenv/pull/102). | |
502 | * Added `/usr/local/etc/rbenv.d` to the list of directories searched | |
503 | for rbenv hooks. | |
504 | * Added support for an `$RBENV_DIR` environment variable which | |
505 | defaults to the current working directory for specifying where rbenv | |
506 | searches for local version files. | |
507 | ||
508 | **0.1.2** (August 16, 2011) | |
509 | ||
510 | * Fixed rbenv to be more resilient against nonexistent entries in | |
511 | `$PATH`. | |
512 | * Made the `rbenv rehash` command operate atomically. | |
513 | * Modified the `rbenv init` script to automatically run `rbenv | |
514 | rehash` so that shims are recreated whenever a new shell is opened. | |
515 | * Added initial support for Zsh autocompletion. | |
516 | * Removed the dependency on egrep for reading version files. | |
517 | ||
518 | **0.1.1** (August 14, 2011) | |
519 | ||
520 | * Fixed a syntax error in the `rbenv help` command. | |
521 | * Removed `-e` from the shebang in favor of `set -e` at the top of | |
522 | each file for compatibility with operating systems that do not | |
523 | support more than one argument in the shebang. | |
524 | ||
525 | **0.1.0** (August 11, 2011) | |
526 | ||
527 | * Initial public release. | |
528 | ||
529 | ### License | |
530 | ||
531 | (The MIT license) | |
532 | ||
533 | Copyright (c) 2013 Sam Stephenson | |
534 | ||
535 | Permission is hereby granted, free of charge, to any person obtaining | |
536 | a copy of this software and associated documentation files (the | |
537 | "Software"), to deal in the Software without restriction, including | |
538 | without limitation the rights to use, copy, modify, merge, publish, | |
539 | distribute, sublicense, and/or sell copies of the Software, and to | |
540 | permit persons to whom the Software is furnished to do so, subject to | |
541 | the following conditions: | |
542 | ||
543 | The above copyright notice and this permission notice shall be | |
544 | included in all copies or substantial portions of the Software. | |
545 | ||
546 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
547 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
548 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
549 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
550 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
551 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
552 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
485 | tracker](https://github.com/rbenv/rbenv/issues). | |
486 | ||
487 | ||
488 | [ruby-build]: https://github.com/rbenv/ruby-build#readme | |
489 | [hooks]: https://github.com/rbenv/rbenv/wiki/Authoring-plugins#rbenv-hooks |
15 | 15 | |
16 | 16 | [ -n "$RBENV_SILENCE_WARNINGS" ] || { |
17 | 17 | echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release." |
18 | echo " To upgrade: https://github.com/sstephenson/rbenv/wiki/ruby-local-exec" | |
18 | echo " To upgrade: https://github.com/rbenv/rbenv/wiki/ruby-local-exec" | |
19 | 19 | echo |
20 | 20 | } >&2 |
21 | 21 |
0 | function __fish_rbenv_needs_command | |
1 | set cmd (commandline -opc) | |
2 | if [ (count $cmd) -eq 1 -a $cmd[1] = 'rbenv' ] | |
3 | return 0 | |
4 | end | |
5 | return 1 | |
6 | end | |
7 | ||
8 | function __fish_rbenv_using_command | |
9 | set cmd (commandline -opc) | |
10 | if [ (count $cmd) -gt 1 ] | |
11 | if [ $argv[1] = $cmd[2] ] | |
12 | return 0 | |
13 | end | |
14 | end | |
15 | return 1 | |
16 | end | |
17 | ||
18 | complete -f -c rbenv -n '__fish_rbenv_needs_command' -a '(rbenv commands)' | |
19 | for cmd in (rbenv commands) | |
20 | complete -f -c rbenv -n "__fish_rbenv_using_command $cmd" -a "(rbenv completions $cmd)" | |
21 | end |
10 | 10 | if [ "${#words}" -eq 2 ]; then |
11 | 11 | completions="$(rbenv commands)" |
12 | 12 | else |
13 | completions="$(rbenv completions ${words[2,-1]})" | |
13 | completions="$(rbenv completions ${words[2,-2]})" | |
14 | 14 | fi |
15 | 15 | |
16 | 16 | reply=("${(ps:\n:)completions}") |
0 | 0 | #!/usr/bin/env bash |
1 | 1 | set -e |
2 | [ -n "$RBENV_DEBUG" ] && set -x | |
2 | export -n CDPATH | |
3 | 3 | |
4 | resolve_link() { | |
5 | $(type -p greadlink readlink | head -1) "$1" | |
4 | if [ "$1" = "--debug" ]; then | |
5 | export RBENV_DEBUG=1 | |
6 | shift | |
7 | fi | |
8 | ||
9 | if [ -n "$RBENV_DEBUG" ]; then | |
10 | export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] ' | |
11 | set -x | |
12 | fi | |
13 | ||
14 | abort() { | |
15 | { if [ "$#" -eq 0 ]; then cat - | |
16 | else echo "rbenv: $*" | |
17 | fi | |
18 | } >&2 | |
19 | exit 1 | |
6 | 20 | } |
7 | 21 | |
8 | abs_dirname() { | |
9 | local cwd="$(pwd)" | |
10 | local path="$1" | |
22 | if enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then | |
23 | abs_dirname() { | |
24 | local path="$(realpath "$1")" | |
25 | echo "${path%/*}" | |
26 | } | |
27 | else | |
28 | [ -z "$RBENV_NATIVE_EXT" ] || abort "failed to load \`realpath' builtin" | |
11 | 29 | |
12 | while [ -n "$path" ]; do | |
13 | cd "${path%/*}" | |
14 | local name="${path##*/}" | |
15 | path="$(resolve_link "$name" || true)" | |
16 | done | |
30 | READLINK=$(type -p greadlink readlink | head -1) | |
31 | [ -n "$READLINK" ] || abort "cannot find readlink - are you missing GNU coreutils?" | |
17 | 32 | |
18 | pwd | |
19 | cd "$cwd" | |
20 | } | |
33 | resolve_link() { | |
34 | $READLINK "$1" | |
35 | } | |
36 | ||
37 | abs_dirname() { | |
38 | local cwd="$PWD" | |
39 | local path="$1" | |
40 | ||
41 | while [ -n "$path" ]; do | |
42 | cd "${path%/*}" | |
43 | local name="${path##*/}" | |
44 | path="$(resolve_link "$name" || true)" | |
45 | done | |
46 | ||
47 | pwd | |
48 | cd "$cwd" | |
49 | } | |
50 | fi | |
21 | 51 | |
22 | 52 | if [ -z "${RBENV_ROOT}" ]; then |
23 | 53 | RBENV_ROOT="${HOME}/.rbenv" |
27 | 57 | export RBENV_ROOT |
28 | 58 | |
29 | 59 | if [ -z "${RBENV_DIR}" ]; then |
30 | RBENV_DIR="$(pwd)" | |
60 | RBENV_DIR="$PWD" | |
31 | 61 | else |
32 | cd "$RBENV_DIR" 2>/dev/null || { | |
33 | echo "rbenv: cannot change working directory to \`$RBENV_DIR'" | |
34 | exit 1 | |
35 | } >&2 | |
36 | RBENV_DIR="$(pwd)" | |
62 | cd "$RBENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$RBENV_DIR'" | |
63 | RBENV_DIR="$PWD" | |
37 | 64 | cd "$OLDPWD" |
38 | 65 | fi |
39 | 66 | export RBENV_DIR |
43 | 70 | |
44 | 71 | bin_path="$(abs_dirname "$0")" |
45 | 72 | for plugin_bin in "${RBENV_ROOT}/plugins/"*/bin; do |
46 | bin_path="${bin_path}:${plugin_bin}" | |
73 | PATH="${plugin_bin}:${PATH}" | |
47 | 74 | done |
48 | 75 | export PATH="${bin_path}:${PATH}" |
49 | 76 | |
50 | hook_path="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" | |
77 | RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${RBENV_ROOT}/rbenv.d" | |
78 | if [ "${bin_path%/*}" != "$RBENV_ROOT" ]; then | |
79 | # Add rbenv's own `rbenv.d` unless rbenv was cloned to RBENV_ROOT | |
80 | RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${bin_path%/*}/rbenv.d" | |
81 | fi | |
82 | RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" | |
51 | 83 | for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do |
52 | hook_path="${hook_path}:${plugin_hook}" | |
84 | RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}" | |
53 | 85 | done |
54 | export RBENV_HOOK_PATH="$hook_path" | |
86 | RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}" | |
87 | export RBENV_HOOK_PATH | |
55 | 88 | |
56 | 89 | shopt -u nullglob |
57 | 90 | |
58 | 91 | |
59 | 92 | command="$1" |
60 | 93 | case "$command" in |
61 | "" | "-h" | "--help" ) | |
62 | echo -e "$(rbenv---version)\n$(rbenv-help)" >&2 | |
94 | "" ) | |
95 | { rbenv---version | |
96 | rbenv-help | |
97 | } | abort | |
63 | 98 | ;; |
64 | "-v" ) | |
99 | -v | --version ) | |
65 | 100 | exec rbenv---version |
101 | ;; | |
102 | -h | --help ) | |
103 | exec rbenv-help | |
66 | 104 | ;; |
67 | 105 | * ) |
68 | 106 | command_path="$(command -v "rbenv-$command" || true)" |
69 | if [ -z "$command_path" ]; then | |
70 | echo "rbenv: no such command \`$command'" >&2 | |
71 | exit 1 | |
72 | fi | |
107 | [ -n "$command_path" ] || abort "no such command \`$command'" | |
73 | 108 | |
74 | 109 | shift 1 |
75 | exec "$command_path" "$@" | |
110 | if [ "$1" = --help ]; then | |
111 | exec rbenv-help "$command" | |
112 | else | |
113 | exec "$command_path" "$@" | |
114 | fi | |
76 | 115 | ;; |
77 | 116 | esac |
11 | 11 | set -e |
12 | 12 | [ -n "$RBENV_DEBUG" ] && set -x |
13 | 13 | |
14 | version="0.4.0" | |
14 | version="1.0.0" | |
15 | git_revision="" | |
15 | 16 | |
16 | cd "$RBENV_ROOT" | |
17 | git_revision="$(git describe --tags HEAD 2>/dev/null || true)" | |
18 | git_revision="${git_revision#v}" | |
17 | if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then | |
18 | git_revision="$(git describe --tags HEAD 2>/dev/null || true)" | |
19 | git_revision="${git_revision#v}" | |
20 | fi | |
19 | 21 | |
20 | 22 | echo "rbenv ${git_revision:-$version}" |
19 | 19 | shift |
20 | 20 | fi |
21 | 21 | |
22 | IFS=: paths=($PATH) | |
23 | ||
22 | 24 | shopt -s nullglob |
23 | 25 | |
24 | { for path in ${PATH//:/$'\n'}; do | |
26 | { for path in "${paths[@]}"; do | |
25 | 27 | for command in "${path}/rbenv-"*; do |
26 | 28 | command="${command##*rbenv-}" |
27 | 29 | if [ -n "$sh" ]; then |
9 | 9 | exit 1 |
10 | 10 | fi |
11 | 11 | |
12 | # Provide rbenv completions | |
13 | if [ "$COMMAND" = "--complete" ]; then | |
14 | exec rbenv-commands | |
15 | fi | |
16 | ||
12 | 17 | COMMAND_PATH="$(command -v "rbenv-$COMMAND" || command -v "rbenv-sh-$COMMAND")" |
13 | if grep -i "^# provide rbenv completions" "$COMMAND_PATH" >/dev/null; then | |
18 | ||
19 | # --help is provided automatically | |
20 | echo --help | |
21 | ||
22 | if grep -iE "^([#%]|--|//) provide rbenv completions" "$COMMAND_PATH" >/dev/null; then | |
14 | 23 | shift |
15 | 24 | exec "$COMMAND_PATH" --complete "$@" |
16 | 25 | fi |
17 | 17 | |
18 | 18 | # Provide rbenv completions |
19 | 19 | if [ "$1" = "--complete" ]; then |
20 | exec rbenv shims --short | |
20 | exec rbenv-shims --short | |
21 | 21 | fi |
22 | 22 | |
23 | export RBENV_VERSION="$(rbenv-version-name)" | |
23 | RBENV_VERSION="$(rbenv-version-name)" | |
24 | 24 | RBENV_COMMAND="$1" |
25 | 25 | |
26 | 26 | if [ -z "$RBENV_COMMAND" ]; then |
28 | 28 | exit 1 |
29 | 29 | fi |
30 | 30 | |
31 | export RBENV_VERSION | |
31 | 32 | RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" |
32 | 33 | RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" |
33 | 34 | |
34 | for script in $(rbenv-hooks exec); do | |
35 | OLDIFS="$IFS" | |
36 | IFS=$'\n' scripts=(`rbenv-hooks exec`) | |
37 | IFS="$OLDIFS" | |
38 | for script in "${scripts[@]}"; do | |
35 | 39 | source "$script" |
36 | 40 | done |
37 | 41 |
13 | 13 | |
14 | 14 | set -e |
15 | 15 | [ -n "$RBENV_DEBUG" ] && set -x |
16 | ||
17 | # Provide rbenv completions | |
18 | if [ "$1" = "--complete" ]; then | |
19 | echo --usage | |
20 | exec rbenv-commands | |
21 | fi | |
16 | 22 | |
17 | 23 | command_path() { |
18 | 24 | local command="$1" |
35 | 41 | } |
36 | 42 | |
37 | 43 | collect_documentation() { |
38 | awk ' | |
44 | $(type -p gawk awk | head -1) ' | |
39 | 45 | /^Summary:/ { |
40 | 46 | summary = substr($0, 10) |
41 | 47 | next |
63 | 69 | } |
64 | 70 | |
65 | 71 | function trim(str) { |
66 | gsub(/^\n*/, "", str) | |
67 | gsub(/\n*$/, "", str) | |
72 | sub(/^\n*/, "", str) | |
73 | sub(/\n*$/, "", str) | |
68 | 74 | return str |
69 | 75 | } |
70 | 76 | |
145 | 151 | print_summaries commands local global shell install uninstall rehash version versions which whence |
146 | 152 | echo |
147 | 153 | echo "See \`rbenv help <command>' for information on a specific command." |
148 | echo "For full documentation, see: https://github.com/sstephenson/rbenv#readme" | |
154 | echo "For full documentation, see: https://github.com/rbenv/rbenv#readme" | |
149 | 155 | else |
150 | 156 | command="$1" |
151 | 157 | if [ -n "$(command_path "$command")" ]; then |
8 | 8 | if [ "$1" = "--complete" ]; then |
9 | 9 | echo exec |
10 | 10 | echo rehash |
11 | echo version-name | |
12 | echo version-origin | |
11 | 13 | echo which |
12 | 14 | exit |
13 | 15 | fi |
18 | 20 | exit 1 |
19 | 21 | fi |
20 | 22 | |
23 | if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then | |
24 | if [ -n "$RBENV_NATIVE_EXT" ]; then | |
25 | echo "rbenv: failed to load \`realpath' builtin" >&2 | |
26 | exit 1 | |
27 | fi | |
28 | READLINK=$(type -p greadlink readlink | head -1) | |
29 | if [ -z "$READLINK" ]; then | |
30 | echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 | |
31 | exit 1 | |
32 | fi | |
33 | ||
21 | 34 | resolve_link() { |
22 | $(type -p greadlink readlink | head -1) $1 | |
35 | $READLINK "$1" | |
23 | 36 | } |
24 | 37 | |
25 | 38 | realpath() { |
26 | local cwd="$(pwd)" | |
27 | local base="$(basename $1)" | |
39 | local cwd="$PWD" | |
28 | 40 | local path="$1" |
41 | local name | |
29 | 42 | |
30 | 43 | while [ -n "$path" ]; do |
31 | cd "${path%/*}" | |
32 | local name="${path##*/}" | |
44 | name="${path##*/}" | |
45 | [ "$name" = "$path" ] || cd "${path%/*}" | |
33 | 46 | path="$(resolve_link "$name" || true)" |
34 | 47 | done |
35 | 48 | |
36 | echo "$(pwd)/$base" | |
49 | echo "${PWD}/$name" | |
37 | 50 | cd "$cwd" |
38 | 51 | } |
52 | fi | |
53 | ||
54 | IFS=: hook_paths=($RBENV_HOOK_PATH) | |
39 | 55 | |
40 | 56 | shopt -s nullglob |
41 | for path in ${RBENV_HOOK_PATH//:/$'\n'}; do | |
42 | for script in $path/"$RBENV_COMMAND"/*.bash; do | |
43 | echo $(realpath $script) | |
57 | for path in "${hook_paths[@]}"; do | |
58 | for script in "$path/$RBENV_COMMAND"/*.bash; do | |
59 | realpath "$script" | |
44 | 60 | done |
45 | 61 | done |
46 | 62 | shopt -u nullglob |
4 | 4 | set -e |
5 | 5 | [ -n "$RBENV_DEBUG" ] && set -x |
6 | 6 | |
7 | # Provide rbenv completions | |
8 | if [ "$1" = "--complete" ]; then | |
9 | echo - | |
10 | echo --no-rehash | |
11 | echo bash | |
12 | echo fish | |
13 | echo ksh | |
14 | echo zsh | |
15 | exit | |
16 | fi | |
17 | ||
7 | 18 | print="" |
8 | 19 | no_rehash="" |
9 | 20 | for args in "$@" |
10 | 21 | do |
11 | 22 | if [ "$args" = "-" ]; then |
12 | 23 | print=1 |
13 | shift | |
24 | shift | |
14 | 25 | fi |
15 | 26 | |
16 | 27 | if [ "$args" = "--no-rehash" ]; then |
21 | 32 | |
22 | 33 | shell="$1" |
23 | 34 | if [ -z "$shell" ]; then |
24 | shell="$(basename "$SHELL")" | |
35 | shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" | |
36 | shell="${shell%% *}" | |
37 | shell="${shell##-}" | |
38 | shell="${shell:-$SHELL}" | |
39 | shell="${shell##*/}" | |
25 | 40 | fi |
26 | 41 | |
27 | resolve_link() { | |
28 | $(type -p greadlink readlink | head -1) $1 | |
29 | } | |
30 | ||
31 | abs_dirname() { | |
32 | local cwd="$(pwd)" | |
33 | local path="$1" | |
34 | ||
35 | while [ -n "$path" ]; do | |
36 | cd "${path%/*}" | |
37 | local name="${path##*/}" | |
38 | path="$(resolve_link "$name" || true)" | |
39 | done | |
40 | ||
41 | pwd | |
42 | cd "$cwd" | |
43 | } | |
44 | ||
45 | root="$(abs_dirname "$0")/.." | |
42 | root="${0%/*}/.." | |
46 | 43 | |
47 | 44 | if [ -z "$print" ]; then |
48 | 45 | case "$shell" in |
49 | 46 | bash ) |
50 | profile='~/.bash_profile' | |
47 | if [ -f "${HOME}/.bashrc" ] && [ ! -f "${HOME}/.bash_profile" ]; then | |
48 | profile='~/.bashrc' | |
49 | else | |
50 | profile='~/.bash_profile' | |
51 | fi | |
51 | 52 | ;; |
52 | 53 | zsh ) |
53 | 54 | profile='~/.zshrc' |
55 | 56 | ksh ) |
56 | 57 | profile='~/.profile' |
57 | 58 | ;; |
59 | fish ) | |
60 | profile='~/.config/fish/config.fish' | |
61 | ;; | |
58 | 62 | * ) |
59 | 63 | profile='your profile' |
60 | 64 | ;; |
61 | 65 | esac |
62 | 66 | |
63 | { echo "# Load rbenv automatically by adding" | |
67 | { echo "# Load rbenv automatically by appending" | |
64 | 68 | echo "# the following to ${profile}:" |
65 | 69 | echo |
66 | echo 'eval "$(rbenv init -)"' | |
70 | case "$shell" in | |
71 | fish ) | |
72 | echo 'status --is-interactive; and . (rbenv init -|psub)' | |
73 | ;; | |
74 | * ) | |
75 | echo 'eval "$(rbenv init -)"' | |
76 | ;; | |
77 | esac | |
67 | 78 | echo |
68 | 79 | } >&2 |
69 | 80 | |
72 | 83 | |
73 | 84 | mkdir -p "${RBENV_ROOT}/"{shims,versions} |
74 | 85 | |
75 | echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' | |
86 | case "$shell" in | |
87 | fish ) | |
88 | echo "setenv PATH '${RBENV_ROOT}/shims' \$PATH" | |
89 | echo "setenv RBENV_SHELL $shell" | |
90 | ;; | |
91 | * ) | |
92 | echo 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' | |
93 | echo "export RBENV_SHELL=$shell" | |
94 | ;; | |
95 | esac | |
76 | 96 | |
97 | completion="${root}/completions/rbenv.${shell}" | |
98 | if [ -r "$completion" ]; then | |
99 | case "$shell" in | |
100 | fish ) echo ". '$completion'" ;; | |
101 | * ) echo "source '$completion'" ;; | |
102 | esac | |
103 | fi | |
104 | ||
105 | if [ -z "$no_rehash" ]; then | |
106 | echo 'command rbenv rehash 2>/dev/null' | |
107 | fi | |
108 | ||
109 | commands=(`rbenv-commands --sh`) | |
77 | 110 | case "$shell" in |
78 | bash | zsh ) | |
79 | echo "source \"$root/completions/rbenv.${shell}\"" | |
111 | fish ) | |
112 | cat <<EOS | |
113 | function rbenv | |
114 | set command \$argv[1] | |
115 | set -e argv[1] | |
116 | ||
117 | switch "\$command" | |
118 | case ${commands[*]} | |
119 | . (rbenv "sh-\$command" \$argv|psub) | |
120 | case '*' | |
121 | command rbenv "\$command" \$argv | |
122 | end | |
123 | end | |
124 | EOS | |
125 | ;; | |
126 | ksh ) | |
127 | cat <<EOS | |
128 | function rbenv { | |
129 | typeset command | |
130 | EOS | |
131 | ;; | |
132 | * ) | |
133 | cat <<EOS | |
134 | rbenv() { | |
135 | local command | |
136 | EOS | |
80 | 137 | ;; |
81 | 138 | esac |
82 | 139 | |
83 | if [ -z "$no_rehash" ]; then | |
84 | echo 'rbenv rehash 2>/dev/null' | |
85 | fi | |
86 | ||
87 | commands=(`rbenv-commands --sh`) | |
140 | if [ "$shell" != "fish" ]; then | |
88 | 141 | IFS="|" |
89 | 142 | cat <<EOS |
90 | rbenv() { | |
91 | typeset command | |
92 | 143 | command="\$1" |
93 | 144 | if [ "\$#" -gt 0 ]; then |
94 | 145 | shift |
96 | 147 | |
97 | 148 | case "\$command" in |
98 | 149 | ${commands[*]}) |
99 | eval \`rbenv "sh-\$command" "\$@"\`;; | |
150 | eval "\$(rbenv "sh-\$command" "\$@")";; | |
100 | 151 | *) |
101 | 152 | command rbenv "\$command" "\$@";; |
102 | 153 | esac |
103 | 154 | } |
104 | 155 | EOS |
156 | fi |
37 | 37 | if [ "$RBENV_VERSION" = "--unset" ]; then |
38 | 38 | rm -f .ruby-version .rbenv-version |
39 | 39 | elif [ -n "$RBENV_VERSION" ]; then |
40 | if [ "$(RBENV_VERSION= rbenv-version-origin)" -ef .rbenv-version ]; then | |
40 | previous_file="$(RBENV_VERSION= rbenv-version-origin || true)" | |
41 | rbenv-version-file-write .ruby-version "$RBENV_VERSION" | |
42 | if [ "$previous_file" -ef .rbenv-version ]; then | |
41 | 43 | rm -f .rbenv-version |
42 | 44 | { echo "rbenv: removed existing \`.rbenv-version' file and migrated" |
43 | 45 | echo " local version specification to \`.ruby-version' file" |
44 | 46 | } >&2 |
45 | 47 | fi |
46 | rbenv-version-file-write .ruby-version "$RBENV_VERSION" | |
47 | 48 | else |
48 | rbenv-version-file-read .ruby-version || | |
49 | rbenv-version-file-read .rbenv-version || | |
50 | { echo "rbenv: no local version configured for this directory" | |
49 | if version_file="$(rbenv-version-file "$PWD")"; then | |
50 | rbenv-version-file-read "$version_file" | |
51 | else | |
52 | echo "rbenv: no local version configured for this directory" >&2 | |
51 | 53 | exit 1 |
52 | } >&2 | |
54 | fi | |
53 | 55 | fi |
21 | 21 | fi |
22 | 22 | |
23 | 23 | if [ "$RBENV_VERSION" = "system" ]; then |
24 | RUBY_PATH="$(rbenv-which ruby)" | |
25 | RUBY_PATH="${RUBY_PATH%/*}" | |
26 | echo "${RUBY_PATH%/bin}" | |
27 | exit | |
24 | if RUBY_PATH="$(rbenv-which ruby 2>/dev/null)"; then | |
25 | RUBY_PATH="${RUBY_PATH%/*}" | |
26 | echo "${RUBY_PATH%/bin}" | |
27 | exit | |
28 | else | |
29 | echo "rbenv: system version not found in PATH" >&2 | |
30 | exit 1 | |
31 | fi | |
28 | 32 | fi |
29 | 33 | |
30 | 34 | RBENV_PREFIX_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}" |
16 | 16 | set -o noclobber |
17 | 17 | { echo > "$PROTOTYPE_SHIM_PATH" |
18 | 18 | } 2>/dev/null || |
19 | { echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" | |
19 | { if [ -w "$SHIM_PATH" ]; then | |
20 | echo "rbenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" | |
21 | else | |
22 | echo "rbenv: cannot rehash: $SHIM_PATH isn't writable" | |
23 | fi | |
20 | 24 | exit 1 |
21 | 25 | } >&2 |
22 | 26 | set +o noclobber |
65 | 69 | # of the first shim in the shims directory, assume rbenv has been |
66 | 70 | # upgraded and the existing shims need to be removed. |
67 | 71 | remove_outdated_shims() { |
68 | for shim in *; do | |
72 | local shim | |
73 | for shim in "$SHIM_PATH"/*; do | |
69 | 74 | if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then |
70 | for shim in *; do rm -f "$shim"; done | |
75 | rm -f "$SHIM_PATH"/* | |
71 | 76 | fi |
72 | 77 | break |
78 | done | |
79 | } | |
80 | ||
81 | # List basenames of executables for every Ruby version | |
82 | list_executable_names() { | |
83 | local version file | |
84 | rbenv-versions --bare --skip-aliases | \ | |
85 | while read version; do | |
86 | for file in "${RBENV_ROOT}/versions/${version}/bin/"*; do | |
87 | echo "${file##*/}" | |
88 | done | |
73 | 89 | done |
74 | 90 | } |
75 | 91 | |
77 | 93 | # registered for installation as a shim. In this way, plugins may call |
78 | 94 | # `make_shims` with a glob to register many shims at once. |
79 | 95 | make_shims() { |
80 | local shims="$@" | |
81 | ||
82 | for file in $shims; do | |
83 | local shim="${file##*/}" | |
96 | local file shim | |
97 | for file; do | |
98 | shim="${file##*/}" | |
84 | 99 | register_shim "$shim" |
85 | 100 | done |
86 | 101 | } |
87 | 102 | |
88 | # Create an empty array for the list of registered shims and an empty | |
89 | # string to use as a search index. | |
90 | registered_shims=() | |
91 | registered_shims_index="" | |
103 | registered_shims=" " | |
92 | 104 | |
93 | # We will keep track of shims registered for installation with the | |
94 | # global `reigstered_shims` array and with a global search index | |
95 | # string. The array will let us iterate over all registered shims. The | |
96 | # index string will let us quickly check whether a shim with the given | |
97 | # name has been registered or not. | |
105 | # Registers the name of a shim to be generated. | |
98 | 106 | register_shim() { |
99 | local shim="$@" | |
100 | registered_shims["${#registered_shims[@]}"]="$shim" | |
101 | registered_shims_index="$registered_shims_index/$shim/" | |
107 | registered_shims="${registered_shims}${1} " | |
102 | 108 | } |
103 | 109 | |
104 | # To install all the registered shims, we iterate over the | |
105 | # `registered_shims` array and create a link if one does not already | |
106 | # exist. | |
110 | # Install all the shims registered via `make_shims` or `register_shim` directly. | |
107 | 111 | install_registered_shims() { |
108 | local shim | |
109 | for shim in "${registered_shims[@]}"; do | |
110 | [ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim" | |
112 | local shim file | |
113 | for shim in $registered_shims; do | |
114 | file="${SHIM_PATH}/${shim}" | |
115 | [ -e "$file" ] || cp "$PROTOTYPE_SHIM_PATH" "$file" | |
111 | 116 | done |
112 | 117 | } |
113 | 118 | |
117 | 122 | # removed. |
118 | 123 | remove_stale_shims() { |
119 | 124 | local shim |
120 | for shim in *; do | |
121 | if [[ "$registered_shims_index" != *"/$shim/"* ]]; then | |
125 | for shim in "$SHIM_PATH"/*; do | |
126 | if [[ "$registered_shims" != *" ${shim##*/} "* ]]; then | |
122 | 127 | rm -f "$shim" |
123 | 128 | fi |
124 | 129 | done |
125 | 130 | } |
126 | 131 | |
127 | ||
128 | # Change to the shims directory. | |
129 | cd "$SHIM_PATH" | |
130 | 132 | shopt -s nullglob |
131 | 133 | |
132 | 134 | # Create the prototype shim, then register shims for all known |
133 | 135 | # executables. |
134 | 136 | create_prototype_shim |
135 | 137 | remove_outdated_shims |
136 | make_shims ../versions/*/bin/* | |
138 | make_shims $(list_executable_names | sort -u) | |
137 | 139 | |
138 | # Restore the previous working directory. | |
139 | cd "$OLDPWD" | |
140 | 140 | |
141 | 141 | # Allow plugins to register shims. |
142 | for script in $(rbenv-hooks rehash); do | |
142 | OLDIFS="$IFS" | |
143 | IFS=$'\n' scripts=(`rbenv-hooks rehash`) | |
144 | IFS="$OLDIFS" | |
145 | ||
146 | for script in "${scripts[@]}"; do | |
143 | 147 | source "$script" |
144 | 148 | done |
145 | 149 | |
146 | # Change back to the shims directory to install the registered shims | |
147 | # and remove stale shims. | |
148 | cd "$SHIM_PATH" | |
149 | 150 | install_registered_shims |
150 | 151 | remove_stale_shims |
6 | 6 | exec rbenv-rehash --complete |
7 | 7 | fi |
8 | 8 | |
9 | shell="$(basename "${RBENV_SHELL:-$SHELL}")" | |
10 | ||
9 | 11 | # When rbenv shell integration is enabled, delegate to rbenv-rehash, |
10 | 12 | # then tell the shell to empty its command lookup cache. |
11 | 13 | rbenv-rehash |
12 | echo "hash -r" | |
14 | ||
15 | case "$shell" in | |
16 | fish ) | |
17 | # no rehash support | |
18 | ;; | |
19 | * ) | |
20 | echo "hash -r 2>/dev/null || true" | |
21 | ;; | |
22 | esac |
23 | 23 | fi |
24 | 24 | |
25 | 25 | version="$1" |
26 | shell="$(basename "${RBENV_SHELL:-$SHELL}")" | |
26 | 27 | |
27 | 28 | if [ -z "$version" ]; then |
28 | 29 | if [ -z "$RBENV_VERSION" ]; then |
35 | 36 | fi |
36 | 37 | |
37 | 38 | if [ "$version" = "--unset" ]; then |
38 | echo "unset RBENV_VERSION" | |
39 | case "$shell" in | |
40 | fish ) | |
41 | echo "set -e RBENV_VERSION" | |
42 | ;; | |
43 | * ) | |
44 | echo "unset RBENV_VERSION" | |
45 | ;; | |
46 | esac | |
39 | 47 | exit |
40 | 48 | fi |
41 | 49 | |
42 | 50 | # Make sure the specified version is installed. |
43 | 51 | if rbenv-prefix "$version" >/dev/null; then |
44 | echo "export RBENV_VERSION=\"${version}\"" | |
52 | case "$shell" in | |
53 | fish ) | |
54 | echo "setenv RBENV_VERSION \"${version}\"" | |
55 | ;; | |
56 | * ) | |
57 | echo "export RBENV_VERSION=\"${version}\"" | |
58 | ;; | |
59 | esac | |
45 | 60 | else |
46 | echo "return 1" | |
61 | echo "false" | |
47 | 62 | exit 1 |
48 | 63 | fi |
10 | 10 | exit |
11 | 11 | fi |
12 | 12 | |
13 | shopt -s nullglob | |
14 | ||
13 | 15 | for command in "${RBENV_ROOT}/shims/"*; do |
14 | 16 | if [ "$1" = "--short" ]; then |
15 | 17 | echo "${command##*/}" |
0 | 0 | #!/usr/bin/env bash |
1 | # Usage: rbenv version-file [<dir>] | |
1 | 2 | # Summary: Detect the file that sets the current rbenv version |
2 | 3 | set -e |
3 | 4 | [ -n "$RBENV_DEBUG" ] && set -x |
4 | 5 | |
6 | target_dir="$1" | |
7 | ||
5 | 8 | find_local_version_file() { |
6 | 9 | local root="$1" |
7 | while [ -n "$root" ]; do | |
10 | while ! [[ "$root" =~ ^//[^/]*$ ]]; do | |
8 | 11 | if [ -e "${root}/.ruby-version" ]; then |
9 | 12 | echo "${root}/.ruby-version" |
10 | exit | |
13 | return 0 | |
11 | 14 | elif [ -e "${root}/.rbenv-version" ]; then |
12 | 15 | echo "${root}/.rbenv-version" |
13 | exit | |
16 | return 0 | |
14 | 17 | fi |
18 | [ -n "$root" ] || break | |
15 | 19 | root="${root%/*}" |
16 | 20 | done |
21 | return 1 | |
17 | 22 | } |
18 | 23 | |
19 | find_local_version_file "$RBENV_DIR" | |
20 | [ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" | |
24 | find_global_version_file() { | |
25 | local global_version_file="${RBENV_ROOT}/version" | |
21 | 26 | |
22 | global_version_file="${RBENV_ROOT}/version" | |
27 | if [ -e "$global_version_file" ]; then | |
28 | echo "$global_version_file" | |
29 | elif [ -e "${RBENV_ROOT}/global" ]; then | |
30 | echo "${RBENV_ROOT}/global" | |
31 | elif [ -e "${RBENV_ROOT}/default" ]; then | |
32 | echo "${RBENV_ROOT}/default" | |
33 | else | |
34 | echo "$global_version_file" | |
35 | fi | |
36 | } | |
23 | 37 | |
24 | if [ -e "$global_version_file" ]; then | |
25 | echo "$global_version_file" | |
26 | elif [ -e "${RBENV_ROOT}/global" ]; then | |
27 | echo "${RBENV_ROOT}/global" | |
28 | elif [ -e "${RBENV_ROOT}/default" ]; then | |
29 | echo "${RBENV_ROOT}/default" | |
38 | if [ -n "$target_dir" ]; then | |
39 | find_local_version_file "$target_dir" | |
30 | 40 | else |
31 | echo "$global_version_file" | |
41 | find_local_version_file "$RBENV_DIR" || { | |
42 | [ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD" | |
43 | } || find_global_version_file | |
32 | 44 | fi |
7 | 7 | if [ -e "$VERSION_FILE" ]; then |
8 | 8 | # Read the first non-whitespace word from the specified version file. |
9 | 9 | # Be careful not to load it whole in case there's something crazy in it. |
10 | version="" | |
11 | while read -a words; do | |
12 | word="${words[0]}" | |
13 | if [ -z "$version" ] && [ -n "$word" ]; then | |
14 | version="$word" | |
15 | fi | |
16 | done < <( cat "$VERSION_FILE" && echo ) | |
10 | IFS="${IFS}"$'\r' | |
11 | words=( $(cut -b 1-1024 "$VERSION_FILE") ) | |
12 | version="${words[0]}" | |
17 | 13 | |
18 | 14 | if [ -n "$version" ]; then |
19 | 15 | echo "$version" |
6 | 6 | RBENV_VERSION_FILE="$(rbenv-version-file)" |
7 | 7 | RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" |
8 | 8 | fi |
9 | ||
10 | OLDIFS="$IFS" | |
11 | IFS=$'\n' scripts=(`rbenv-hooks version-name`) | |
12 | IFS="$OLDIFS" | |
13 | for script in "${scripts[@]}"; do | |
14 | source "$script" | |
15 | done | |
9 | 16 | |
10 | 17 | if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then |
11 | 18 | echo "system" |
20 | 27 | if version_exists "$RBENV_VERSION"; then |
21 | 28 | echo "$RBENV_VERSION" |
22 | 29 | elif version_exists "${RBENV_VERSION#ruby-}"; then |
23 | { echo "warning: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'" | |
24 | echo " (set by $(rbenv-version-origin))" | |
25 | } >&2 | |
26 | 30 | echo "${RBENV_VERSION#ruby-}" |
27 | 31 | else |
28 | echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2 | |
32 | echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 | |
29 | 33 | exit 1 |
30 | 34 | fi |
2 | 2 | set -e |
3 | 3 | [ -n "$RBENV_DEBUG" ] && set -x |
4 | 4 | |
5 | if [ -n "$RBENV_VERSION" ]; then | |
5 | unset RBENV_VERSION_ORIGIN | |
6 | ||
7 | OLDIFS="$IFS" | |
8 | IFS=$'\n' scripts=(`rbenv-hooks version-origin`) | |
9 | IFS="$OLDIFS" | |
10 | for script in "${scripts[@]}"; do | |
11 | source "$script" | |
12 | done | |
13 | ||
14 | if [ -n "$RBENV_VERSION_ORIGIN" ]; then | |
15 | echo "$RBENV_VERSION_ORIGIN" | |
16 | elif [ -n "$RBENV_VERSION" ]; then | |
6 | 17 | echo "RBENV_VERSION environment variable" |
7 | 18 | else |
8 | 19 | rbenv-version-file |
0 | 0 | #!/usr/bin/env bash |
1 | 1 | # Summary: List all Ruby versions available to rbenv |
2 | # Usage: rbenv versions [--bare] | |
2 | # Usage: rbenv versions [--bare] [--skip-aliases] | |
3 | 3 | # |
4 | 4 | # Lists all Ruby versions found in `$RBENV_ROOT/versions/*'. |
5 | 5 | |
6 | 6 | set -e |
7 | 7 | [ -n "$RBENV_DEBUG" ] && set -x |
8 | 8 | |
9 | if [ "$1" = "--bare" ]; then | |
9 | unset bare | |
10 | unset skip_aliases | |
11 | # Provide rbenv completions | |
12 | for arg; do | |
13 | case "$arg" in | |
14 | --complete ) | |
15 | echo --bare | |
16 | echo --skip-aliases | |
17 | exit ;; | |
18 | --bare ) bare=1 ;; | |
19 | --skip-aliases ) skip_aliases=1 ;; | |
20 | * ) | |
21 | rbenv-help --usage versions >&2 | |
22 | exit 1 | |
23 | ;; | |
24 | esac | |
25 | done | |
26 | ||
27 | versions_dir="${RBENV_ROOT}/versions" | |
28 | ||
29 | if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then | |
30 | if [ -n "$RBENV_NATIVE_EXT" ]; then | |
31 | echo "rbenv: failed to load \`realpath' builtin" >&2 | |
32 | exit 1 | |
33 | fi | |
34 | ||
35 | READLINK=$(type -p greadlink readlink | head -1) | |
36 | if [ -z "$READLINK" ]; then | |
37 | echo "rbenv: cannot find readlink - are you missing GNU coreutils?" >&2 | |
38 | exit 1 | |
39 | fi | |
40 | ||
41 | resolve_link() { | |
42 | $READLINK "$1" | |
43 | } | |
44 | ||
45 | realpath() { | |
46 | local cwd="$PWD" | |
47 | local path="$1" | |
48 | local name | |
49 | ||
50 | while [ -n "$path" ]; do | |
51 | name="${path##*/}" | |
52 | [ "$name" = "$path" ] || cd "${path%/*}" | |
53 | path="$(resolve_link "$name" || true)" | |
54 | done | |
55 | ||
56 | echo "${PWD}/$name" | |
57 | cd "$cwd" | |
58 | } | |
59 | fi | |
60 | ||
61 | if [ -d "$versions_dir" ]; then | |
62 | versions_dir="$(realpath "$versions_dir")" | |
63 | fi | |
64 | ||
65 | if [ -n "$bare" ]; then | |
10 | 66 | hit_prefix="" |
11 | 67 | miss_prefix="" |
12 | 68 | current_version="" |
18 | 74 | include_system="1" |
19 | 75 | fi |
20 | 76 | |
77 | num_versions=0 | |
78 | ||
21 | 79 | print_version() { |
22 | 80 | if [ "$1" == "$current_version" ]; then |
23 | 81 | echo "${hit_prefix}$(rbenv-version 2>/dev/null)" |
24 | 82 | else |
25 | 83 | echo "${miss_prefix}$1" |
26 | 84 | fi |
85 | num_versions=$((num_versions + 1)) | |
27 | 86 | } |
28 | 87 | |
29 | 88 | # Include "system" in the non-bare output, if it exists |
31 | 90 | print_version system |
32 | 91 | fi |
33 | 92 | |
34 | for path in "${RBENV_ROOT}/versions/"*; do | |
93 | shopt -s nullglob | |
94 | for path in "$versions_dir"/*; do | |
35 | 95 | if [ -d "$path" ]; then |
96 | if [ -n "$skip_aliases" ] && [ -L "$path" ]; then | |
97 | target="$(realpath "$path")" | |
98 | [ "${target%/*}" != "$versions_dir" ] || continue | |
99 | fi | |
36 | 100 | print_version "${path##*/}" |
37 | 101 | fi |
38 | 102 | done |
103 | shopt -u nullglob | |
104 | ||
105 | if [ "$num_versions" -eq 0 ] && [ -n "$include_system" ]; then | |
106 | echo "Warning: no Ruby detected on the system" >&2 | |
107 | exit 1 | |
108 | fi |
7 | 7 | # Provide rbenv completions |
8 | 8 | if [ "$1" = "--complete" ]; then |
9 | 9 | echo --path |
10 | exec rbenv shims --short | |
10 | exec rbenv-shims --short | |
11 | 11 | fi |
12 | 12 | |
13 | 13 | if [ "$1" = "--path" ]; then |
11 | 11 | |
12 | 12 | # Provide rbenv completions |
13 | 13 | if [ "$1" = "--complete" ]; then |
14 | exec rbenv shims --short | |
14 | exec rbenv-shims --short | |
15 | 15 | fi |
16 | 16 | |
17 | expand_path() { | |
18 | if [ ! -d "$1" ]; then | |
19 | return 1 | |
20 | fi | |
21 | ||
22 | local cwd="$(pwd)" | |
23 | cd "$1" | |
24 | pwd | |
25 | cd "$cwd" | |
17 | remove_from_path() { | |
18 | local path_to_remove="$1" | |
19 | local path_before | |
20 | local result=":$PATH:" | |
21 | while [ "$path_before" != "$result" ]; do | |
22 | path_before="$result" | |
23 | result="${result//:$path_to_remove:/:}" | |
24 | done | |
25 | result="${result%:}" | |
26 | echo "${result#:}" | |
26 | 27 | } |
27 | 28 | |
28 | remove_from_path() { | |
29 | local path_to_remove="$(expand_path "$1")" | |
30 | local result="" | |
31 | ||
32 | if [ -z "$path_to_remove" ]; then | |
33 | echo "${PATH}" | |
34 | return | |
35 | fi | |
36 | ||
37 | local paths | |
38 | IFS=: paths=($PATH) | |
39 | ||
40 | for path in "${paths[@]}"; do | |
41 | path="$(expand_path "$path" || true)" | |
42 | if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then | |
43 | result="${result}${path}:" | |
44 | fi | |
45 | done | |
46 | ||
47 | echo "${result%:}" | |
48 | } | |
49 | ||
50 | RBENV_VERSION="$(rbenv-version-name)" | |
51 | 29 | RBENV_COMMAND="$1" |
52 | 30 | |
53 | 31 | if [ -z "$RBENV_COMMAND" ]; then |
54 | 32 | rbenv-help --usage which >&2 |
55 | 33 | exit 1 |
56 | 34 | fi |
35 | ||
36 | RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}" | |
57 | 37 | |
58 | 38 | if [ "$RBENV_VERSION" = "system" ]; then |
59 | 39 | PATH="$(remove_from_path "${RBENV_ROOT}/shims")" |
62 | 42 | RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" |
63 | 43 | fi |
64 | 44 | |
65 | for script in $(rbenv-hooks which); do | |
45 | OLDIFS="$IFS" | |
46 | IFS=$'\n' scripts=(`rbenv-hooks which`) | |
47 | IFS="$OLDIFS" | |
48 | for script in "${scripts[@]}"; do | |
66 | 49 | source "$script" |
67 | 50 | done |
68 | 51 | |
69 | 52 | if [ -x "$RBENV_COMMAND_PATH" ]; then |
70 | 53 | echo "$RBENV_COMMAND_PATH" |
54 | elif [ "$RBENV_VERSION" != "system" ] && [ ! -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then | |
55 | echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 | |
56 | exit 1 | |
71 | 57 | else |
72 | 58 | echo "rbenv: $RBENV_COMMAND: command not found" >&2 |
73 | 59 |
0 | hook = lambda do |installer| | |
1 | begin | |
2 | # Ignore gems that aren't installed in locations that rbenv searches for binstubs | |
3 | if installer.spec.executables.any? && | |
4 | [Gem.default_bindir, Gem.bindir(Gem.user_dir)].include?(installer.bin_dir) | |
5 | `rbenv rehash` | |
6 | end | |
7 | rescue | |
8 | warn "rbenv: error in gem-rehash (#{$!.class.name}: #{$!.message})" | |
9 | end | |
10 | end | |
11 | ||
12 | if defined?(Bundler::Installer) && Bundler::Installer.respond_to?(:install) && !Bundler::Installer.respond_to?(:install_without_rbenv_rehash) | |
13 | Bundler::Installer.class_eval do | |
14 | class << self | |
15 | alias install_without_rbenv_rehash install | |
16 | def install(root, definition, options = {}) | |
17 | begin | |
18 | if Gem.default_path.include?(Bundler.bundle_path.to_s) | |
19 | bin_dir = Gem.bindir(Bundler.bundle_path.to_s) | |
20 | bins_before = File.exist?(bin_dir) ? Dir.entries(bin_dir).size : 2 | |
21 | end | |
22 | rescue | |
23 | warn "rbenv: error in Bundler post-install hook (#{$!.class.name}: #{$!.message})" | |
24 | end | |
25 | ||
26 | result = install_without_rbenv_rehash(root, definition, options) | |
27 | ||
28 | if bin_dir && File.exist?(bin_dir) && Dir.entries(bin_dir).size > bins_before | |
29 | `rbenv rehash` | |
30 | end | |
31 | result | |
32 | end | |
33 | end | |
34 | end | |
35 | else | |
36 | begin | |
37 | Gem.post_install(&hook) | |
38 | Gem.post_uninstall(&hook) | |
39 | rescue | |
40 | warn "rbenv: error installing gem-rehash hooks (#{$!.class.name}: #{$!.message})" | |
41 | end | |
42 | end |
0 | export RUBYLIB="${BASH_SOURCE%.bash}:$RUBYLIB" |
0 | CC = @CC@ | |
1 | ||
2 | CFLAGS = @CFLAGS@ | |
3 | LOCAL_CFLAGS = @LOCAL_CFLAGS@ | |
4 | DEFS = @DEFS@ | |
5 | LOCAL_DEFS = @LOCAL_DEFS@ | |
6 | ||
7 | CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS) | |
8 | ||
9 | SHOBJ_CC = @SHOBJ_CC@ | |
10 | SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ | |
11 | SHOBJ_LD = @SHOBJ_LD@ | |
12 | SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ | |
13 | SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ | |
14 | SHOBJ_LIBS = @SHOBJ_LIBS@ | |
15 | SHOBJ_STATUS = @SHOBJ_STATUS@ | |
16 | ||
17 | .c.o: | |
18 | $(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) -c -o $@ $< | |
19 | ||
20 | ../libexec/rbenv-realpath.dylib: realpath.o | |
21 | $(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS) | |
22 | ||
23 | clean: | |
24 | rm -f *.o ../libexec/*.dylib |
0 | #ifndef __BASH_H__ | |
1 | #define __BASH_H__ | |
2 | ||
3 | #define EXECUTION_SUCCESS 0 | |
4 | #define EXECUTION_FAILURE 1 | |
5 | #define EX_USAGE 258 | |
6 | ||
7 | #define BUILTIN_ENABLED 1 | |
8 | ||
9 | typedef struct word_desc { | |
10 | char *word; | |
11 | int flags; | |
12 | } WORD_DESC; | |
13 | ||
14 | typedef struct word_list { | |
15 | struct word_list *next; | |
16 | WORD_DESC *word; | |
17 | } WORD_LIST; | |
18 | ||
19 | typedef int sh_builtin_func_t(WORD_LIST *); | |
20 | ||
21 | struct builtin { | |
22 | char *name; | |
23 | sh_builtin_func_t *function; | |
24 | int flags; | |
25 | char * const *long_doc; | |
26 | const char *short_doc; | |
27 | char *unused; | |
28 | }; | |
29 | ||
30 | #endif |
0 | #!/usr/bin/env bash | |
1 | set -e | |
2 | ||
3 | src_dir="${0%/*}" | |
4 | ||
5 | if [ -z "$CC" ]; then | |
6 | if type -p gcc >/dev/null; then | |
7 | CC=gcc | |
8 | else | |
9 | echo "warning: gcc not found; using CC=cc" >&2 | |
10 | CC=cc | |
11 | fi | |
12 | fi | |
13 | ||
14 | if ! type -p "$CC" >/dev/null; then | |
15 | echo "aborted: compiler not found: $CC" >&2 | |
16 | exit 1 | |
17 | fi | |
18 | ||
19 | case "$(uname -s)" in | |
20 | Darwin* ) | |
21 | host_os="darwin$(uname -r)" | |
22 | ;; | |
23 | OpenBSD* ) | |
24 | host_os="openbsd$(uname -r)" | |
25 | ;; | |
26 | * ) | |
27 | host_os="linux-gnu" | |
28 | esac | |
29 | ||
30 | eval "$("$src_dir"/shobj-conf -C "$CC" -o "$host_os")" | |
31 | ||
32 | sed " | |
33 | s,@CC@,${CC}, | |
34 | s,@CFLAGS@,${CFLAGS}, | |
35 | s,@LOCAL_CFLAGS@,${LOCAL_CFLAGS}, | |
36 | s,@DEFS@,${DEFS}, | |
37 | s,@LOCAL_DEFS@,${LOCAL_DEFS}, | |
38 | s,@SHOBJ_CC@,${SHOBJ_CC}, | |
39 | s,@SHOBJ_CFLAGS@,${SHOBJ_CFLAGS}, | |
40 | s,@SHOBJ_LD@,${SHOBJ_LD}, | |
41 | s,@SHOBJ_LDFLAGS@,${SHOBJ_LDFLAGS//,/\\,}, | |
42 | s,@SHOBJ_XLDFLAGS@,${SHOBJ_XLDFLAGS//,/\\,}, | |
43 | s,@SHOBJ_LIBS@,${SHOBJ_LIBS}, | |
44 | s,@SHOBJ_STATUS@,${SHOBJ_STATUS}, | |
45 | " "$src_dir"/Makefile.in > "$src_dir"/Makefile |
0 | #include "bash.h" | |
1 | #include <stdlib.h> | |
2 | #include <stdio.h> | |
3 | ||
4 | int realpath_builtin(list) | |
5 | WORD_LIST *list; | |
6 | { | |
7 | int es; | |
8 | char *realbuf, *p; | |
9 | ||
10 | if (list == 0) { | |
11 | // builtin_usage(); | |
12 | return (EX_USAGE); | |
13 | } | |
14 | ||
15 | for (es = EXECUTION_SUCCESS; list; list = list->next) { | |
16 | p = list->word->word; | |
17 | realbuf = realpath(p, NULL); | |
18 | if (realbuf == NULL) { | |
19 | es = EXECUTION_FAILURE; | |
20 | // builtin_error("%s: cannot resolve: %s", p, strerror(errno)); | |
21 | } else { | |
22 | printf("%s\n", realbuf); | |
23 | free(realbuf); | |
24 | } | |
25 | } | |
26 | return es; | |
27 | } | |
28 | ||
29 | char *realpath_doc[] = { | |
30 | "Display each PATHNAME argument, resolving symbolic links. The exit status", | |
31 | "is 0 if each PATHNAME was resolved; non-zero otherwise.", | |
32 | (char *)NULL | |
33 | }; | |
34 | ||
35 | struct builtin realpath_struct = { | |
36 | "realpath", | |
37 | realpath_builtin, | |
38 | BUILTIN_ENABLED, | |
39 | realpath_doc, | |
40 | "realpath pathname [pathname...]", | |
41 | 0 | |
42 | }; |
0 | #! /bin/sh | |
1 | # | |
2 | # shobj-conf -- output a series of variable assignments to be substituted | |
3 | # into a Makefile by configure which specify system-dependent | |
4 | # information for creating shared objects that may be loaded | |
5 | # into bash with `enable -f' | |
6 | # | |
7 | # usage: shobj-conf [-C compiler] -c host_cpu -o host_os -v host_vendor | |
8 | # | |
9 | # Chet Ramey | |
10 | # chet@po.cwru.edu | |
11 | ||
12 | # Copyright (C) 1996-2002 Free Software Foundation, Inc. | |
13 | # | |
14 | # This program is free software; you can redistribute it and/or modify | |
15 | # it under the terms of the GNU General Public License as published by | |
16 | # the Free Software Foundation; either version 2, or (at your option) | |
17 | # any later version. | |
18 | # | |
19 | # This program is distributed in the hope that it will be useful, | |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | # GNU General Public License for more details. | |
23 | # | |
24 | # You should have received a copy of the GNU General Public License | |
25 | # along with this program; if not, write to the Free Software | |
26 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. | |
27 | ||
28 | # | |
29 | # defaults | |
30 | # | |
31 | SHOBJ_STATUS=supported | |
32 | SHLIB_STATUS=supported | |
33 | ||
34 | SHOBJ_CC=cc | |
35 | SHOBJ_CFLAGS= | |
36 | SHOBJ_LD= | |
37 | SHOBJ_LDFLAGS= | |
38 | SHOBJ_XLDFLAGS= | |
39 | SHOBJ_LIBS= | |
40 | ||
41 | SHLIB_XLDFLAGS= | |
42 | SHLIB_LIBS= | |
43 | ||
44 | SHLIB_DOT='.' | |
45 | SHLIB_LIBPREF='lib' | |
46 | SHLIB_LIBSUFF='so' | |
47 | ||
48 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF)' | |
49 | SHLIB_DLLVERSION='$(SHLIB_MAJOR)' | |
50 | ||
51 | PROGNAME=`basename $0` | |
52 | USAGE="$PROGNAME [-C compiler] -c host_cpu -o host_os -v host_vendor" | |
53 | ||
54 | while [ $# -gt 0 ]; do | |
55 | case "$1" in | |
56 | -C) shift; SHOBJ_CC="$1"; shift ;; | |
57 | -c) shift; host_cpu="$1"; shift ;; | |
58 | -o) shift; host_os="$1"; shift ;; | |
59 | -v) shift; host_vendor="$1"; shift ;; | |
60 | *) echo "$USAGE" >&2 ; exit 2;; | |
61 | esac | |
62 | done | |
63 | ||
64 | case "${host_os}-${SHOBJ_CC}" in | |
65 | sunos4*-*gcc*) | |
66 | SHOBJ_CFLAGS=-fpic | |
67 | SHOBJ_LD=/usr/bin/ld | |
68 | SHOBJ_LDFLAGS='-assert pure-text' | |
69 | ||
70 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
71 | ;; | |
72 | ||
73 | sunos4*) | |
74 | SHOBJ_CFLAGS=-pic | |
75 | SHOBJ_LD=/usr/bin/ld | |
76 | SHOBJ_LDFLAGS='-assert pure-text' | |
77 | ||
78 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
79 | ;; | |
80 | ||
81 | sunos5*-*gcc*|solaris2*-*gcc*) | |
82 | SHOBJ_CFLAGS=-fpic | |
83 | SHOBJ_LD='${CC}' | |
84 | ld_used=`gcc -print-prog-name=ld` | |
85 | if ${ld_used} -V 2>&1 | grep GNU >/dev/null 2>&1; then | |
86 | # This line works for the GNU ld | |
87 | SHOBJ_LDFLAGS='-shared -Wl,-h,$@' | |
88 | else | |
89 | # This line works for the Solaris linker in /usr/ccs/bin/ld | |
90 | SHOBJ_LDFLAGS='-shared -Wl,-i -Wl,-h,$@' | |
91 | fi | |
92 | ||
93 | # SHLIB_XLDFLAGS='-R $(libdir)' | |
94 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
95 | ;; | |
96 | ||
97 | sunos5*|solaris2*) | |
98 | SHOBJ_CFLAGS='-K pic' | |
99 | SHOBJ_LD=/usr/ccs/bin/ld | |
100 | SHOBJ_LDFLAGS='-G -dy -z text -i -h $@' | |
101 | ||
102 | # SHLIB_XLDFLAGS='-R $(libdir)' | |
103 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
104 | ;; | |
105 | ||
106 | # All versions of Linux or the semi-mythical GNU Hurd. | |
107 | linux*-*|gnu*-*|k*bsd*-gnu-*) | |
108 | SHOBJ_CFLAGS=-fPIC | |
109 | SHOBJ_LD='${CC}' | |
110 | SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' | |
111 | ||
112 | SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir) -Wl,-soname,`basename $@ $(SHLIB_MINOR)`' | |
113 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
114 | ;; | |
115 | ||
116 | freebsd2* | netbsd*) | |
117 | SHOBJ_CFLAGS=-fpic | |
118 | SHOBJ_LD=ld | |
119 | SHOBJ_LDFLAGS='-x -Bshareable' | |
120 | ||
121 | SHLIB_XLDFLAGS='-R$(libdir)' | |
122 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
123 | ;; | |
124 | ||
125 | # FreeBSD-3.x ELF | |
126 | freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*) | |
127 | SHOBJ_CFLAGS=-fpic | |
128 | SHOBJ_LD='${CC}' | |
129 | ||
130 | if [ -x /usr/bin/objformat ] && [ "`/usr/bin/objformat`" = "elf" ]; then | |
131 | SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' | |
132 | ||
133 | SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)' | |
134 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
135 | else | |
136 | SHOBJ_LDFLAGS='-shared' | |
137 | ||
138 | SHLIB_XLDFLAGS='-R$(libdir)' | |
139 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
140 | fi | |
141 | ;; | |
142 | ||
143 | # Darwin/MacOS X | |
144 | darwin1*) | |
145 | SHOBJ_STATUS=supported | |
146 | SHLIB_STATUS=supported | |
147 | ||
148 | SHOBJ_CFLAGS='' | |
149 | SHLIB_LIBSUFF='dylib' | |
150 | ||
151 | SHOBJ_LD='${CC}' | |
152 | SHOBJ_LDFLAGS='-dynamiclib' | |
153 | ;; | |
154 | ||
155 | darwin8*) | |
156 | SHOBJ_STATUS=supported | |
157 | SHLIB_STATUS=supported | |
158 | ||
159 | SHOBJ_CFLAGS='-fno-common' | |
160 | ||
161 | SHOBJ_LD='MACOSX_DEPLOYMENT_TARGET=10.3 ${CC}' | |
162 | ||
163 | SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)' | |
164 | SHLIB_LIBSUFF='dylib' | |
165 | ||
166 | SHOBJ_LDFLAGS='-undefined dynamic_lookup' | |
167 | SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' | |
168 | ||
169 | SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1 | |
170 | ;; | |
171 | ||
172 | darwin*|macosx*) | |
173 | SHOBJ_STATUS=unsupported | |
174 | SHLIB_STATUS=supported | |
175 | ||
176 | SHOBJ_CFLAGS='-fno-common' | |
177 | ||
178 | SHOBJ_LD='${CC}' | |
179 | ||
180 | SHLIB_LIBVERSION='$(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)' | |
181 | SHLIB_LIBSUFF='dylib' | |
182 | ||
183 | case "${host_os}" in | |
184 | darwin[78]*) SHOBJ_LDFLAGS='' | |
185 | SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' | |
186 | ;; | |
187 | *) SHOBJ_LDFLAGS='-dynamic' | |
188 | SHLIB_XLDFLAGS='-arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v' | |
189 | ;; | |
190 | esac | |
191 | ||
192 | SHLIB_LIBS='-lncurses' # see if -lcurses works on MacOS X 10.1 | |
193 | ;; | |
194 | ||
195 | openbsd*) | |
196 | SHOBJ_CFLAGS=-fPIC | |
197 | SHOBJ_LD='${CC}' | |
198 | SHOBJ_LDFLAGS='-shared' | |
199 | ||
200 | SHLIB_XLDFLAGS='-R$(libdir)' | |
201 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
202 | ;; | |
203 | ||
204 | bsdi2*) | |
205 | SHOBJ_CC=shlicc2 | |
206 | SHOBJ_CFLAGS= | |
207 | SHOBJ_LD=ld | |
208 | SHOBJ_LDFLAGS=-r | |
209 | SHOBJ_LIBS=-lc_s.2.1.0 | |
210 | ||
211 | # BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in | |
212 | # the ass -- they require changing {/usr/lib,etc}/shlib.map on | |
213 | # each system, and the library creation process is byzantine | |
214 | SHLIB_STATUS=unsupported | |
215 | ;; | |
216 | ||
217 | bsdi3*) | |
218 | SHOBJ_CC=shlicc2 | |
219 | SHOBJ_CFLAGS= | |
220 | SHOBJ_LD=ld | |
221 | SHOBJ_LDFLAGS=-r | |
222 | SHOBJ_LIBS=-lc_s.3.0.0 | |
223 | ||
224 | # BSD/OS 2.x and 3.x `shared libraries' are too much of a pain in | |
225 | # the ass -- they require changing {/usr/lib,etc}/shlib.map on | |
226 | # each system, and the library creation process is byzantine | |
227 | SHLIB_STATUS=unsupported | |
228 | ;; | |
229 | ||
230 | bsdi4*) | |
231 | # BSD/OS 4.x now supports ELF and SunOS-style dynamically-linked | |
232 | # shared libraries. gcc 2.x is the standard compiler, and the | |
233 | # `normal' gcc options should work as they do in Linux. | |
234 | ||
235 | SHOBJ_CFLAGS=-fPIC | |
236 | SHOBJ_LD='${CC}' | |
237 | SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' | |
238 | ||
239 | SHLIB_XLDFLAGS='-Wl,-soname,`basename $@ $(SHLIB_MINOR)`' | |
240 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)$(SHLIB_MINOR)' | |
241 | ;; | |
242 | ||
243 | osf*-*gcc*) | |
244 | # Fix to use gcc linker driver from bfischer@TechFak.Uni-Bielefeld.DE | |
245 | SHOBJ_LD='${CC}' | |
246 | SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' | |
247 | ||
248 | SHLIB_XLDFLAGS='-rpath $(libdir)' | |
249 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
250 | ;; | |
251 | ||
252 | osf*) | |
253 | SHOBJ_LD=ld | |
254 | SHOBJ_LDFLAGS='-shared -soname $@ -expect_unresolved "*"' | |
255 | ||
256 | SHLIB_XLDFLAGS='-rpath $(libdir)' | |
257 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
258 | ;; | |
259 | ||
260 | aix4.[2-9]*-*gcc*) # lightly tested by jik@cisco.com | |
261 | SHOBJ_CFLAGS=-fpic | |
262 | SHOBJ_LD='ld' | |
263 | SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall' | |
264 | SHOBJ_XLDFLAGS='-G' | |
265 | ||
266 | SHLIB_XLDFLAGS='-bM:SRE' | |
267 | SHLIB_LIBS='-lcurses -lc' | |
268 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
269 | ;; | |
270 | ||
271 | aix4.[2-9]*) | |
272 | SHOBJ_CFLAGS=-K | |
273 | SHOBJ_LD='ld' | |
274 | SHOBJ_LDFLAGS='-bdynamic -bnoentry -bexpall' | |
275 | SHOBJ_XLDFLAGS='-G' | |
276 | ||
277 | SHLIB_XLDFLAGS='-bM:SRE' | |
278 | SHLIB_LIBS='-lcurses -lc' | |
279 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
280 | ;; | |
281 | ||
282 | # | |
283 | # THE FOLLOWING ARE UNTESTED -- and some may not support the dlopen interface | |
284 | # | |
285 | irix[56]*-*gcc*) | |
286 | SHOBJ_CFLAGS='-fpic' | |
287 | SHOBJ_LD='${CC}' | |
288 | SHOBJ_LDFLAGS='-shared -Wl,-soname,$@' | |
289 | ||
290 | SHLIB_XLDFLAGS='-Wl,-rpath,$(libdir)' | |
291 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
292 | ;; | |
293 | ||
294 | irix[56]*) | |
295 | SHOBJ_CFLAGS='-K PIC' | |
296 | SHOBJ_LD=ld | |
297 | # SHOBJ_LDFLAGS='-call_shared -hidden_symbol -no_unresolved -soname $@' | |
298 | # Change from David Kaelbling <drk@sgi.com>. If you have problems, | |
299 | # remove the `-no_unresolved' | |
300 | SHOBJ_LDFLAGS='-shared -no_unresolved -soname $@' | |
301 | ||
302 | SHLIB_XLDFLAGS='-rpath $(libdir)' | |
303 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
304 | ;; | |
305 | ||
306 | hpux9*-*gcc*) | |
307 | # must use gcc; the bundled cc cannot compile PIC code | |
308 | SHOBJ_CFLAGS='-fpic' | |
309 | SHOBJ_LD='${CC}' | |
310 | SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s' | |
311 | ||
312 | SHLIB_XLDFLAGS='-Wl,+b,$(libdir)' | |
313 | SHLIB_LIBSUFF='sl' | |
314 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
315 | ;; | |
316 | ||
317 | hpux9*) | |
318 | SHOBJ_STATUS=unsupported | |
319 | SHLIB_STATUS=unsupported | |
320 | ||
321 | # If you are using the HP ANSI C compiler, you can uncomment and use | |
322 | # this code (I have not tested it) | |
323 | # SHOBJ_STATUS=supported | |
324 | # SHLIB_STATUS=supported | |
325 | # | |
326 | # SHOBJ_CFLAGS='+z' | |
327 | # SHOBJ_LD='ld' | |
328 | # SHOBJ_LDFLAGS='-b +s' | |
329 | # | |
330 | # SHLIB_XLDFLAGS='+b $(libdir)' | |
331 | # SHLIB_LIBSUFF='sl' | |
332 | # SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
333 | ||
334 | ;; | |
335 | ||
336 | hpux10*-*gcc*) | |
337 | # must use gcc; the bundled cc cannot compile PIC code | |
338 | SHOBJ_CFLAGS='-fpic' | |
339 | SHOBJ_LD='${CC}' | |
340 | # if you have problems linking here, moving the `-Wl,+h,$@' from | |
341 | # SHLIB_XLDFLAGS to SHOBJ_LDFLAGS has been reported to work | |
342 | SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,+s' | |
343 | ||
344 | SHLIB_XLDFLAGS='-Wl,+h,$@ -Wl,+b,$(libdir)' | |
345 | SHLIB_LIBSUFF='sl' | |
346 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
347 | ;; | |
348 | ||
349 | hpux10*) | |
350 | SHOBJ_STATUS=unsupported | |
351 | SHLIB_STATUS=unsupported | |
352 | ||
353 | # If you are using the HP ANSI C compiler, you can uncomment and use | |
354 | # this code (I have not tested it) | |
355 | # SHOBJ_STATUS=supported | |
356 | # SHLIB_STATUS=supported | |
357 | # | |
358 | # SHOBJ_CFLAGS='+z' | |
359 | # SHOBJ_LD='ld' | |
360 | # SHOBJ_LDFLAGS='-b +s +h $@' | |
361 | # | |
362 | # SHLIB_XLDFLAGS='+b $(libdir)' | |
363 | # SHLIB_LIBSUFF='sl' | |
364 | # SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
365 | ||
366 | ;; | |
367 | ||
368 | hpux11*-*gcc*) | |
369 | # must use gcc; the bundled cc cannot compile PIC code | |
370 | SHOBJ_CFLAGS='-fpic' | |
371 | SHOBJ_LD='${CC}' | |
372 | # SHOBJ_LDFLAGS='-shared -Wl,-b -Wl,-B,symbolic -Wl,+s -Wl,+std -Wl,+h,$@' | |
373 | SHOBJ_LDFLAGS='-shared -fpic -Wl,-b -Wl,+s -Wl,+h,$@' | |
374 | ||
375 | SHLIB_XLDFLAGS='-Wl,+b,$(libdir)' | |
376 | SHLIB_LIBSUFF='sl' | |
377 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
378 | ;; | |
379 | ||
380 | hpux11*) | |
381 | SHOBJ_STATUS=unsupported | |
382 | SHLIB_STATUS=unsupported | |
383 | ||
384 | # If you are using the HP ANSI C compiler, you can uncomment and use | |
385 | # this code (I have not tested it) | |
386 | # SHOBJ_STATUS=supported | |
387 | # SHLIB_STATUS=supported | |
388 | # | |
389 | # SHOBJ_CFLAGS='+z' | |
390 | # SHOBJ_LD='ld' | |
391 | # SHOBJ_LDFLAGS='-b +s +h $@' | |
392 | # | |
393 | # SHLIB_XLDFLAGS='+b $(libdir)' | |
394 | # SHLIB_LIBSUFF='sl' | |
395 | # SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
396 | ||
397 | ;; | |
398 | ||
399 | sysv4*-*gcc*) | |
400 | SHOBJ_CFLAGS=-shared | |
401 | SHOBJ_LDFLAGS='-shared -h $@' | |
402 | SHOBJ_LD='${CC}' | |
403 | ||
404 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
405 | ;; | |
406 | ||
407 | sysv4*) | |
408 | SHOBJ_CFLAGS='-K PIC' | |
409 | SHOBJ_LD=ld | |
410 | SHOBJ_LDFLAGS='-dy -z text -G -h $@' | |
411 | ||
412 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
413 | ;; | |
414 | ||
415 | sco3.2v5*-*gcc*) | |
416 | SHOBJ_CFLAGS='-fpic' # DEFAULTS TO ELF | |
417 | SHOBJ_LD='${CC}' | |
418 | SHOBJ_LDFLAGS='-shared' | |
419 | ||
420 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
421 | ;; | |
422 | ||
423 | sco3.2v5*) | |
424 | SHOBJ_CFLAGS='-K pic -b elf' | |
425 | SHOBJ_LD=ld | |
426 | SHOBJ_LDFLAGS='-G -b elf -dy -z text -h $@' | |
427 | ||
428 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
429 | ;; | |
430 | ||
431 | sysv5uw7*-*gcc*) | |
432 | SHOBJ_CFLAGS='-fpic' | |
433 | SHOBJ_LD='${CC}' | |
434 | SHOBJ_LDFLAGS='-shared' | |
435 | ||
436 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
437 | ;; | |
438 | ||
439 | sysv5uw7*) | |
440 | SHOBJ_CFLAGS='-K PIC' | |
441 | SHOBJ_LD=ld | |
442 | SHOBJ_LDFLAGS='-G -dy -z text -h $@' | |
443 | ||
444 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
445 | ;; | |
446 | ||
447 | sysv5UnixWare*-*gcc*) | |
448 | SHOBJ_CFLAGS=-fpic | |
449 | SHOBJ_LD='${CC}' | |
450 | SHOBJ_LDFLAGS='-shared' | |
451 | ||
452 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
453 | ;; | |
454 | ||
455 | sysv5UnixWare*) | |
456 | SHOBJ_CFLAGS='-K PIC' | |
457 | SHOBJ_LD=ld | |
458 | SHOBJ_LDFLAGS='-G -dy -z text -h $@' | |
459 | ||
460 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
461 | ;; | |
462 | ||
463 | sysv5OpenUNIX*-*gcc*) | |
464 | SHOBJ_CFLAGS=-fpic | |
465 | SHOBJ_LD='${CC}' | |
466 | SHOBJ_LDFLAGS='-shared' | |
467 | ||
468 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
469 | ;; | |
470 | ||
471 | sysv5OpenUNIX*) | |
472 | SHOBJ_CFLAGS='-K PIC' | |
473 | SHOBJ_LD=ld | |
474 | SHOBJ_LDFLAGS='-G -dy -z text -h $@' | |
475 | ||
476 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
477 | ;; | |
478 | ||
479 | dgux*-*gcc*) | |
480 | SHOBJ_CFLAGS=-fpic | |
481 | SHOBJ_LD='${CC}' | |
482 | SHOBJ_LDFLAGS='-shared' | |
483 | ||
484 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
485 | ;; | |
486 | ||
487 | dgux*) | |
488 | SHOBJ_CFLAGS='-K pic' | |
489 | SHOBJ_LD=ld | |
490 | SHOBJ_LDFLAGS='-G -dy -h $@' | |
491 | ||
492 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
493 | ;; | |
494 | ||
495 | msdos*) | |
496 | SHOBJ_STATUS=unsupported | |
497 | SHLIB_STATUS=unsupported | |
498 | ;; | |
499 | ||
500 | cygwin*) | |
501 | SHOBJ_LD='$(CC)' | |
502 | SHOBJ_LDFLAGS='-shared -Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--export-all -Wl,--out-implib=$(@).a' | |
503 | SHLIB_LIBPREF='cyg' | |
504 | SHLIB_LIBSUFF='dll' | |
505 | SHLIB_LIBVERSION='$(SHLIB_DLLVERSION).$(SHLIB_LIBSUFF)' | |
506 | SHLIB_LIBS='$(TERMCAP_LIB)' | |
507 | ||
508 | SHLIB_DOT= | |
509 | # For official cygwin releases, DLLVERSION will be defined in the | |
510 | # environment of configure, and will be incremented any time the API | |
511 | # changes in a non-backwards compatible manner. Otherwise, it is just | |
512 | # SHLIB_MAJOR. | |
513 | if [ -n "$DLLVERSION" ] ; then | |
514 | SHLIB_DLLVERSION="$DLLVERSION" | |
515 | fi | |
516 | ;; | |
517 | ||
518 | # | |
519 | # Rely on correct gcc configuration for everything else | |
520 | # | |
521 | *-*gcc*) | |
522 | SHOBJ_CFLAGS=-fpic | |
523 | SHOBJ_LD='${CC}' | |
524 | SHOBJ_LDFLAGS='-shared' | |
525 | ||
526 | SHLIB_LIBVERSION='$(SHLIB_LIBSUFF).$(SHLIB_MAJOR)' | |
527 | ;; | |
528 | ||
529 | *) | |
530 | SHOBJ_STATUS=unsupported | |
531 | SHLIB_STATUS=unsupported | |
532 | ;; | |
533 | ||
534 | esac | |
535 | ||
536 | echo SHOBJ_CC=\'"$SHOBJ_CC"\' | |
537 | echo SHOBJ_CFLAGS=\'"$SHOBJ_CFLAGS"\' | |
538 | echo SHOBJ_LD=\'"$SHOBJ_LD"\' | |
539 | echo SHOBJ_LDFLAGS=\'"$SHOBJ_LDFLAGS"\' | |
540 | echo SHOBJ_XLDFLAGS=\'"$SHOBJ_XLDFLAGS"\' | |
541 | echo SHOBJ_LIBS=\'"$SHOBJ_LIBS"\' | |
542 | ||
543 | echo SHLIB_XLDFLAGS=\'"$SHLIB_XLDFLAGS"\' | |
544 | echo SHLIB_LIBS=\'"$SHLIB_LIBS"\' | |
545 | ||
546 | echo SHLIB_DOT=\'"$SHLIB_DOT"\' | |
547 | ||
548 | echo SHLIB_LIBPREF=\'"$SHLIB_LIBPREF"\' | |
549 | echo SHLIB_LIBSUFF=\'"$SHLIB_LIBSUFF"\' | |
550 | ||
551 | echo SHLIB_LIBVERSION=\'"$SHLIB_LIBVERSION"\' | |
552 | echo SHLIB_DLLVERSION=\'"$SHLIB_DLLVERSION"\' | |
553 | ||
554 | echo SHOBJ_STATUS=\'"$SHOBJ_STATUS"\' | |
555 | echo SHLIB_STATUS=\'"$SHLIB_STATUS"\' | |
556 | ||
557 | exit 0 |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | export GIT_DIR="${RBENV_TEST_DIR}/.git" | |
5 | ||
6 | setup() { | |
7 | mkdir -p "$HOME" | |
8 | git config --global user.name "Tester" | |
9 | git config --global user.email "tester@test.local" | |
10 | cd "$RBENV_TEST_DIR" | |
11 | } | |
12 | ||
13 | git_commit() { | |
14 | git commit --quiet --allow-empty -m "empty" | |
15 | } | |
16 | ||
17 | @test "default version" { | |
18 | assert [ ! -e "$RBENV_ROOT" ] | |
19 | run rbenv---version | |
20 | assert_success | |
21 | [[ $output == "rbenv "?.?.? ]] | |
22 | } | |
23 | ||
24 | @test "doesn't read version from non-rbenv repo" { | |
25 | git init | |
26 | git remote add origin https://github.com/homebrew/homebrew.git | |
27 | git_commit | |
28 | git tag v1.0 | |
29 | ||
30 | run rbenv---version | |
31 | assert_success | |
32 | [[ $output == "rbenv "?.?.? ]] | |
33 | } | |
34 | ||
35 | @test "reads version from git repo" { | |
36 | git init | |
37 | git remote add origin https://github.com/rbenv/rbenv.git | |
38 | git_commit | |
39 | git tag v0.4.1 | |
40 | git_commit | |
41 | git_commit | |
42 | ||
43 | run rbenv---version | |
44 | assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)" | |
45 | } | |
46 | ||
47 | @test "prints default version if no tags in git repo" { | |
48 | git init | |
49 | git remote add origin https://github.com/rbenv/rbenv.git | |
50 | git_commit | |
51 | ||
52 | run rbenv---version | |
53 | [[ $output == "rbenv "?.?.? ]] | |
54 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "commands" { | |
5 | run rbenv-commands | |
6 | assert_success | |
7 | assert_line "init" | |
8 | assert_line "rehash" | |
9 | assert_line "shell" | |
10 | refute_line "sh-shell" | |
11 | assert_line "echo" | |
12 | } | |
13 | ||
14 | @test "commands --sh" { | |
15 | run rbenv-commands --sh | |
16 | assert_success | |
17 | refute_line "init" | |
18 | assert_line "shell" | |
19 | } | |
20 | ||
21 | @test "commands in path with spaces" { | |
22 | path="${RBENV_TEST_DIR}/my commands" | |
23 | cmd="${path}/rbenv-sh-hello" | |
24 | mkdir -p "$path" | |
25 | touch "$cmd" | |
26 | chmod +x "$cmd" | |
27 | ||
28 | PATH="${path}:$PATH" run rbenv-commands --sh | |
29 | assert_success | |
30 | assert_line "hello" | |
31 | } | |
32 | ||
33 | @test "commands --no-sh" { | |
34 | run rbenv-commands --no-sh | |
35 | assert_success | |
36 | assert_line "init" | |
37 | refute_line "shell" | |
38 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_command() { | |
5 | bin="${RBENV_TEST_DIR}/bin" | |
6 | mkdir -p "$bin" | |
7 | echo "$2" > "${bin}/$1" | |
8 | chmod +x "${bin}/$1" | |
9 | } | |
10 | ||
11 | @test "command with no completion support" { | |
12 | create_command "rbenv-hello" "#!$BASH | |
13 | echo hello" | |
14 | run rbenv-completions hello | |
15 | assert_success "--help" | |
16 | } | |
17 | ||
18 | @test "command with completion support" { | |
19 | create_command "rbenv-hello" "#!$BASH | |
20 | # Provide rbenv completions | |
21 | if [[ \$1 = --complete ]]; then | |
22 | echo hello | |
23 | else | |
24 | exit 1 | |
25 | fi" | |
26 | run rbenv-completions hello | |
27 | assert_success | |
28 | assert_output <<OUT | |
29 | --help | |
30 | hello | |
31 | OUT | |
32 | } | |
33 | ||
34 | @test "forwards extra arguments" { | |
35 | create_command "rbenv-hello" "#!$BASH | |
36 | # provide rbenv completions | |
37 | if [[ \$1 = --complete ]]; then | |
38 | shift 1 | |
39 | for arg; do echo \$arg; done | |
40 | else | |
41 | exit 1 | |
42 | fi" | |
43 | run rbenv-completions hello happy world | |
44 | assert_success | |
45 | assert_output <<OUT | |
46 | --help | |
47 | happy | |
48 | world | |
49 | OUT | |
50 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_executable() { | |
5 | name="${1?}" | |
6 | shift 1 | |
7 | bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" | |
8 | mkdir -p "$bin" | |
9 | { if [ $# -eq 0 ]; then cat - | |
10 | else echo "$@" | |
11 | fi | |
12 | } | sed -Ee '1s/^ +//' > "${bin}/$name" | |
13 | chmod +x "${bin}/$name" | |
14 | } | |
15 | ||
16 | @test "fails with invalid version" { | |
17 | export RBENV_VERSION="2.0" | |
18 | run rbenv-exec ruby -v | |
19 | assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)" | |
20 | } | |
21 | ||
22 | @test "fails with invalid version set from file" { | |
23 | mkdir -p "$RBENV_TEST_DIR" | |
24 | cd "$RBENV_TEST_DIR" | |
25 | echo 1.9 > .ruby-version | |
26 | run rbenv-exec rspec | |
27 | assert_failure "rbenv: version \`1.9' is not installed (set by $PWD/.ruby-version)" | |
28 | } | |
29 | ||
30 | @test "completes with names of executables" { | |
31 | export RBENV_VERSION="2.0" | |
32 | create_executable "ruby" "#!/bin/sh" | |
33 | create_executable "rake" "#!/bin/sh" | |
34 | ||
35 | rbenv-rehash | |
36 | run rbenv-completions exec | |
37 | assert_success | |
38 | assert_output <<OUT | |
39 | --help | |
40 | rake | |
41 | ruby | |
42 | OUT | |
43 | } | |
44 | ||
45 | @test "supports hook path with spaces" { | |
46 | hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" | |
47 | mkdir -p "${hook_path}/exec" | |
48 | echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash" | |
49 | ||
50 | export RBENV_VERSION=system | |
51 | RBENV_HOOK_PATH="$hook_path" run rbenv-exec env | |
52 | assert_success | |
53 | assert_line "HELLO=from hook" | |
54 | } | |
55 | ||
56 | @test "carries original IFS within hooks" { | |
57 | hook_path="${RBENV_TEST_DIR}/rbenv.d" | |
58 | mkdir -p "${hook_path}/exec" | |
59 | cat > "${hook_path}/exec/hello.bash" <<SH | |
60 | hellos=(\$(printf "hello\\tugly world\\nagain")) | |
61 | echo HELLO="\$(printf ":%s" "\${hellos[@]}")" | |
62 | SH | |
63 | ||
64 | export RBENV_VERSION=system | |
65 | RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-exec env | |
66 | assert_success | |
67 | assert_line "HELLO=:hello:ugly:world:again" | |
68 | } | |
69 | ||
70 | @test "forwards all arguments" { | |
71 | export RBENV_VERSION="2.0" | |
72 | create_executable "ruby" <<SH | |
73 | #!$BASH | |
74 | echo \$0 | |
75 | for arg; do | |
76 | # hack to avoid bash builtin echo which can't output '-e' | |
77 | printf " %s\\n" "\$arg" | |
78 | done | |
79 | SH | |
80 | ||
81 | run rbenv-exec ruby -w "/path to/ruby script.rb" -- extra args | |
82 | assert_success | |
83 | assert_output <<OUT | |
84 | ${RBENV_ROOT}/versions/2.0/bin/ruby | |
85 | -w | |
86 | /path to/ruby script.rb | |
87 | -- | |
88 | extra | |
89 | args | |
90 | OUT | |
91 | } | |
92 | ||
93 | @test "supports ruby -S <cmd>" { | |
94 | export RBENV_VERSION="2.0" | |
95 | ||
96 | # emulate `ruby -S' behavior | |
97 | create_executable "ruby" <<SH | |
98 | #!$BASH | |
99 | if [[ \$1 == "-S"* ]]; then | |
100 | found="\$(PATH="\${RUBYPATH:-\$PATH}" which \$2)" | |
101 | # assert that the found executable has ruby for shebang | |
102 | if head -1 "\$found" | grep ruby >/dev/null; then | |
103 | \$BASH "\$found" | |
104 | else | |
105 | echo "ruby: no Ruby script found in input (LoadError)" >&2 | |
106 | exit 1 | |
107 | fi | |
108 | else | |
109 | echo 'ruby 2.0 (rbenv test)' | |
110 | fi | |
111 | SH | |
112 | ||
113 | create_executable "rake" <<SH | |
114 | #!/usr/bin/env ruby | |
115 | echo hello rake | |
116 | SH | |
117 | ||
118 | rbenv-rehash | |
119 | run ruby -S rake | |
120 | assert_success "hello rake" | |
121 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "default" { | |
5 | run rbenv global | |
6 | assert_success | |
7 | assert_output "system" | |
8 | } | |
9 | ||
10 | @test "read RBENV_ROOT/version" { | |
11 | mkdir -p "$RBENV_ROOT" | |
12 | echo "1.2.3" > "$RBENV_ROOT/version" | |
13 | run rbenv-global | |
14 | assert_success | |
15 | assert_output "1.2.3" | |
16 | } | |
17 | ||
18 | @test "set RBENV_ROOT/version" { | |
19 | mkdir -p "$RBENV_ROOT/versions/1.2.3" | |
20 | run rbenv-global "1.2.3" | |
21 | assert_success | |
22 | run rbenv global | |
23 | assert_success "1.2.3" | |
24 | } | |
25 | ||
26 | @test "fail setting invalid RBENV_ROOT/version" { | |
27 | mkdir -p "$RBENV_ROOT" | |
28 | run rbenv-global "1.2.3" | |
29 | assert_failure "rbenv: version \`1.2.3' not installed" | |
30 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "without args shows summary of common commands" { | |
5 | run rbenv-help | |
6 | assert_success | |
7 | assert_line "Usage: rbenv <command> [<args>]" | |
8 | assert_line "Some useful rbenv commands are:" | |
9 | } | |
10 | ||
11 | @test "invalid command" { | |
12 | run rbenv-help hello | |
13 | assert_failure "rbenv: no such command \`hello'" | |
14 | } | |
15 | ||
16 | @test "shows help for a specific command" { | |
17 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
18 | cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH | |
19 | #!shebang | |
20 | # Usage: rbenv hello <world> | |
21 | # Summary: Says "hello" to you, from rbenv | |
22 | # This command is useful for saying hello. | |
23 | echo hello | |
24 | SH | |
25 | ||
26 | run rbenv-help hello | |
27 | assert_success | |
28 | assert_output <<SH | |
29 | Usage: rbenv hello <world> | |
30 | ||
31 | This command is useful for saying hello. | |
32 | SH | |
33 | } | |
34 | ||
35 | @test "replaces missing extended help with summary text" { | |
36 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
37 | cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH | |
38 | #!shebang | |
39 | # Usage: rbenv hello <world> | |
40 | # Summary: Says "hello" to you, from rbenv | |
41 | echo hello | |
42 | SH | |
43 | ||
44 | run rbenv-help hello | |
45 | assert_success | |
46 | assert_output <<SH | |
47 | Usage: rbenv hello <world> | |
48 | ||
49 | Says "hello" to you, from rbenv | |
50 | SH | |
51 | } | |
52 | ||
53 | @test "extracts only usage" { | |
54 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
55 | cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH | |
56 | #!shebang | |
57 | # Usage: rbenv hello <world> | |
58 | # Summary: Says "hello" to you, from rbenv | |
59 | # This extended help won't be shown. | |
60 | echo hello | |
61 | SH | |
62 | ||
63 | run rbenv-help --usage hello | |
64 | assert_success "Usage: rbenv hello <world>" | |
65 | } | |
66 | ||
67 | @test "multiline usage section" { | |
68 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
69 | cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH | |
70 | #!shebang | |
71 | # Usage: rbenv hello <world> | |
72 | # rbenv hi [everybody] | |
73 | # rbenv hola --translate | |
74 | # Summary: Says "hello" to you, from rbenv | |
75 | # Help text. | |
76 | echo hello | |
77 | SH | |
78 | ||
79 | run rbenv-help hello | |
80 | assert_success | |
81 | assert_output <<SH | |
82 | Usage: rbenv hello <world> | |
83 | rbenv hi [everybody] | |
84 | rbenv hola --translate | |
85 | ||
86 | Help text. | |
87 | SH | |
88 | } | |
89 | ||
90 | @test "multiline extended help section" { | |
91 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
92 | cat > "${RBENV_TEST_DIR}/bin/rbenv-hello" <<SH | |
93 | #!shebang | |
94 | # Usage: rbenv hello <world> | |
95 | # Summary: Says "hello" to you, from rbenv | |
96 | # This is extended help text. | |
97 | # It can contain multiple lines. | |
98 | # | |
99 | # And paragraphs. | |
100 | ||
101 | echo hello | |
102 | SH | |
103 | ||
104 | run rbenv-help hello | |
105 | assert_success | |
106 | assert_output <<SH | |
107 | Usage: rbenv hello <world> | |
108 | ||
109 | This is extended help text. | |
110 | It can contain multiple lines. | |
111 | ||
112 | And paragraphs. | |
113 | SH | |
114 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_hook() { | |
5 | mkdir -p "$1/$2" | |
6 | touch "$1/$2/$3" | |
7 | } | |
8 | ||
9 | @test "prints usage help given no argument" { | |
10 | run rbenv-hooks | |
11 | assert_failure "Usage: rbenv hooks <command>" | |
12 | } | |
13 | ||
14 | @test "prints list of hooks" { | |
15 | path1="${RBENV_TEST_DIR}/rbenv.d" | |
16 | path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" | |
17 | create_hook "$path1" exec "hello.bash" | |
18 | create_hook "$path1" exec "ahoy.bash" | |
19 | create_hook "$path1" exec "invalid.sh" | |
20 | create_hook "$path1" which "boom.bash" | |
21 | create_hook "$path2" exec "bueno.bash" | |
22 | ||
23 | RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec | |
24 | assert_success | |
25 | assert_output <<OUT | |
26 | ${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash | |
27 | ${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash | |
28 | ${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash | |
29 | OUT | |
30 | } | |
31 | ||
32 | @test "supports hook paths with spaces" { | |
33 | path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" | |
34 | path2="${RBENV_TEST_DIR}/etc/rbenv hooks" | |
35 | create_hook "$path1" exec "hello.bash" | |
36 | create_hook "$path2" exec "ahoy.bash" | |
37 | ||
38 | RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec | |
39 | assert_success | |
40 | assert_output <<OUT | |
41 | ${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash | |
42 | ${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash | |
43 | OUT | |
44 | } | |
45 | ||
46 | @test "resolves relative paths" { | |
47 | path="${RBENV_TEST_DIR}/rbenv.d" | |
48 | create_hook "$path" exec "hello.bash" | |
49 | mkdir -p "$HOME" | |
50 | ||
51 | RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec | |
52 | assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash" | |
53 | } | |
54 | ||
55 | @test "resolves symlinks" { | |
56 | path="${RBENV_TEST_DIR}/rbenv.d" | |
57 | mkdir -p "${path}/exec" | |
58 | mkdir -p "$HOME" | |
59 | touch "${HOME}/hola.bash" | |
60 | ln -s "../../home/hola.bash" "${path}/exec/hello.bash" | |
61 | touch "${path}/exec/bright.sh" | |
62 | ln -s "bright.sh" "${path}/exec/world.bash" | |
63 | ||
64 | RBENV_HOOK_PATH="$path" run rbenv-hooks exec | |
65 | assert_success | |
66 | assert_output <<OUT | |
67 | ${HOME}/hola.bash | |
68 | ${RBENV_TEST_DIR}/rbenv.d/exec/bright.sh | |
69 | OUT | |
70 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "creates shims and versions directories" { | |
5 | assert [ ! -d "${RBENV_ROOT}/shims" ] | |
6 | assert [ ! -d "${RBENV_ROOT}/versions" ] | |
7 | run rbenv-init - | |
8 | assert_success | |
9 | assert [ -d "${RBENV_ROOT}/shims" ] | |
10 | assert [ -d "${RBENV_ROOT}/versions" ] | |
11 | } | |
12 | ||
13 | @test "auto rehash" { | |
14 | run rbenv-init - | |
15 | assert_success | |
16 | assert_line "command rbenv rehash 2>/dev/null" | |
17 | } | |
18 | ||
19 | @test "setup shell completions" { | |
20 | root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" | |
21 | run rbenv-init - bash | |
22 | assert_success | |
23 | assert_line "source '${root}/test/../libexec/../completions/rbenv.bash'" | |
24 | } | |
25 | ||
26 | @test "detect parent shell" { | |
27 | SHELL=/bin/false run rbenv-init - | |
28 | assert_success | |
29 | assert_line "export RBENV_SHELL=bash" | |
30 | } | |
31 | ||
32 | @test "detect parent shell from script" { | |
33 | mkdir -p "$RBENV_TEST_DIR" | |
34 | cd "$RBENV_TEST_DIR" | |
35 | cat > myscript.sh <<OUT | |
36 | #!/bin/sh | |
37 | eval "\$(rbenv-init -)" | |
38 | echo \$RBENV_SHELL | |
39 | OUT | |
40 | chmod +x myscript.sh | |
41 | run ./myscript.sh /bin/zsh | |
42 | assert_success "sh" | |
43 | } | |
44 | ||
45 | @test "setup shell completions (fish)" { | |
46 | root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" | |
47 | run rbenv-init - fish | |
48 | assert_success | |
49 | assert_line ". '${root}/test/../libexec/../completions/rbenv.fish'" | |
50 | } | |
51 | ||
52 | @test "fish instructions" { | |
53 | run rbenv-init fish | |
54 | assert [ "$status" -eq 1 ] | |
55 | assert_line 'status --is-interactive; and . (rbenv init -|psub)' | |
56 | } | |
57 | ||
58 | @test "option to skip rehash" { | |
59 | run rbenv-init - --no-rehash | |
60 | assert_success | |
61 | refute_line "rbenv rehash 2>/dev/null" | |
62 | } | |
63 | ||
64 | @test "adds shims to PATH" { | |
65 | export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" | |
66 | run rbenv-init - bash | |
67 | assert_success | |
68 | assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' | |
69 | } | |
70 | ||
71 | @test "adds shims to PATH (fish)" { | |
72 | export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin" | |
73 | run rbenv-init - fish | |
74 | assert_success | |
75 | assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" | |
76 | } | |
77 | ||
78 | @test "can add shims to PATH more than once" { | |
79 | export PATH="${RBENV_ROOT}/shims:$PATH" | |
80 | run rbenv-init - bash | |
81 | assert_success | |
82 | assert_line 0 'export PATH="'${RBENV_ROOT}'/shims:${PATH}"' | |
83 | } | |
84 | ||
85 | @test "can add shims to PATH more than once (fish)" { | |
86 | export PATH="${RBENV_ROOT}/shims:$PATH" | |
87 | run rbenv-init - fish | |
88 | assert_success | |
89 | assert_line 0 "setenv PATH '${RBENV_ROOT}/shims' \$PATH" | |
90 | } | |
91 | ||
92 | @test "outputs sh-compatible syntax" { | |
93 | run rbenv-init - bash | |
94 | assert_success | |
95 | assert_line ' case "$command" in' | |
96 | ||
97 | run rbenv-init - zsh | |
98 | assert_success | |
99 | assert_line ' case "$command" in' | |
100 | } | |
101 | ||
102 | @test "outputs fish-specific syntax (fish)" { | |
103 | run rbenv-init - fish | |
104 | assert_success | |
105 | assert_line ' switch "$command"' | |
106 | refute_line ' case "$command" in' | |
107 | } |
0 | #!/usr/bin/env bash | |
1 | # Usage: rbenv echo [-F<char>] VAR | |
2 | ||
3 | if [[ $1 == -F* ]]; then | |
4 | sep="${1:2}" | |
5 | echo "${!2}" | tr "${sep:-:}" $'\n' | |
6 | else | |
7 | echo "${!1}" | |
8 | fi |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | setup() { | |
5 | mkdir -p "${RBENV_TEST_DIR}/myproject" | |
6 | cd "${RBENV_TEST_DIR}/myproject" | |
7 | } | |
8 | ||
9 | @test "no version" { | |
10 | assert [ ! -e "${PWD}/.ruby-version" ] | |
11 | run rbenv-local | |
12 | assert_failure "rbenv: no local version configured for this directory" | |
13 | } | |
14 | ||
15 | @test "local version" { | |
16 | echo "1.2.3" > .ruby-version | |
17 | run rbenv-local | |
18 | assert_success "1.2.3" | |
19 | } | |
20 | ||
21 | @test "supports legacy .rbenv-version file" { | |
22 | echo "1.2.3" > .rbenv-version | |
23 | run rbenv-local | |
24 | assert_success "1.2.3" | |
25 | } | |
26 | ||
27 | @test "local .ruby-version has precedence over .rbenv-version" { | |
28 | echo "1.8" > .rbenv-version | |
29 | echo "2.0" > .ruby-version | |
30 | run rbenv-local | |
31 | assert_success "2.0" | |
32 | } | |
33 | ||
34 | @test "discovers version file in parent directory" { | |
35 | echo "1.2.3" > .ruby-version | |
36 | mkdir -p "subdir" && cd "subdir" | |
37 | run rbenv-local | |
38 | assert_success "1.2.3" | |
39 | } | |
40 | ||
41 | @test "ignores RBENV_DIR" { | |
42 | echo "1.2.3" > .ruby-version | |
43 | mkdir -p "$HOME" | |
44 | echo "2.0-home" > "${HOME}/.ruby-version" | |
45 | RBENV_DIR="$HOME" run rbenv-local | |
46 | assert_success "1.2.3" | |
47 | } | |
48 | ||
49 | @test "sets local version" { | |
50 | mkdir -p "${RBENV_ROOT}/versions/1.2.3" | |
51 | run rbenv-local 1.2.3 | |
52 | assert_success "" | |
53 | assert [ "$(cat .ruby-version)" = "1.2.3" ] | |
54 | } | |
55 | ||
56 | @test "changes local version" { | |
57 | echo "1.0-pre" > .ruby-version | |
58 | mkdir -p "${RBENV_ROOT}/versions/1.2.3" | |
59 | run rbenv-local | |
60 | assert_success "1.0-pre" | |
61 | run rbenv-local 1.2.3 | |
62 | assert_success "" | |
63 | assert [ "$(cat .ruby-version)" = "1.2.3" ] | |
64 | } | |
65 | ||
66 | @test "renames .rbenv-version to .ruby-version" { | |
67 | echo "1.8.7" > .rbenv-version | |
68 | mkdir -p "${RBENV_ROOT}/versions/1.9.3" | |
69 | run rbenv-local | |
70 | assert_success "1.8.7" | |
71 | run rbenv-local "1.9.3" | |
72 | assert_success | |
73 | assert_output <<OUT | |
74 | rbenv: removed existing \`.rbenv-version' file and migrated | |
75 | local version specification to \`.ruby-version' file | |
76 | OUT | |
77 | assert [ ! -e .rbenv-version ] | |
78 | assert [ "$(cat .ruby-version)" = "1.9.3" ] | |
79 | } | |
80 | ||
81 | @test "doesn't rename .rbenv-version if changing the version failed" { | |
82 | echo "1.8.7" > .rbenv-version | |
83 | assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ] | |
84 | run rbenv-local "1.9.3" | |
85 | assert_failure "rbenv: version \`1.9.3' not installed" | |
86 | assert [ ! -e .ruby-version ] | |
87 | assert [ "$(cat .rbenv-version)" = "1.8.7" ] | |
88 | } | |
89 | ||
90 | @test "unsets local version" { | |
91 | touch .ruby-version | |
92 | run rbenv-local --unset | |
93 | assert_success "" | |
94 | assert [ ! -e .rbenv-version ] | |
95 | } | |
96 | ||
97 | @test "unsets alternate version file" { | |
98 | touch .rbenv-version | |
99 | run rbenv-local --unset | |
100 | assert_success "" | |
101 | assert [ ! -e .rbenv-version ] | |
102 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "prefix" { | |
5 | mkdir -p "${RBENV_TEST_DIR}/myproject" | |
6 | cd "${RBENV_TEST_DIR}/myproject" | |
7 | echo "1.2.3" > .ruby-version | |
8 | mkdir -p "${RBENV_ROOT}/versions/1.2.3" | |
9 | run rbenv-prefix | |
10 | assert_success "${RBENV_ROOT}/versions/1.2.3" | |
11 | } | |
12 | ||
13 | @test "prefix for invalid version" { | |
14 | RBENV_VERSION="1.2.3" run rbenv-prefix | |
15 | assert_failure "rbenv: version \`1.2.3' not installed" | |
16 | } | |
17 | ||
18 | @test "prefix for system" { | |
19 | mkdir -p "${RBENV_TEST_DIR}/bin" | |
20 | touch "${RBENV_TEST_DIR}/bin/ruby" | |
21 | chmod +x "${RBENV_TEST_DIR}/bin/ruby" | |
22 | RBENV_VERSION="system" run rbenv-prefix | |
23 | assert_success "$RBENV_TEST_DIR" | |
24 | } | |
25 | ||
26 | @test "prefix for invalid system" { | |
27 | PATH="$(path_without ruby)" run rbenv-prefix system | |
28 | assert_failure "rbenv: system version not found in PATH" | |
29 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "blank invocation" { | |
5 | run rbenv | |
6 | assert_failure | |
7 | assert_line 0 "$(rbenv---version)" | |
8 | } | |
9 | ||
10 | @test "invalid command" { | |
11 | run rbenv does-not-exist | |
12 | assert_failure | |
13 | assert_output "rbenv: no such command \`does-not-exist'" | |
14 | } | |
15 | ||
16 | @test "default RBENV_ROOT" { | |
17 | RBENV_ROOT="" HOME=/home/mislav run rbenv root | |
18 | assert_success | |
19 | assert_output "/home/mislav/.rbenv" | |
20 | } | |
21 | ||
22 | @test "inherited RBENV_ROOT" { | |
23 | RBENV_ROOT=/opt/rbenv run rbenv root | |
24 | assert_success | |
25 | assert_output "/opt/rbenv" | |
26 | } | |
27 | ||
28 | @test "default RBENV_DIR" { | |
29 | run rbenv echo RBENV_DIR | |
30 | assert_output "$(pwd)" | |
31 | } | |
32 | ||
33 | @test "inherited RBENV_DIR" { | |
34 | dir="${BATS_TMPDIR}/myproject" | |
35 | mkdir -p "$dir" | |
36 | RBENV_DIR="$dir" run rbenv echo RBENV_DIR | |
37 | assert_output "$dir" | |
38 | } | |
39 | ||
40 | @test "invalid RBENV_DIR" { | |
41 | dir="${BATS_TMPDIR}/does-not-exist" | |
42 | assert [ ! -d "$dir" ] | |
43 | RBENV_DIR="$dir" run rbenv echo RBENV_DIR | |
44 | assert_failure | |
45 | assert_output "rbenv: cannot change working directory to \`$dir'" | |
46 | } | |
47 | ||
48 | @test "adds its own libexec to PATH" { | |
49 | run rbenv echo "PATH" | |
50 | assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH" | |
51 | } | |
52 | ||
53 | @test "adds plugin bin dirs to PATH" { | |
54 | mkdir -p "$RBENV_ROOT"/plugins/ruby-build/bin | |
55 | mkdir -p "$RBENV_ROOT"/plugins/rbenv-each/bin | |
56 | run rbenv echo -F: "PATH" | |
57 | assert_success | |
58 | assert_line 0 "${BATS_TEST_DIRNAME%/*}/libexec" | |
59 | assert_line 1 "${RBENV_ROOT}/plugins/ruby-build/bin" | |
60 | assert_line 2 "${RBENV_ROOT}/plugins/rbenv-each/bin" | |
61 | } | |
62 | ||
63 | @test "RBENV_HOOK_PATH preserves value from environment" { | |
64 | RBENV_HOOK_PATH=/my/hook/path:/other/hooks run rbenv echo -F: "RBENV_HOOK_PATH" | |
65 | assert_success | |
66 | assert_line 0 "/my/hook/path" | |
67 | assert_line 1 "/other/hooks" | |
68 | assert_line 2 "${RBENV_ROOT}/rbenv.d" | |
69 | } | |
70 | ||
71 | @test "RBENV_HOOK_PATH includes rbenv built-in plugins" { | |
72 | run rbenv echo "RBENV_HOOK_PATH" | |
73 | assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" | |
74 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_executable() { | |
5 | local bin="${RBENV_ROOT}/versions/${1}/bin" | |
6 | mkdir -p "$bin" | |
7 | touch "${bin}/$2" | |
8 | chmod +x "${bin}/$2" | |
9 | } | |
10 | ||
11 | @test "empty rehash" { | |
12 | assert [ ! -d "${RBENV_ROOT}/shims" ] | |
13 | run rbenv-rehash | |
14 | assert_success "" | |
15 | assert [ -d "${RBENV_ROOT}/shims" ] | |
16 | rmdir "${RBENV_ROOT}/shims" | |
17 | } | |
18 | ||
19 | @test "non-writable shims directory" { | |
20 | mkdir -p "${RBENV_ROOT}/shims" | |
21 | chmod -w "${RBENV_ROOT}/shims" | |
22 | run rbenv-rehash | |
23 | assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" | |
24 | } | |
25 | ||
26 | @test "rehash in progress" { | |
27 | mkdir -p "${RBENV_ROOT}/shims" | |
28 | touch "${RBENV_ROOT}/shims/.rbenv-shim" | |
29 | run rbenv-rehash | |
30 | assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" | |
31 | } | |
32 | ||
33 | @test "creates shims" { | |
34 | create_executable "1.8" "ruby" | |
35 | create_executable "1.8" "rake" | |
36 | create_executable "2.0" "ruby" | |
37 | create_executable "2.0" "rspec" | |
38 | ||
39 | assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] | |
40 | assert [ ! -e "${RBENV_ROOT}/shims/rake" ] | |
41 | assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] | |
42 | ||
43 | run rbenv-rehash | |
44 | assert_success "" | |
45 | ||
46 | run ls "${RBENV_ROOT}/shims" | |
47 | assert_success | |
48 | assert_output <<OUT | |
49 | rake | |
50 | rspec | |
51 | ruby | |
52 | OUT | |
53 | } | |
54 | ||
55 | @test "removes outdated shims" { | |
56 | mkdir -p "${RBENV_ROOT}/shims" | |
57 | touch "${RBENV_ROOT}/shims/oldshim1" | |
58 | chmod +x "${RBENV_ROOT}/shims/oldshim1" | |
59 | ||
60 | create_executable "2.0" "rake" | |
61 | create_executable "2.0" "ruby" | |
62 | ||
63 | run rbenv-rehash | |
64 | assert_success "" | |
65 | ||
66 | assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ] | |
67 | } | |
68 | ||
69 | @test "do exact matches when removing stale shims" { | |
70 | create_executable "2.0" "unicorn_rails" | |
71 | create_executable "2.0" "rspec-core" | |
72 | ||
73 | rbenv-rehash | |
74 | ||
75 | cp "$RBENV_ROOT"/shims/{rspec-core,rspec} | |
76 | cp "$RBENV_ROOT"/shims/{rspec-core,rails} | |
77 | cp "$RBENV_ROOT"/shims/{rspec-core,uni} | |
78 | chmod +x "$RBENV_ROOT"/shims/{rspec,rails,uni} | |
79 | ||
80 | run rbenv-rehash | |
81 | assert_success "" | |
82 | ||
83 | assert [ ! -e "${RBENV_ROOT}/shims/rails" ] | |
84 | assert [ ! -e "${RBENV_ROOT}/shims/rake" ] | |
85 | assert [ ! -e "${RBENV_ROOT}/shims/uni" ] | |
86 | } | |
87 | ||
88 | @test "binary install locations containing spaces" { | |
89 | create_executable "dirname1 p247" "ruby" | |
90 | create_executable "dirname2 preview1" "rspec" | |
91 | ||
92 | assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] | |
93 | assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] | |
94 | ||
95 | run rbenv-rehash | |
96 | assert_success "" | |
97 | ||
98 | run ls "${RBENV_ROOT}/shims" | |
99 | assert_success | |
100 | assert_output <<OUT | |
101 | rspec | |
102 | ruby | |
103 | OUT | |
104 | } | |
105 | ||
106 | @test "carries original IFS within hooks" { | |
107 | hook_path="${RBENV_TEST_DIR}/rbenv.d" | |
108 | mkdir -p "${hook_path}/rehash" | |
109 | cat > "${hook_path}/rehash/hello.bash" <<SH | |
110 | hellos=(\$(printf "hello\\tugly world\\nagain")) | |
111 | echo HELLO="\$(printf ":%s" "\${hellos[@]}")" | |
112 | exit | |
113 | SH | |
114 | ||
115 | RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-rehash | |
116 | assert_success | |
117 | assert_output "HELLO=:hello:ugly:world:again" | |
118 | } | |
119 | ||
120 | @test "sh-rehash in bash" { | |
121 | create_executable "2.0" "ruby" | |
122 | RBENV_SHELL=bash run rbenv-sh-rehash | |
123 | assert_success "hash -r 2>/dev/null || true" | |
124 | assert [ -x "${RBENV_ROOT}/shims/ruby" ] | |
125 | } | |
126 | ||
127 | @test "sh-rehash in fish" { | |
128 | create_executable "2.0" "ruby" | |
129 | RBENV_SHELL=fish run rbenv-sh-rehash | |
130 | assert_success "" | |
131 | assert [ -x "${RBENV_ROOT}/shims/ruby" ] | |
132 | } |
0 | #!/usr/bin/env bash | |
1 | set -e | |
2 | ||
3 | if [ -n "$RBENV_NATIVE_EXT" ]; then | |
4 | src/configure | |
5 | make -C src | |
6 | fi | |
7 | ||
8 | exec bats ${CI:+--tap} test |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "no shell version" { | |
5 | mkdir -p "${RBENV_TEST_DIR}/myproject" | |
6 | cd "${RBENV_TEST_DIR}/myproject" | |
7 | echo "1.2.3" > .ruby-version | |
8 | RBENV_VERSION="" run rbenv-sh-shell | |
9 | assert_failure "rbenv: no shell-specific version configured" | |
10 | } | |
11 | ||
12 | @test "shell version" { | |
13 | RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell | |
14 | assert_success 'echo "$RBENV_VERSION"' | |
15 | } | |
16 | ||
17 | @test "shell version (fish)" { | |
18 | RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell | |
19 | assert_success 'echo "$RBENV_VERSION"' | |
20 | } | |
21 | ||
22 | @test "shell unset" { | |
23 | RBENV_SHELL=bash run rbenv-sh-shell --unset | |
24 | assert_success "unset RBENV_VERSION" | |
25 | } | |
26 | ||
27 | @test "shell unset (fish)" { | |
28 | RBENV_SHELL=fish run rbenv-sh-shell --unset | |
29 | assert_success "set -e RBENV_VERSION" | |
30 | } | |
31 | ||
32 | @test "shell change invalid version" { | |
33 | run rbenv-sh-shell 1.2.3 | |
34 | assert_failure | |
35 | assert_output <<SH | |
36 | rbenv: version \`1.2.3' not installed | |
37 | false | |
38 | SH | |
39 | } | |
40 | ||
41 | @test "shell change version" { | |
42 | mkdir -p "${RBENV_ROOT}/versions/1.2.3" | |
43 | RBENV_SHELL=bash run rbenv-sh-shell 1.2.3 | |
44 | assert_success 'export RBENV_VERSION="1.2.3"' | |
45 | } | |
46 | ||
47 | @test "shell change version (fish)" { | |
48 | mkdir -p "${RBENV_ROOT}/versions/1.2.3" | |
49 | RBENV_SHELL=fish run rbenv-sh-shell 1.2.3 | |
50 | assert_success 'setenv RBENV_VERSION "1.2.3"' | |
51 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | @test "no shims" { | |
5 | run rbenv-shims | |
6 | assert_success | |
7 | assert [ -z "$output" ] | |
8 | } | |
9 | ||
10 | @test "shims" { | |
11 | mkdir -p "${RBENV_ROOT}/shims" | |
12 | touch "${RBENV_ROOT}/shims/ruby" | |
13 | touch "${RBENV_ROOT}/shims/irb" | |
14 | run rbenv-shims | |
15 | assert_success | |
16 | assert_line "${RBENV_ROOT}/shims/ruby" | |
17 | assert_line "${RBENV_ROOT}/shims/irb" | |
18 | } | |
19 | ||
20 | @test "shims --short" { | |
21 | mkdir -p "${RBENV_ROOT}/shims" | |
22 | touch "${RBENV_ROOT}/shims/ruby" | |
23 | touch "${RBENV_ROOT}/shims/irb" | |
24 | run rbenv-shims --short | |
25 | assert_success | |
26 | assert_line "irb" | |
27 | assert_line "ruby" | |
28 | } |
0 | unset RBENV_VERSION | |
1 | unset RBENV_DIR | |
2 | ||
3 | # guard against executing this block twice due to bats internals | |
4 | if [ -z "$RBENV_TEST_DIR" ]; then | |
5 | RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" | |
6 | export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")" | |
7 | ||
8 | if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then | |
9 | export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")" | |
10 | else | |
11 | if [ -n "$RBENV_NATIVE_EXT" ]; then | |
12 | echo "rbenv: failed to load \`realpath' builtin" >&2 | |
13 | exit 1 | |
14 | fi | |
15 | fi | |
16 | ||
17 | export RBENV_ROOT="${RBENV_TEST_DIR}/root" | |
18 | export HOME="${RBENV_TEST_DIR}/home" | |
19 | ||
20 | PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin | |
21 | PATH="${RBENV_TEST_DIR}/bin:$PATH" | |
22 | PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" | |
23 | PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" | |
24 | PATH="${RBENV_ROOT}/shims:$PATH" | |
25 | export PATH | |
26 | ||
27 | for xdg_var in `env 2>/dev/null | grep ^XDG_ | cut -d= -f1`; do unset "$xdg_var"; done | |
28 | unset xdg_var | |
29 | fi | |
30 | ||
31 | teardown() { | |
32 | rm -rf "$RBENV_TEST_DIR" | |
33 | } | |
34 | ||
35 | flunk() { | |
36 | { if [ "$#" -eq 0 ]; then cat - | |
37 | else echo "$@" | |
38 | fi | |
39 | } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2 | |
40 | return 1 | |
41 | } | |
42 | ||
43 | assert_success() { | |
44 | if [ "$status" -ne 0 ]; then | |
45 | flunk "command failed with exit status $status" | |
46 | elif [ "$#" -gt 0 ]; then | |
47 | assert_output "$1" | |
48 | fi | |
49 | } | |
50 | ||
51 | assert_failure() { | |
52 | if [ "$status" -eq 0 ]; then | |
53 | flunk "expected failed exit status" | |
54 | elif [ "$#" -gt 0 ]; then | |
55 | assert_output "$1" | |
56 | fi | |
57 | } | |
58 | ||
59 | assert_equal() { | |
60 | if [ "$1" != "$2" ]; then | |
61 | { echo "expected: $1" | |
62 | echo "actual: $2" | |
63 | } | flunk | |
64 | fi | |
65 | } | |
66 | ||
67 | assert_output() { | |
68 | local expected | |
69 | if [ $# -eq 0 ]; then expected="$(cat -)" | |
70 | else expected="$1" | |
71 | fi | |
72 | assert_equal "$expected" "$output" | |
73 | } | |
74 | ||
75 | assert_line() { | |
76 | if [ "$1" -ge 0 ] 2>/dev/null; then | |
77 | assert_equal "$2" "${lines[$1]}" | |
78 | else | |
79 | local line | |
80 | for line in "${lines[@]}"; do | |
81 | if [ "$line" = "$1" ]; then return 0; fi | |
82 | done | |
83 | flunk "expected line \`$1'" | |
84 | fi | |
85 | } | |
86 | ||
87 | refute_line() { | |
88 | if [ "$1" -ge 0 ] 2>/dev/null; then | |
89 | local num_lines="${#lines[@]}" | |
90 | if [ "$1" -lt "$num_lines" ]; then | |
91 | flunk "output has $num_lines lines" | |
92 | fi | |
93 | else | |
94 | local line | |
95 | for line in "${lines[@]}"; do | |
96 | if [ "$line" = "$1" ]; then | |
97 | flunk "expected to not find line \`$line'" | |
98 | fi | |
99 | done | |
100 | fi | |
101 | } | |
102 | ||
103 | assert() { | |
104 | if ! "$@"; then | |
105 | flunk "failed: $@" | |
106 | fi | |
107 | } | |
108 | ||
109 | # Output a modified PATH that ensures that the given executable is not present, | |
110 | # but in which system utils necessary for rbenv operation are still available. | |
111 | path_without() { | |
112 | local exe="$1" | |
113 | local path=":${PATH}:" | |
114 | local found alt util | |
115 | for found in $(which -a "$exe"); do | |
116 | found="${found%/*}" | |
117 | if [ "$found" != "${RBENV_ROOT}/shims" ]; then | |
118 | alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" | |
119 | mkdir -p "$alt" | |
120 | for util in bash head cut readlink greadlink; do | |
121 | if [ -x "${found}/$util" ]; then | |
122 | ln -s "${found}/$util" "${alt}/$util" | |
123 | fi | |
124 | done | |
125 | path="${path/:${found}:/:${alt}:}" | |
126 | fi | |
127 | done | |
128 | path="${path#:}" | |
129 | echo "${path%:}" | |
130 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | setup() { | |
5 | mkdir -p "${RBENV_TEST_DIR}/myproject" | |
6 | cd "${RBENV_TEST_DIR}/myproject" | |
7 | } | |
8 | ||
9 | @test "fails without arguments" { | |
10 | run rbenv-version-file-read | |
11 | assert_failure "" | |
12 | } | |
13 | ||
14 | @test "fails for invalid file" { | |
15 | run rbenv-version-file-read "non-existent" | |
16 | assert_failure "" | |
17 | } | |
18 | ||
19 | @test "fails for blank file" { | |
20 | echo > my-version | |
21 | run rbenv-version-file-read my-version | |
22 | assert_failure "" | |
23 | } | |
24 | ||
25 | @test "reads simple version file" { | |
26 | cat > my-version <<<"1.9.3" | |
27 | run rbenv-version-file-read my-version | |
28 | assert_success "1.9.3" | |
29 | } | |
30 | ||
31 | @test "ignores leading spaces" { | |
32 | cat > my-version <<<" 1.9.3" | |
33 | run rbenv-version-file-read my-version | |
34 | assert_success "1.9.3" | |
35 | } | |
36 | ||
37 | @test "reads only the first word from file" { | |
38 | cat > my-version <<<"1.9.3-p194@tag 1.8.7 hi" | |
39 | run rbenv-version-file-read my-version | |
40 | assert_success "1.9.3-p194@tag" | |
41 | } | |
42 | ||
43 | @test "loads only the first line in file" { | |
44 | cat > my-version <<IN | |
45 | 1.8.7 one | |
46 | 1.9.3 two | |
47 | IN | |
48 | run rbenv-version-file-read my-version | |
49 | assert_success "1.8.7" | |
50 | } | |
51 | ||
52 | @test "ignores leading blank lines" { | |
53 | cat > my-version <<IN | |
54 | ||
55 | 1.9.3 | |
56 | IN | |
57 | run rbenv-version-file-read my-version | |
58 | assert_success "1.9.3" | |
59 | } | |
60 | ||
61 | @test "handles the file with no trailing newline" { | |
62 | echo -n "1.8.7" > my-version | |
63 | run rbenv-version-file-read my-version | |
64 | assert_success "1.8.7" | |
65 | } | |
66 | ||
67 | @test "ignores carriage returns" { | |
68 | cat > my-version <<< $'1.9.3\r' | |
69 | run rbenv-version-file-read my-version | |
70 | assert_success "1.9.3" | |
71 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | setup() { | |
5 | mkdir -p "$RBENV_TEST_DIR" | |
6 | cd "$RBENV_TEST_DIR" | |
7 | } | |
8 | ||
9 | @test "invocation without 2 arguments prints usage" { | |
10 | run rbenv-version-file-write | |
11 | assert_failure "Usage: rbenv version-file-write <file> <version>" | |
12 | run rbenv-version-file-write "one" "" | |
13 | assert_failure | |
14 | } | |
15 | ||
16 | @test "setting nonexistent version fails" { | |
17 | assert [ ! -e ".ruby-version" ] | |
18 | run rbenv-version-file-write ".ruby-version" "1.8.7" | |
19 | assert_failure "rbenv: version \`1.8.7' not installed" | |
20 | assert [ ! -e ".ruby-version" ] | |
21 | } | |
22 | ||
23 | @test "writes value to arbitrary file" { | |
24 | mkdir -p "${RBENV_ROOT}/versions/1.8.7" | |
25 | assert [ ! -e "my-version" ] | |
26 | run rbenv-version-file-write "${PWD}/my-version" "1.8.7" | |
27 | assert_success "" | |
28 | assert [ "$(cat my-version)" = "1.8.7" ] | |
29 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | setup() { | |
5 | mkdir -p "$RBENV_TEST_DIR" | |
6 | cd "$RBENV_TEST_DIR" | |
7 | } | |
8 | ||
9 | create_file() { | |
10 | mkdir -p "$(dirname "$1")" | |
11 | touch "$1" | |
12 | } | |
13 | ||
14 | @test "prints global file if no version files exist" { | |
15 | assert [ ! -e "${RBENV_ROOT}/version" ] | |
16 | assert [ ! -e ".ruby-version" ] | |
17 | run rbenv-version-file | |
18 | assert_success "${RBENV_ROOT}/version" | |
19 | } | |
20 | ||
21 | @test "detects 'global' file" { | |
22 | create_file "${RBENV_ROOT}/global" | |
23 | run rbenv-version-file | |
24 | assert_success "${RBENV_ROOT}/global" | |
25 | } | |
26 | ||
27 | @test "detects 'default' file" { | |
28 | create_file "${RBENV_ROOT}/default" | |
29 | run rbenv-version-file | |
30 | assert_success "${RBENV_ROOT}/default" | |
31 | } | |
32 | ||
33 | @test "'version' has precedence over 'global' and 'default'" { | |
34 | create_file "${RBENV_ROOT}/version" | |
35 | create_file "${RBENV_ROOT}/global" | |
36 | create_file "${RBENV_ROOT}/default" | |
37 | run rbenv-version-file | |
38 | assert_success "${RBENV_ROOT}/version" | |
39 | } | |
40 | ||
41 | @test "in current directory" { | |
42 | create_file ".ruby-version" | |
43 | run rbenv-version-file | |
44 | assert_success "${RBENV_TEST_DIR}/.ruby-version" | |
45 | } | |
46 | ||
47 | @test "legacy file in current directory" { | |
48 | create_file ".rbenv-version" | |
49 | run rbenv-version-file | |
50 | assert_success "${RBENV_TEST_DIR}/.rbenv-version" | |
51 | } | |
52 | ||
53 | @test ".ruby-version has precedence over legacy file" { | |
54 | create_file ".ruby-version" | |
55 | create_file ".rbenv-version" | |
56 | run rbenv-version-file | |
57 | assert_success "${RBENV_TEST_DIR}/.ruby-version" | |
58 | } | |
59 | ||
60 | @test "in parent directory" { | |
61 | create_file ".ruby-version" | |
62 | mkdir -p project | |
63 | cd project | |
64 | run rbenv-version-file | |
65 | assert_success "${RBENV_TEST_DIR}/.ruby-version" | |
66 | } | |
67 | ||
68 | @test "topmost file has precedence" { | |
69 | create_file ".ruby-version" | |
70 | create_file "project/.ruby-version" | |
71 | cd project | |
72 | run rbenv-version-file | |
73 | assert_success "${RBENV_TEST_DIR}/project/.ruby-version" | |
74 | } | |
75 | ||
76 | @test "legacy file has precedence if higher" { | |
77 | create_file ".ruby-version" | |
78 | create_file "project/.rbenv-version" | |
79 | cd project | |
80 | run rbenv-version-file | |
81 | assert_success "${RBENV_TEST_DIR}/project/.rbenv-version" | |
82 | } | |
83 | ||
84 | @test "RBENV_DIR has precedence over PWD" { | |
85 | create_file "widget/.ruby-version" | |
86 | create_file "project/.ruby-version" | |
87 | cd project | |
88 | RBENV_DIR="${RBENV_TEST_DIR}/widget" run rbenv-version-file | |
89 | assert_success "${RBENV_TEST_DIR}/widget/.ruby-version" | |
90 | } | |
91 | ||
92 | @test "PWD is searched if RBENV_DIR yields no results" { | |
93 | mkdir -p "widget/blank" | |
94 | create_file "project/.ruby-version" | |
95 | cd project | |
96 | RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file | |
97 | assert_success "${RBENV_TEST_DIR}/project/.ruby-version" | |
98 | } | |
99 | ||
100 | @test "finds version file in target directory" { | |
101 | create_file "project/.ruby-version" | |
102 | run rbenv-version-file "${PWD}/project" | |
103 | assert_success "${RBENV_TEST_DIR}/project/.ruby-version" | |
104 | } | |
105 | ||
106 | @test "fails when no version file in target directory" { | |
107 | run rbenv-version-file "$PWD" | |
108 | assert_failure "" | |
109 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_version() { | |
5 | mkdir -p "${RBENV_ROOT}/versions/$1" | |
6 | } | |
7 | ||
8 | setup() { | |
9 | mkdir -p "$RBENV_TEST_DIR" | |
10 | cd "$RBENV_TEST_DIR" | |
11 | } | |
12 | ||
13 | @test "no version selected" { | |
14 | assert [ ! -d "${RBENV_ROOT}/versions" ] | |
15 | run rbenv-version-name | |
16 | assert_success "system" | |
17 | } | |
18 | ||
19 | @test "system version is not checked for existance" { | |
20 | RBENV_VERSION=system run rbenv-version-name | |
21 | assert_success "system" | |
22 | } | |
23 | ||
24 | @test "RBENV_VERSION can be overridden by hook" { | |
25 | create_version "1.8.7" | |
26 | create_version "1.9.3" | |
27 | ||
28 | mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" | |
29 | cat > "${RBENV_ROOT}/rbenv.d/version-name/test.bash" <<HOOK | |
30 | RBENV_VERSION=1.9.3 | |
31 | HOOK | |
32 | ||
33 | RBENV_VERSION=1.8.7 RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" run rbenv-version-name | |
34 | assert_success "1.9.3" | |
35 | } | |
36 | ||
37 | @test "RBENV_VERSION has precedence over local" { | |
38 | create_version "1.8.7" | |
39 | create_version "1.9.3" | |
40 | ||
41 | cat > ".ruby-version" <<<"1.8.7" | |
42 | run rbenv-version-name | |
43 | assert_success "1.8.7" | |
44 | ||
45 | RBENV_VERSION=1.9.3 run rbenv-version-name | |
46 | assert_success "1.9.3" | |
47 | } | |
48 | ||
49 | @test "local file has precedence over global" { | |
50 | create_version "1.8.7" | |
51 | create_version "1.9.3" | |
52 | ||
53 | cat > "${RBENV_ROOT}/version" <<<"1.8.7" | |
54 | run rbenv-version-name | |
55 | assert_success "1.8.7" | |
56 | ||
57 | cat > ".ruby-version" <<<"1.9.3" | |
58 | run rbenv-version-name | |
59 | assert_success "1.9.3" | |
60 | } | |
61 | ||
62 | @test "missing version" { | |
63 | RBENV_VERSION=1.2 run rbenv-version-name | |
64 | assert_failure "rbenv: version \`1.2' is not installed (set by RBENV_VERSION environment variable)" | |
65 | } | |
66 | ||
67 | @test "version with prefix in name" { | |
68 | create_version "1.8.7" | |
69 | cat > ".ruby-version" <<<"ruby-1.8.7" | |
70 | run rbenv-version-name | |
71 | assert_success | |
72 | assert_output "1.8.7" | |
73 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | setup() { | |
5 | mkdir -p "$RBENV_TEST_DIR" | |
6 | cd "$RBENV_TEST_DIR" | |
7 | } | |
8 | ||
9 | @test "reports global file even if it doesn't exist" { | |
10 | assert [ ! -e "${RBENV_ROOT}/version" ] | |
11 | run rbenv-version-origin | |
12 | assert_success "${RBENV_ROOT}/version" | |
13 | } | |
14 | ||
15 | @test "detects global file" { | |
16 | mkdir -p "$RBENV_ROOT" | |
17 | touch "${RBENV_ROOT}/version" | |
18 | run rbenv-version-origin | |
19 | assert_success "${RBENV_ROOT}/version" | |
20 | } | |
21 | ||
22 | @test "detects RBENV_VERSION" { | |
23 | RBENV_VERSION=1 run rbenv-version-origin | |
24 | assert_success "RBENV_VERSION environment variable" | |
25 | } | |
26 | ||
27 | @test "detects local file" { | |
28 | touch .ruby-version | |
29 | run rbenv-version-origin | |
30 | assert_success "${PWD}/.ruby-version" | |
31 | } | |
32 | ||
33 | @test "detects alternate version file" { | |
34 | touch .rbenv-version | |
35 | run rbenv-version-origin | |
36 | assert_success "${PWD}/.rbenv-version" | |
37 | } | |
38 | ||
39 | @test "reports from hook" { | |
40 | mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin" | |
41 | cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" <<HOOK | |
42 | RBENV_VERSION_ORIGIN=plugin | |
43 | HOOK | |
44 | ||
45 | RBENV_VERSION=1 RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" run rbenv-version-origin | |
46 | assert_success "plugin" | |
47 | } | |
48 | ||
49 | @test "doesn't inherit RBENV_VERSION_ORIGIN from environment" { | |
50 | RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin | |
51 | assert_success "${RBENV_ROOT}/version" | |
52 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_version() { | |
5 | mkdir -p "${RBENV_ROOT}/versions/$1" | |
6 | } | |
7 | ||
8 | setup() { | |
9 | mkdir -p "$RBENV_TEST_DIR" | |
10 | cd "$RBENV_TEST_DIR" | |
11 | } | |
12 | ||
13 | @test "no version selected" { | |
14 | assert [ ! -d "${RBENV_ROOT}/versions" ] | |
15 | run rbenv-version | |
16 | assert_success "system (set by ${RBENV_ROOT}/version)" | |
17 | } | |
18 | ||
19 | @test "set by RBENV_VERSION" { | |
20 | create_version "1.9.3" | |
21 | RBENV_VERSION=1.9.3 run rbenv-version | |
22 | assert_success "1.9.3 (set by RBENV_VERSION environment variable)" | |
23 | } | |
24 | ||
25 | @test "set by local file" { | |
26 | create_version "1.9.3" | |
27 | cat > ".ruby-version" <<<"1.9.3" | |
28 | run rbenv-version | |
29 | assert_success "1.9.3 (set by ${PWD}/.ruby-version)" | |
30 | } | |
31 | ||
32 | @test "set by global file" { | |
33 | create_version "1.9.3" | |
34 | cat > "${RBENV_ROOT}/version" <<<"1.9.3" | |
35 | run rbenv-version | |
36 | assert_success "1.9.3 (set by ${RBENV_ROOT}/version)" | |
37 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_version() { | |
5 | mkdir -p "${RBENV_ROOT}/versions/$1" | |
6 | } | |
7 | ||
8 | setup() { | |
9 | mkdir -p "$RBENV_TEST_DIR" | |
10 | cd "$RBENV_TEST_DIR" | |
11 | } | |
12 | ||
13 | stub_system_ruby() { | |
14 | local stub="${RBENV_TEST_DIR}/bin/ruby" | |
15 | mkdir -p "$(dirname "$stub")" | |
16 | touch "$stub" && chmod +x "$stub" | |
17 | } | |
18 | ||
19 | @test "no versions installed" { | |
20 | stub_system_ruby | |
21 | assert [ ! -d "${RBENV_ROOT}/versions" ] | |
22 | run rbenv-versions | |
23 | assert_success "* system (set by ${RBENV_ROOT}/version)" | |
24 | } | |
25 | ||
26 | @test "not even system ruby available" { | |
27 | PATH="$(path_without ruby)" run rbenv-versions | |
28 | assert_failure | |
29 | assert_output "Warning: no Ruby detected on the system" | |
30 | } | |
31 | ||
32 | @test "bare output no versions installed" { | |
33 | assert [ ! -d "${RBENV_ROOT}/versions" ] | |
34 | run rbenv-versions --bare | |
35 | assert_success "" | |
36 | } | |
37 | ||
38 | @test "single version installed" { | |
39 | stub_system_ruby | |
40 | create_version "1.9" | |
41 | run rbenv-versions | |
42 | assert_success | |
43 | assert_output <<OUT | |
44 | * system (set by ${RBENV_ROOT}/version) | |
45 | 1.9 | |
46 | OUT | |
47 | } | |
48 | ||
49 | @test "single version bare" { | |
50 | create_version "1.9" | |
51 | run rbenv-versions --bare | |
52 | assert_success "1.9" | |
53 | } | |
54 | ||
55 | @test "multiple versions" { | |
56 | stub_system_ruby | |
57 | create_version "1.8.7" | |
58 | create_version "1.9.3" | |
59 | create_version "2.0.0" | |
60 | run rbenv-versions | |
61 | assert_success | |
62 | assert_output <<OUT | |
63 | * system (set by ${RBENV_ROOT}/version) | |
64 | 1.8.7 | |
65 | 1.9.3 | |
66 | 2.0.0 | |
67 | OUT | |
68 | } | |
69 | ||
70 | @test "indicates current version" { | |
71 | stub_system_ruby | |
72 | create_version "1.9.3" | |
73 | create_version "2.0.0" | |
74 | RBENV_VERSION=1.9.3 run rbenv-versions | |
75 | assert_success | |
76 | assert_output <<OUT | |
77 | system | |
78 | * 1.9.3 (set by RBENV_VERSION environment variable) | |
79 | 2.0.0 | |
80 | OUT | |
81 | } | |
82 | ||
83 | @test "bare doesn't indicate current version" { | |
84 | create_version "1.9.3" | |
85 | create_version "2.0.0" | |
86 | RBENV_VERSION=1.9.3 run rbenv-versions --bare | |
87 | assert_success | |
88 | assert_output <<OUT | |
89 | 1.9.3 | |
90 | 2.0.0 | |
91 | OUT | |
92 | } | |
93 | ||
94 | @test "globally selected version" { | |
95 | stub_system_ruby | |
96 | create_version "1.9.3" | |
97 | create_version "2.0.0" | |
98 | cat > "${RBENV_ROOT}/version" <<<"1.9.3" | |
99 | run rbenv-versions | |
100 | assert_success | |
101 | assert_output <<OUT | |
102 | system | |
103 | * 1.9.3 (set by ${RBENV_ROOT}/version) | |
104 | 2.0.0 | |
105 | OUT | |
106 | } | |
107 | ||
108 | @test "per-project version" { | |
109 | stub_system_ruby | |
110 | create_version "1.9.3" | |
111 | create_version "2.0.0" | |
112 | cat > ".ruby-version" <<<"1.9.3" | |
113 | run rbenv-versions | |
114 | assert_success | |
115 | assert_output <<OUT | |
116 | system | |
117 | * 1.9.3 (set by ${RBENV_TEST_DIR}/.ruby-version) | |
118 | 2.0.0 | |
119 | OUT | |
120 | } | |
121 | ||
122 | @test "ignores non-directories under versions" { | |
123 | create_version "1.9" | |
124 | touch "${RBENV_ROOT}/versions/hello" | |
125 | ||
126 | run rbenv-versions --bare | |
127 | assert_success "1.9" | |
128 | } | |
129 | ||
130 | @test "lists symlinks under versions" { | |
131 | create_version "1.8.7" | |
132 | ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" | |
133 | ||
134 | run rbenv-versions --bare | |
135 | assert_success | |
136 | assert_output <<OUT | |
137 | 1.8 | |
138 | 1.8.7 | |
139 | OUT | |
140 | } | |
141 | ||
142 | @test "doesn't list symlink aliases when --skip-aliases" { | |
143 | create_version "1.8.7" | |
144 | ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" | |
145 | mkdir moo | |
146 | ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9" | |
147 | ||
148 | run rbenv-versions --bare --skip-aliases | |
149 | assert_success | |
150 | ||
151 | assert_output <<OUT | |
152 | 1.8.7 | |
153 | 1.9 | |
154 | OUT | |
155 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_executable() { | |
5 | local bin="${RBENV_ROOT}/versions/${1}/bin" | |
6 | mkdir -p "$bin" | |
7 | touch "${bin}/$2" | |
8 | chmod +x "${bin}/$2" | |
9 | } | |
10 | ||
11 | @test "finds versions where present" { | |
12 | create_executable "1.8" "ruby" | |
13 | create_executable "1.8" "rake" | |
14 | create_executable "2.0" "ruby" | |
15 | create_executable "2.0" "rspec" | |
16 | ||
17 | run rbenv-whence ruby | |
18 | assert_success | |
19 | assert_output <<OUT | |
20 | 1.8 | |
21 | 2.0 | |
22 | OUT | |
23 | ||
24 | run rbenv-whence rake | |
25 | assert_success "1.8" | |
26 | ||
27 | run rbenv-whence rspec | |
28 | assert_success "2.0" | |
29 | } |
0 | #!/usr/bin/env bats | |
1 | ||
2 | load test_helper | |
3 | ||
4 | create_executable() { | |
5 | local bin | |
6 | if [[ $1 == */* ]]; then bin="$1" | |
7 | else bin="${RBENV_ROOT}/versions/${1}/bin" | |
8 | fi | |
9 | mkdir -p "$bin" | |
10 | touch "${bin}/$2" | |
11 | chmod +x "${bin}/$2" | |
12 | } | |
13 | ||
14 | @test "outputs path to executable" { | |
15 | create_executable "1.8" "ruby" | |
16 | create_executable "2.0" "rspec" | |
17 | ||
18 | RBENV_VERSION=1.8 run rbenv-which ruby | |
19 | assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" | |
20 | ||
21 | RBENV_VERSION=2.0 run rbenv-which rspec | |
22 | assert_success "${RBENV_ROOT}/versions/2.0/bin/rspec" | |
23 | } | |
24 | ||
25 | @test "searches PATH for system version" { | |
26 | create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" | |
27 | create_executable "${RBENV_ROOT}/shims" "kill-all-humans" | |
28 | ||
29 | RBENV_VERSION=system run rbenv-which kill-all-humans | |
30 | assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" | |
31 | } | |
32 | ||
33 | @test "searches PATH for system version (shims prepended)" { | |
34 | create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" | |
35 | create_executable "${RBENV_ROOT}/shims" "kill-all-humans" | |
36 | ||
37 | PATH="${RBENV_ROOT}/shims:$PATH" RBENV_VERSION=system run rbenv-which kill-all-humans | |
38 | assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" | |
39 | } | |
40 | ||
41 | @test "searches PATH for system version (shims appended)" { | |
42 | create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" | |
43 | create_executable "${RBENV_ROOT}/shims" "kill-all-humans" | |
44 | ||
45 | PATH="$PATH:${RBENV_ROOT}/shims" RBENV_VERSION=system run rbenv-which kill-all-humans | |
46 | assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" | |
47 | } | |
48 | ||
49 | @test "searches PATH for system version (shims spread)" { | |
50 | create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" | |
51 | create_executable "${RBENV_ROOT}/shims" "kill-all-humans" | |
52 | ||
53 | PATH="${RBENV_ROOT}/shims:${RBENV_ROOT}/shims:/tmp/non-existent:$PATH:${RBENV_ROOT}/shims" \ | |
54 | RBENV_VERSION=system run rbenv-which kill-all-humans | |
55 | assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" | |
56 | } | |
57 | ||
58 | @test "doesn't include current directory in PATH search" { | |
59 | export PATH="$(path_without "kill-all-humans")" | |
60 | mkdir -p "$RBENV_TEST_DIR" | |
61 | cd "$RBENV_TEST_DIR" | |
62 | touch kill-all-humans | |
63 | chmod +x kill-all-humans | |
64 | RBENV_VERSION=system run rbenv-which kill-all-humans | |
65 | assert_failure "rbenv: kill-all-humans: command not found" | |
66 | } | |
67 | ||
68 | @test "version not installed" { | |
69 | create_executable "2.0" "rspec" | |
70 | RBENV_VERSION=1.9 run rbenv-which rspec | |
71 | assert_failure "rbenv: version \`1.9' is not installed (set by RBENV_VERSION environment variable)" | |
72 | } | |
73 | ||
74 | @test "no executable found" { | |
75 | create_executable "1.8" "rspec" | |
76 | RBENV_VERSION=1.8 run rbenv-which rake | |
77 | assert_failure "rbenv: rake: command not found" | |
78 | } | |
79 | ||
80 | @test "no executable found for system version" { | |
81 | export PATH="$(path_without "rake")" | |
82 | RBENV_VERSION=system run rbenv-which rake | |
83 | assert_failure "rbenv: rake: command not found" | |
84 | } | |
85 | ||
86 | @test "executable found in other versions" { | |
87 | create_executable "1.8" "ruby" | |
88 | create_executable "1.9" "rspec" | |
89 | create_executable "2.0" "rspec" | |
90 | ||
91 | RBENV_VERSION=1.8 run rbenv-which rspec | |
92 | assert_failure | |
93 | assert_output <<OUT | |
94 | rbenv: rspec: command not found | |
95 | ||
96 | The \`rspec' command exists in these Ruby versions: | |
97 | 1.9 | |
98 | 2.0 | |
99 | OUT | |
100 | } | |
101 | ||
102 | @test "carries original IFS within hooks" { | |
103 | hook_path="${RBENV_TEST_DIR}/rbenv.d" | |
104 | mkdir -p "${hook_path}/which" | |
105 | cat > "${hook_path}/which/hello.bash" <<SH | |
106 | hellos=(\$(printf "hello\\tugly world\\nagain")) | |
107 | echo HELLO="\$(printf ":%s" "\${hellos[@]}")" | |
108 | exit | |
109 | SH | |
110 | ||
111 | RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' RBENV_VERSION=system run rbenv-which anything | |
112 | assert_success | |
113 | assert_output "HELLO=:hello:ugly:world:again" | |
114 | } | |
115 | ||
116 | @test "discovers version from rbenv-version-name" { | |
117 | mkdir -p "$RBENV_ROOT" | |
118 | cat > "${RBENV_ROOT}/version" <<<"1.8" | |
119 | create_executable "1.8" "ruby" | |
120 | ||
121 | mkdir -p "$RBENV_TEST_DIR" | |
122 | cd "$RBENV_TEST_DIR" | |
123 | ||
124 | RBENV_VERSION= run rbenv-which ruby | |
125 | assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" | |
126 | } |