blob: 7a6b472e99a9bd0d6f5767c96e2e9e4607c8a161 [file] [log] [blame]
Éric Lemoinec8928042016-11-08 12:53:02 +00001#!/usr/bin/env bash
2
3## Functions
4
5log_info() {
6 echo "[INFO] $*"
7}
8
9log_err() {
10 echo "[ERROR] $*" >&2
11}
12
13_atexit() {
14 RETVAL=$?
15 trap true INT TERM EXIT
16
17 if [ $RETVAL -ne 0 ]; then
18 log_err "Execution failed"
19 else
20 log_info "Execution successful"
21 fi
22 return $RETVAL
23}
24
25## Main
26
27[ -n "$DEBUG" ] && set -x
28
29LUA_VERSION=$(lua -v 2>&1)
30if [[ $? -ne 0 ]]; then
31 log_err "No lua interpreter present"
32 exit $?
33fi
34if [[ ! $LUA_VERSION =~ [Lua\ 5\.1] ]]; then
35 log_err "Lua version 5.1 is required"
36 exit 1
37fi
38
39lua5.1 -e "require('lpeg')" > /dev/null 2>&1
40if [[ $? -ne 0 ]]; then
41 log_err "lua-lpeg is required (run apt-get install lua-lpeg)"
42 exit 1
43fi
44
45lua5.1 -e "require('cjson')" > /dev/null 2>&1
46if [[ $? -ne 0 ]]; then
47 log_err "lua-cjson is required (run apt-get install lua-cjson)"
48 exit 1
49fi
50
51for pgm in "cmake wget curl"; do
52 which $pgm > /dev/null 2>&1
53 if [[ $? -ne 0 ]]; then
54 log_err "$pgm is required (run apt-get install $pgm)"
55 exit 1
56 fi
57done
58
59if [[ ! -f /usr/lib/x86_64-linux-gnu/liblua5.1.so ]]; then
60 log_err "package liblua5.1-0-dev is not installed (run apt-get install liblua5.1-0-dev)"
61 exit 1
62fi
63
64set -e
65
66curl -s -o lua/mocks/annotation.lua "https://raw.githubusercontent.com/mozilla-services/heka/versions/0.10/sandbox/lua/modules/annotation.lua"
67curl -s -o lua/mocks/anomaly.lua "https://raw.githubusercontent.com/mozilla-services/heka/versions/0.10/sandbox/lua/modules/anomaly.lua"
68curl -s -o lua/mocks/date_time.lua "https://raw.githubusercontent.com/mozilla-services/lua_sandbox/97331863d3e05d25131b786e3e9199e805b9b4ba/modules/date_time.lua"
69curl -s -o lua/mocks/inspect.lua "https://raw.githubusercontent.com/kikito/inspect.lua/master/inspect.lua"
70
71CBUF_COMMIT="bb6dd9f88f148813315b5a660b7e2ba47f958b31"
72CBUF_TARBALL_URL="https://github.com/mozilla-services/lua_circular_buffer/archive/${CBUF_COMMIT}.tar.gz"
73CBUF_DIR="/tmp/lua_circular_buffer-${CBUF_COMMIT}"
74CBUF_SO="${CBUF_DIR}/release/circular_buffer.so"
75if [[ ! -f "${CBUF_SO}" ]]; then
76 rm -rf ${CBUF_DIR}
77 wget -qO - ${CBUF_TARBALL_URL} | tar -zxvf - -C /tmp
78 (cd ${CBUF_DIR} && mkdir release && cd release && cmake -DCMAKE_BUILD_TYPE=release .. && make)
79 cp ${CBUF_SO} ./
80fi
81
82for t in $(ls lua/test_*.lua); do
83 lua5.1 $t
84done
85
86trap _atexit INT TERM EXIT