adds local lua environment

This commit is contained in:
Harald Albrecht 2019-02-08 23:42:35 +01:00
parent 4e3254fa61
commit f7b1a3b066
7 changed files with 83 additions and 29 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
env/

8
.travis.yml Normal file
View File

@ -0,0 +1,8 @@
language: python
sudo: false
before_install:
- ./env.sh
script:
- ./env.sh busted

8
.vscode/tasks.json vendored
View File

@ -10,8 +10,8 @@
"isDefault": true
},
"type": "shell",
"command": "luacheck",
"args": ["-q", "./sdcard", "./spec"],
"command": "${workspaceFolder}/env.sh",
"args": ["luacheck", "-q", "./sdcard", "./spec"],
"presentation": {
"echo": true,
"reveal": "always",
@ -28,8 +28,8 @@
"isDefault": true
},
"type": "shell",
"command": "busted",
"args": [],
"command": "${workspaceFolder}/env.sh",
"args": ["busted"],
"presentation": {
"echo": true,
"reveal": "always",

View File

@ -244,9 +244,9 @@ rinse-and-repeat cycle with copying to microSD card, starting the Keybow
hardware, and then wondering what went wrong, without any real clue as to what
is the cause of failure.
Before your first testing, you'll need to run `./setup-tests.sh` once in order
to install (on Ubuntu-based distributions) the required system distribution and
LuaRocks packages.
> **Note:** before `check.sh` runs all tests and lints multibow, it installs
> a local Lua 5.3 environment including luarocks and the required luarock packages,
> if not already done so. This local environment will be placed into `./env`.
### Visual Studio Code
@ -257,9 +257,9 @@ test task which runs all tests.
### Shell
After having run `./setup-tests.sh` once, simply run `./check.sh` while in the
`multibow` repository root directory to run all tests and linting.
Simply run `./check.sh` while in the `multibow` repository root directory to run
all tests and linting.
If you want to just test a certain file or directory, then run `busted
spec/layout/kdenlive_spec.lua` to unit test a specific keyboard layout
(or set of layouts) or `busted spec/layout` to check all layouts.
(or set of layouts) or `./env.sh busted spec/layouts` to check all layouts.

View File

@ -1,12 +1,5 @@
#!/bin/bash
hascmd() {
command -v "$1" >/dev/null
}
if ! hascmd busted || ! hascmd luacheck ; then
echo "missing busted TDD library and luacheck Lua static source code checker; trying to install..."
bash ./setup-tests.sh
fi
echo "testing..."
busted
./env.sh busted
echo "linting..."
luacheck -q ./sdcard ./spec
./env.sh luacheck -q ./sdcard ./spec

62
env.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/bash
#
# Checks for a local lua/luarocks/... environment, installing it if it is
# missing. If a command and arguments are specified, then this command is run
# from the environment.
#
# Copyright 2019 Harald Albrecht
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
VENV=./env
HEREROCKS=$VENV/hererocks.py
# Checks for a specific luarocks package, installing it if necessary.
rock() {
luarocks list | grep -q $1
if [ $? != 0 ]; then
luarocks install $1
fi
}
# Downloads the fine hererocks Lua/luarocks installation script if not already
# done so, then ensures to install Lua 5.3 and latest luarocks.
mkdir -p $VENV
if [ ! -f $VENV/hererocks.py ]; then
wget https://raw.githubusercontent.com/mpeterv/hererocks/latest/hererocks.py -O $HEREROCKS
fi
if [ ! -f $VENV/bin/activate ]; then
python3 $HEREROCKS $VENV -l5.3 -rlatest
fi
# Activate the Lua/luarocks environment, then check for required luarocks
# packages, and install the missing ones.
source $VENV/bin/activate
rock luasec
rock busted
rock luasocket
rock luacheck
# Finally check if a command with args should be run from inside the Lua
# environment.
if [ -n "$1" ]; then
CMD=$VENV/bin/$1
shift
$CMD "$@"
fi

View File

@ -1,10 +0,0 @@
#!/bin/bash
# Installs the required libraries on Ubuntu ~18.10 LTS for Lua testing.
#sudo apt-get remove lua*
sudo apt-get install --yes lua5.3 liblua5.3-dev
sudo update-alternatives --install /usr/bin/lua lua /usr/bin/lua5.3 10
sudo apt-get install --yes luarocks
sudo luarocks install busted
sudo luarocks install luasocket
sudo luarocks install luacheck