├── .gitignore ├── .travis.yml ├── LICENCE ├── Makefile ├── README.md ├── bin └── moonbox ├── configure ├── moonbox-0.1-1.rockspec └── test ├── check_dependencies.bash └── test_suite.bats /.gitignore: -------------------------------------------------------------------------------- 1 | /BoxFile 2 | /.moonbox/ 3 | 4 | /config.make 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: erlang 2 | 3 | env: 4 | global: 5 | - LUAROCKS_BASE=luarocks-2.1.1 6 | matrix: 7 | - LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1 8 | - LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2 9 | - LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0 LUAJIT_VER=2.0 10 | - LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.1 LUAJIT_VER=2.1 11 | 12 | before_install: 13 | - if [ $LUA = "luajit" ] && [ $LUAJIT_VER = "2.0" ]; then 14 | sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y; 15 | fi 16 | - if [ $LUA = "luajit" ] && [ $LUAJIT_VER = "2.1" ]; then 17 | sudo add-apt-repository ppa:neomantra/luajit-v2.1 -y && sudo apt-get update -y; 18 | fi 19 | - sudo apt-get install $LUA $LUA_DEV 20 | - lua$LUA_SFX -v 21 | # Install a recent luarocks release 22 | - wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz 23 | - tar zxvpf $LUAROCKS_BASE.tar.gz 24 | - cd $LUAROCKS_BASE 25 | - ./configure 26 | --lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR" 27 | - sudo make 28 | - sudo make install 29 | - cd $TRAVIS_BUILD_DIR 30 | 31 | install: 32 | - git clone https://github.com/sstephenson/bats.git 33 | - cd bats 34 | - sudo ./install.sh /usr/local 35 | - cd $TRAVIS_BUILD_DIR 36 | 37 | script: 38 | - ./configure 39 | - make test 40 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 Sebastián Moreno 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | -include ./config.make 2 | 3 | all: 4 | -@echo Nothing to do 5 | 6 | install: 7 | install -d $(prefix)/bin 8 | install -m 0755 ./bin/moonbox $(prefix)/bin 9 | 10 | uninstall: 11 | rm -rf $(prefix)/bin/moonbox 12 | 13 | test: 14 | bats test/test_suite.bats 15 | 16 | .PHONY: test 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MoonBox 2 | [![Build Status](https://travis-ci.org/kernelp4nic/moonbox.png?branch=master)](https://travis-ci.org/kernelp4nic/moonbox) 3 | 4 | ##### Where your moon rocks live. 5 | 6 | moonbox will help you manage specific versions of lua rocks for a 7 | project. It heavily relies on [luarocks](http://luarocks.org/). 8 | 9 | ![alt text](http://upload.wikimedia.org/wikipedia/commons/2/25/Y12_moon_box_for_apollo_11.jpg "Apollo 11 Moon Box") 10 | 11 | [Image reference](http://commons.wikimedia.org/wiki/File:Y12_moon_box_for_apollo_11.jpg) 12 | 13 | 14 | ## Name 15 | 16 | The name comes from the Apollo 11 sample boxes to store moon rocks. 17 | 18 | > One of the proud accomplishments in Y-12 history was to develop and manufacture "moon boxes" for the historic Apollo 11 mission in July 1969. Astronauts used the boxes to collect and bring back to Earth nearly 50 pounds of moon rocks and soil, and the Y-12-made boxes were also used in subsequent Apollo missions. 19 | > Each of the boxes was machined from a single piece of aluminum, "seamless except for the lid opening, which had a metalized gasket that firmly sealed when closed." Metal straps secured the lid while in transit. The boxes are on display in multiple places, including the Smithsonian Air & Space Museum in Washington, D.C., and in the Y-12 History Center. 20 | 21 | (click [here](http://blogs.knoxnews.com/munger/2012/03/three-men-and-a-moonbox.html) for more info) 22 | 23 | 24 | ## Installing 25 | 26 | ### Via LuaRocks: 27 | 28 | ```bash 29 | ➯ luarocks install https://raw.githubusercontent.com/kernelp4nic/moonbox/master/moonbox-0.1-1.rockspec 30 | ``` 31 | 32 | ### Manual: 33 | 34 | ```bash 35 | ➯ git clone https://github.com/kernelp4nic/moonbox 36 | ➯ cd moonbox 37 | ➯ ./configure # supports --prefix as parameter (default is /usr/local) 38 | ➯ make install 39 | ``` 40 | 41 | ## Usage 42 | 43 | ### BoxFile 44 | 45 | moonbox needs a configuration file to work with. If you do not have one, 46 | you can create a sample one with `moonbox init`. Otherwise, just follow this convention: 47 | 48 | ```bash 49 | penlight # without version, will install the latest 50 | redis-lua 2.0.4-1 # provide a rock version 51 | gin 0.1.4-1 http://gin.io/repo # you can also provide a custom server 52 | http://luarocks.org/repositories/rocks/uuid-0.2-1.rockspec # you can provide a rockspec url too 53 | 54 | ``` 55 | 56 | ### Installing rocks 57 | 58 | ```bash 59 | ➯ cd your_project_dir 60 | ➯ moonbox init #creates a sample BoxFile inside your project, edit with your rocks and versions 61 | ➯ moonbox install 62 | >> starting to install rocks at 'your_project_dir/.moonbox' 63 | 64 | Installing http://www.luarocks.org/repositories/rocks/penlight-1.3.1-1.src.rock... 65 | Using http://www.luarocks.org/repositories/rocks/penlight-1.3.1-1.src.rock... switching to 'build' mode 66 | Updating manifest for your_project_dir/.moonbox/lib/luarocks/rocks 67 | 68 | penlight 1.3.1-1 is now built and installed in your_project_dir/.moonbox (license: MIT/X11) 69 | 70 | >> installation complete! 71 | ``` 72 | 73 | ### Environments 74 | 75 | moonbox comes handy when you need to have an isolated directory with 76 | all your rocks dependencies. You can run `source moonbox env enter` and this 77 | will update your LUA_PATH/LUA_CPATH environment variables to work with your current directory. 78 | 79 | As you may have noticed, environment commands are sourced. This means that 80 | every moonbox change will impact your current shell process. 81 | 82 | #### Environment show 83 | 84 | ```bash 85 | ➯ source moonbox env show 86 | >> env at 'your_project_dir/.moonbox' 87 | ``` 88 | 89 | #### Entering an Environment 90 | 91 | ```bash 92 | ➯ source moonbox env enter 93 | >> env setted up at 'your_project_dir/.moonbox' 94 | ➯ lua 95 | Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio 96 | > require 'pl.lapp' 97 | > 98 | ``` 99 | 100 | #### Leaving an Environment 101 | 102 | ```bash 103 | ➯ source moonbox env leave 104 | >> env at 'your_project_dir/.moonbox' has been removed. 105 | ➯ lua 106 | Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio 107 | > require 'pl.lapp' 108 | stdin:1: module 'pl.lapp' not found: 109 | no field package.preload['pl.lapp'] 110 | stack traceback: 111 | [C]: in function 'require' 112 | stdin:1: in main chunk 113 | [C]: ? 114 | > 115 | ``` 116 | 117 | ### Need more help? 118 | 119 | ```bash 120 | ➯ moonbox help 121 | ``` 122 | 123 | ## Lua versions supported (5.1, 5.2) 124 | If you have installed [luarocks](http://luarocks.org/) 2.1.2 or later, 125 | moonbox will support both versions of Lua. 126 | 127 | ## Tests 128 | moonbox uses [bats](https://github.com/sstephenson/bats) to run tests. 129 | You can install it following [this guide](https://github.com/sstephenson/bats#installing-bats-from-source). 130 | 131 | Once installed, run from the command line: 132 | 133 | ```bash 134 | ➯ cd moonbox_sources 135 | ➯ make test 136 | bats test/test_suite.bats 137 | ✓ install/uninstall moonbox 138 | ✓ 'moonbox help' command 139 | ✓ 'moonbox version' command 140 | ✓ 'moonbox install' command without BoxFile 141 | ✓ 'moonbox init' check BoxFile creation 142 | ✓ 'moonbox install' with empty BoxFile 143 | ✓ 'moonbox install' with populated BoxFile - rockname 144 | ✓ 'moonbox install' with populated BoxFile - rockname && version 145 | ✓ 'moonbox install' with populated BoxFile - rockname && version && repo 146 | ✓ 'moonbox install' with populated BoxFile - rockspec 147 | ✓ 'source moonbox env show' command without previous moonbox env setup 148 | ✓ 'source moonbox env show' command with previous moonbox env setup 149 | ✓ 'source moonbox env enter' command without moonbox install 150 | ✓ 'source moonbox env enter' command 151 | ✓ 'source moonbox env leave' command 152 | 153 | 15 tests, 0 failures 154 | ``` 155 | 156 | ## License 157 | 158 | Released under MIT License, check LICENSE file for details. 159 | 160 | ## Thanks 161 | 162 | Guys from [luarocks](http://luarocks.org/), they rock (literally)! and 163 | moonbox could not live without it! 164 | 165 | To the awesome time lord [@pote](https://github.com/pote) for [gpm](https://github.com/pote/gpm). 166 | I took several ideas from his work. 167 | 168 | [@ignacio](https://github.com/ignacio) to point me out several tips and changes. Also he is my jedi Lua master. -------------------------------------------------------------------------------- /bin/moonbox: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | boxFile="BoxFile" 4 | moonDir=".moonbox" 5 | 6 | usage () { 7 | cat << EOL 8 | SYNOPSIS 9 | 10 | moonbox will help you to manage specific versions of lua rocks for a 11 | project, it heavily relies on luarocks (http://luarocks.org/). 12 | 13 | moonbox needs a configuration file to work with, if you do not have one, 14 | you can create a sample with 'moonbox init', otherwise, just follow 15 | this convention: 16 | 17 | penlight # without version, will install the latest 18 | redis-lua 2.0.4-1 # provide a rock version 19 | gin 0.1.4-1 http://gin.io/repo # you can also provide a custom server 20 | http://luarocks.org/repositories/rocks/uuid-0.2-1.rockspec # you can provide a rockspec url too 21 | 22 | moonbox comes handy when you need to have an isolated directory with 23 | all your rocks dependencies, you can run 'source moonbox env enter' and this 24 | will update your LUA_PATH/LUA_CPATH to work with your current directory. 25 | 26 | USAGE 27 | \$ moonbox # Default action: 'install'. 28 | \$ moonbox install # Parses the moonbox file, installs rocks. 29 | \$ moonbox init # Create a sample moonbox file. 30 | 31 | \$ source moonbox env # Default action 'env show' 32 | \$ source moonbox env enter # Enters the env inside this folder. 33 | \$ source moonbox env leave # Leaves the previous configured env. 34 | \$ source moonbox env show # Show current configured env. 35 | 36 | \$ moonbox help # Prints this message 37 | \$ moonbox version # Show the version of moonbox 38 | EOL 39 | } 40 | 41 | write_sample (){ 42 | [[ -f "$boxFile" ]] && echo ">> $boxFile already exist, nothing to do." && return 43 | cat >$boxFile <> $boxFile successfuly created!" 54 | } 55 | 56 | env_script_being_sourced (){ 57 | if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then return 1; else return 0; fi 58 | } 59 | 60 | env_show (){ 61 | env_script_being_sourced && echo ">> moonbox env commands must be sourced first, \ 62 | for more info run 'moonbox help'" && return 63 | [[ ! -z $MOONBOX_CURRENT ]] && echo ">> env at '$MOONBOX_CURRENT'" && return 64 | echo ">> could not find a moonbox env! You can start a new one with 'source moonbox env enter'" 65 | } 66 | 67 | env_leave (){ 68 | env_script_being_sourced && echo ">> moonbox env commands must be sourced first, \ 69 | for more info run 'moonbox help'" && return 70 | [[ -z $MOONBOX_CURRENT ]] && echo ">> could not find a moonbox env! \ 71 | You can start a new one with 'source moonbox env enter'" && return 72 | 73 | PATH=$MOONBOX_OLD_PATH 74 | LUA_PATH=$MOONBOX_OLD_LUA_PATH 75 | LUA_CPATH=$MOONBOX_OLD_LUA_CPATH 76 | LUA_PATH_5_2=$MOONBOX_OLD_LUA_PATH_5_2 77 | LUA_CPATH_5_2=$MOONBOX_OLD_LUA_CPATH_5_2 78 | 79 | export PATH LUA_PATH LUA_CPATH LUA_PATH_5_2 LUA_CPATH_5_2 80 | echo ">> env at '$MOONBOX_CURRENT' has been removed." 81 | unset MOONBOX_OLD_PATH MOONBOX_OLD_LUA_CPATH MOONBOX_OLD_LUA_PATH MOONBOX_OLD_LUA_PATH_5_2 MOONBOX_OLD_LUA_CPATH_5_2 MOONBOX_CURRENT 82 | } 83 | 84 | env_enter (){ 85 | env_script_being_sourced && echo ">> moonbox env commands must be sourced first, \ 86 | for more info run 'moonbox help'" && return 87 | # make sure we do not have any previous env set up 88 | [[ ! -z $MOONBOX_CURRENT ]] && echo -e ">> env already set up on: \ 89 | '$MOONBOX_CURRENT'. \n>> Run 'moonbox env leave' to remove the env setup." && return 90 | 91 | MOONBOX_DIR=`pwd`"/$moonDir" 92 | # check for directory 93 | [[ ! -d "$MOONBOX_DIR" ]] && echo ">> '$moonDir' directory not found. \ 94 | Run 'moonbox init' first." && return 95 | 96 | # save old paths 97 | MOONBOX_OLD_PATH=$PATH 98 | MOONBOX_OLD_LUA_PATH=$LUA_PATH 99 | MOONBOX_OLD_LUA_CPATH=$LUA_CPATH 100 | MOONBOX_OLD_LUA_PATH_5_2=$LUA_PATH_5_2 101 | MOONBOX_OLD_LUA_CPATH_5_2=$LUA_CPATH_5_2 102 | 103 | # build new paths 104 | MOONBOX_CURRENT=$MOONBOX_DIR 105 | LUA_PATH="$MOONBOX_CURRENT/share/lua/5.1/?.lua;$MOONBOX_CURRENT/share/lua/5.1/?/init.lua;$LUA_PATH" 106 | LUA_CPATH="$MOONBOX_CURRENT/lib/lua/5.1/?.so;./?.so;$LUA_CPATH" 107 | LUA_PATH_5_2="$MOONBOX_CURRENT/share/lua/5.2/?.lua;$MOONBOX_CURRENT/share/lua/5.2/?/init.lua;$LUA_PATH_5_2" 108 | LUA_CPATH_5_2="$MOONBOX_CURRENT/lib/lua/5.2/?.so;./?.so;$LUA_CPATH_5_2" 109 | PATH="$MOONBOX_DIR/bin":$PATH 110 | 111 | export LUA_CPATH LUA_PATH LUA_PATH_5_2 LUA_CPATH_5_2 MOONBOX_CURRENT PATH 112 | echo ">> env setted up at '$MOONBOX_CURRENT'" 113 | } 114 | 115 | env_handler (){ 116 | case "$1" in 117 | show) 118 | env_show ;; 119 | enter) 120 | env_enter ;; 121 | leave) 122 | env_leave ;; 123 | *) 124 | env_show ;; 125 | esac 126 | } 127 | 128 | install_rocks (){ 129 | # check for luarocks 130 | command -v luarocks >/dev/null 2>&1 || { 131 | echo >&2 "Luarocks needs to be installed to use moonbox, please check \ 132 | http://luarocks.org/en/Documentation"; 133 | return 134 | } 135 | 136 | [[ ! -f "$boxFile" ]] && echo ">> $boxFile file does not exist, \ 137 | You can create an example with 'moonbox init'" && return 138 | 139 | # get the rocks and extra info from the moonbox file 140 | rocks=$(sed 's/#.*//;/^\s*$/d' < $boxFile) || "" 141 | [[ -z "$rocks" ]] && echo ">> $boxFile file seems to be empty, \ 142 | If you already created one with 'moonbox init' needs to be edited" && return 143 | 144 | echo ">> starting to install rocks at '"`pwd`"/$moonDir'" && echo 145 | while read rock version server; do 146 | # build server flag (if needed) 147 | if [ -z "${server}" ]; then server_cmd=""; else server_cmd="--server=$server"; fi 148 | # install the rocks inside our moonbox directory with the info parsed from our config file 149 | luarocks --tree=$moonDir install $rock $version $server_cmd 150 | done < <(echo "$rocks") 151 | 152 | [[ $? != 0 ]] && echo -e "\n>> Something went wrong with the rocks install, \ 153 | check luarocks log for details" && return 154 | echo -e "\n>> installation complete!" 155 | } 156 | 157 | # 'moonbox install' is default action 158 | case "${1:-"install"}" in 159 | init) 160 | write_sample ;; 161 | version|v) 162 | echo ">> moonbox v0.1" ;; 163 | install) 164 | install_rocks ;; 165 | env) 166 | env_handler $2 ;; 167 | help|h) 168 | usage ;; 169 | *) 170 | usage ;; 171 | esac 172 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | prefix=/usr/local 4 | 5 | usage() { 6 | echo "Usage: configure [-h|--help] [--prefix=prefix]" 7 | } 8 | 9 | while [ "$1" != "" ]; do 10 | case "$1" in 11 | --prefix=*) 12 | prefix=${1#--prefix=} ;; 13 | --prefix) 14 | shift 15 | prefix=$1 ;; 16 | -h|--help) 17 | usage && exit ;; 18 | *) 19 | echo "$0: unknown argument $1" >&2 20 | usage && exit 1 ;; 21 | esac 22 | shift 23 | done 24 | 25 | cat <> config.make 29 | EOF 30 | 31 | cat > ./config.make <= 5.1, < 5.3" 20 | } 21 | build = { 22 | type = "none", 23 | install = { bin = {"bin/moonbox"} } 24 | } -------------------------------------------------------------------------------- /test/check_dependencies.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | command -v luarocks >/dev/null 2>&1 || { 4 | echo >&2 "luarocks needs to be installed to run this tests"; 5 | exit 1 6 | } 7 | 8 | if [ -z $LUA ]; then 9 | export LUA="lua" 10 | fi 11 | command -v $LUA >/dev/null 2>&1 || { 12 | echo >&2 "Lua needs to be installed to run this tests"; 13 | exit 1 14 | } 15 | -------------------------------------------------------------------------------- /test/test_suite.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load check_dependencies 4 | 5 | setup (){ 6 | 7 | unset LUA_PATH 8 | unset LUA_CPATH 9 | unset LUA_PATH_5_2 10 | unset LUA_CPATH_5_2 11 | unset MOONBOX_CURRENT 12 | 13 | rm -rf BoxFile 14 | rm -rf .moonbox 15 | rm -rf config.make 16 | } 17 | 18 | @test "install/uninstall moonbox" { 19 | run ./configure 20 | run make install 21 | run make uninstall 22 | } 23 | 24 | @test "'moonbox help' command" { 25 | run bin/moonbox help 26 | [ "${lines[0]}" = "SYNOPSIS" ] 27 | 28 | run bin/moonbox h 29 | [ "${lines[0]}" = "SYNOPSIS" ] 30 | } 31 | 32 | @test "'moonbox version' command" { 33 | run bin/moonbox version 34 | [ "$output" = ">> moonbox v0.1" ] 35 | } 36 | 37 | @test "'moonbox install' command without BoxFile" { 38 | run bin/moonbox 39 | [ "$output" = ">> BoxFile file does not exist, You can create an example with 'moonbox init'" ] 40 | 41 | run [ -d ".moonbox" ] 42 | [ "$status" -eq 1 ] 43 | } 44 | 45 | @test "'moonbox init' check BoxFile creation" { 46 | run bin/moonbox init 47 | [ "$output" = ">> BoxFile successfuly created!" ] 48 | 49 | run cat BoxFile 50 | [ "${lines[1]}" = "# WARNING: This file is an example, needs to be edited" ] 51 | 52 | run [ -d ".moonbox" ] 53 | [ "$status" -eq 1 ] 54 | } 55 | 56 | @test "'moonbox install' with empty BoxFile" { 57 | run bin/moonbox init 58 | run bin/moonbox install 59 | [ "$output" = ">> BoxFile file seems to be empty, If you already created one with 'moonbox init' needs to be edited" ] 60 | 61 | run [ -d ".moonbox" ] 62 | [ "$status" -eq 1 ] 63 | } 64 | 65 | @test "'moonbox install' with populated BoxFile - rockname" { 66 | echo "stacktraceplus # this is a comment, should be ignored" > BoxFile 67 | run bin/moonbox install 68 | last_line=${lines[${#lines[@]}-1]} 69 | [ "${lines[0]}" = ">> starting to install rocks at '`pwd`/.moonbox'" ] 70 | [ "$last_line" = ">> installation complete!" ] 71 | 72 | run [ -d ".moonbox" ] 73 | } 74 | 75 | @test "'moonbox install' with populated BoxFile - rockname && version" { 76 | echo "stacktraceplus 0.1.1-1" > BoxFile 77 | run bin/moonbox install 78 | last_line=${lines[${#lines[@]}-1]} 79 | [ "${lines[0]}" = ">> starting to install rocks at '`pwd`/.moonbox'" ] 80 | [ "$last_line" = ">> installation complete!" ] 81 | 82 | run [ -d ".moonbox" ] 83 | } 84 | 85 | @test "'moonbox install' with populated BoxFile - rockname && version && repo" { 86 | echo "stacktraceplus 0.1.1-1 http://luarocks.org/repositories/rocks/" > BoxFile 87 | run bin/moonbox install 88 | last_line=${lines[${#lines[@]}-1]} 89 | [ "${lines[0]}" = ">> starting to install rocks at '`pwd`/.moonbox'" ] 90 | [ "$last_line" = ">> installation complete!" ] 91 | 92 | run [ -d ".moonbox" ] 93 | } 94 | 95 | @test "'moonbox install' with populated BoxFile - rockspec" { 96 | echo "http://luarocks.org/repositories/rocks/uuid-0.2-1.rockspec" >> BoxFile 97 | run bin/moonbox install 98 | last_line=${lines[${#lines[@]}-1]} 99 | [ "${lines[0]}" = ">> starting to install rocks at '`pwd`/.moonbox'" ] 100 | [ "$last_line" = ">> installation complete!" ] 101 | 102 | run [ -d ".moonbox" ] 103 | } 104 | 105 | @test "'source moonbox env show' command without previous moonbox env setup" { 106 | cmd_output=">> could not find a moonbox env! You can start a new one with 'source moonbox env enter'" 107 | run source bin/moonbox env show 108 | [ "$output" = $cmd_output ] 109 | # check default env action 110 | run source bin/moonbox env 111 | [ "$output" = $cmd_output ] 112 | } 113 | 114 | @test "'source moonbox env show' command with previous moonbox env setup" { 115 | echo "stacktraceplus" > BoxFile 116 | run bin/moonbox install 117 | run [ -d ".moonbox" ] 118 | . bin/moonbox env enter && . bin/moonbox env show >> env_status 119 | [ `head -n 1 env_status` = ">> env at '`pwd`/.moonbox'" ] 120 | } 121 | 122 | @test "'source moonbox env enter' command without moonbox install" { 123 | run source bin/moonbox env enter 124 | [ "$output" = ">> '.moonbox' directory not found. Run 'moonbox init' first." ] 125 | } 126 | 127 | @test "'source moonbox env enter' command" { 128 | echo "stacktraceplus" > BoxFile 129 | run bin/moonbox install 130 | run [ -d ".moonbox" ] 131 | 132 | . bin/moonbox env enter && $LUA -l StackTracePlus -e "print("test")" 133 | } 134 | 135 | @test "'source moonbox env leave' command" { 136 | echo "stacktraceplus" > BoxFile 137 | run bin/moonbox install 138 | run [ -d ".moonbox" ] 139 | 140 | # TO-DO: kind of a hack, I know. 141 | . bin/moonbox env enter && . bin/moonbox env leave >> env_status 142 | [ `tail -n 1 env_status` = ">> env at '`pwd`/.moonbox' has been removed." ] 143 | run rm -rf env_status 144 | 145 | # this needs to fail 146 | run $LUA -l StackTracePlus 147 | [ "$status" -eq 1 ] 148 | } 149 | --------------------------------------------------------------------------------