summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-15 14:50:09 +0800
committerGitHub <[email protected]>2017-05-15 14:50:09 +0800
commit36a1f8af040e5c21e0bdbd937bd1286e6b0b15ca (patch)
tree744887ad8e2105f9e66428d6d934c62379e98573
parent36187ba80bd03051eda6fcef20dd54368330a367 (diff)
parentf04981e7a207a25ece6047e83ac3c34c8747e89b (diff)
Merge pull request #91 from TitanSnow/luacov
Luacov
-rw-r--r--.travis.yml26
-rw-r--r--.travis/copyright1
-rw-r--r--.travis/platform.sh15
-rw-r--r--.travis/setenv_lua.sh3
-rw-r--r--.travis/setup_lua.sh124
l---------core/pkg/tbox.pkg/lib/coverage1
-rw-r--r--core/src/xmake/xmake.lua3
-rw-r--r--core/xmake.lua5
-rwxr-xr-xtests/tests20
9 files changed, 183 insertions, 15 deletions
diff --git a/.travis.yml b/.travis.yml
index 3048265a6..0aa161d1e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,36 @@
-sudo: false
+sudo: required
language: C
os:
- linux
- osx
+env:
+ global:
+ - LUAROCKS=2.2.2
+ - LUA=lua5.1
+
+before_install:
+ - rm install
+ - source .travis/setenv_lua.sh
+ - luarocks install luacov
+
+install:
+ - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust; fi
+ - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get autoremove -yq gcc g++; sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; sudo apt-get update -q; sudo apt-get install -yq gcc-6 g++-6; sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 99 --slave /usr/bin/gcov gcov /usr/bin/gcov-6 --slave /usr/bin/g++ g++ /usr/bin/g++-6; gcc --version; g++ --version; gcov --version; fi
+
script:
- scripts/get.sh __local__
- xmake lua versioninfo
+ - xmake f -m coverage -P core
- xmake -P core
- export XMAKE_PROGRAM_DIR=$PWD/xmake
- core/build/xmake lua versioninfo
+ - echo 'require("luacov")' > tmp
+ - cat xmake/core/_xmake_main.lua >> tmp
+ - mv tmp xmake/core/_xmake_main.lua
+ - cp core/build/xmake $(which xmake) || sudo cp core/build/xmake $(which xmake)
+ - tests/tests
+
+after_success:
+ - luacov
+ - bash <(curl -s https://codecov.io/bash)
diff --git a/.travis/copyright b/.travis/copyright
new file mode 100644
index 000000000..0346e778f
--- /dev/null
+++ b/.travis/copyright
@@ -0,0 +1 @@
+Copyright (c) 2015-2017 codecov
diff --git a/.travis/platform.sh b/.travis/platform.sh
new file mode 100644
index 000000000..7259a7d63
--- /dev/null
+++ b/.travis/platform.sh
@@ -0,0 +1,15 @@
+if [ -z "${PLATFORM:-}" ]; then
+ PLATFORM=$TRAVIS_OS_NAME;
+fi
+
+if [ "$PLATFORM" == "osx" ]; then
+ PLATFORM="macosx";
+fi
+
+if [ -z "$PLATFORM" ]; then
+ if [ "$(uname)" == "Linux" ]; then
+ PLATFORM="linux";
+ else
+ PLATFORM="macosx";
+ fi;
+fi
diff --git a/.travis/setenv_lua.sh b/.travis/setenv_lua.sh
new file mode 100644
index 000000000..8d8c82558
--- /dev/null
+++ b/.travis/setenv_lua.sh
@@ -0,0 +1,3 @@
+export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin
+bash .travis/setup_lua.sh
+eval `$HOME/.lua/luarocks path`
diff --git a/.travis/setup_lua.sh b/.travis/setup_lua.sh
new file mode 100644
index 000000000..86b0db6e7
--- /dev/null
+++ b/.travis/setup_lua.sh
@@ -0,0 +1,124 @@
+#! /bin/bash
+
+# A script for setting up environment for travis-ci testing.
+# Sets up Lua and Luarocks.
+# LUA must be "lua5.1", "lua5.2" or "luajit".
+# luajit2.0 - master v2.0
+# luajit2.1 - master v2.1
+
+set -eufo pipefail
+
+LUAJIT_BASE="LuaJIT-2.0.4"
+
+source .travis/platform.sh
+
+LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/lua
+
+LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks
+
+mkdir $HOME/.lua
+
+LUAJIT="no"
+
+if [ "$PLATFORM" == "macosx" ]; then
+ if [ "$LUA" == "luajit" ]; then
+ LUAJIT="yes";
+ fi
+ if [ "$LUA" == "luajit2.0" ]; then
+ LUAJIT="yes";
+ fi
+ if [ "$LUA" == "luajit2.1" ]; then
+ LUAJIT="yes";
+ fi;
+elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
+ LUAJIT="yes";
+fi
+
+mkdir -p "$LUA_HOME_DIR"
+
+if [ "$LUAJIT" == "yes" ]; then
+
+ if [ "$LUA" == "luajit" ]; then
+ curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz;
+ else
+ git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE;
+ fi
+
+ cd $LUAJIT_BASE
+
+ if [ "$LUA" == "luajit2.1" ]; then
+ git checkout v2.1;
+ fi
+
+ make && make install PREFIX="$LUA_HOME_DIR"
+
+ if [ "$LUA" == "luajit2.1" ]; then
+ ln -s $LUA_HOME_DIR/bin/luajit-2.1.0-alpha $HOME/.lua/luajit
+ ln -s $LUA_HOME_DIR/bin/luajit-2.1.0-alpha $HOME/.lua/lua;
+ else
+ ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit
+ ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua;
+ fi;
+
+else
+
+ if [ "$LUA" == "lua5.1" ]; then
+ curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
+ cd lua-5.1.5;
+ elif [ "$LUA" == "lua5.2" ]; then
+ curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz
+ cd lua-5.2.4;
+ elif [ "$LUA" == "lua5.3" ]; then
+ curl http://www.lua.org/ftp/lua-5.3.1.tar.gz | tar xz
+ cd lua-5.3.1;
+ fi
+
+ # Build Lua without backwards compatibility for testing
+ perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile
+ make $PLATFORM
+ make INSTALL_TOP="$LUA_HOME_DIR" install;
+
+ ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua
+ ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac;
+
+fi
+
+cd $TRAVIS_BUILD_DIR
+
+lua -v
+
+LUAROCKS_BASE=luarocks-$LUAROCKS
+
+curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
+
+cd $LUAROCKS_BASE
+
+if [ "$LUA" == "luajit" ]; then
+ ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
+elif [ "$LUA" == "luajit2.0" ]; then
+ ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR";
+elif [ "$LUA" == "luajit2.1" ]; then
+ ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR";
+else
+ ./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR"
+fi
+
+make build && make install
+
+ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks
+
+cd $TRAVIS_BUILD_DIR
+
+luarocks --version
+
+rm -rf $LUAROCKS_BASE
+
+if [ "$LUAJIT" == "yes" ]; then
+ rm -rf $LUAJIT_BASE;
+elif [ "$LUA" == "lua5.1" ]; then
+ rm -rf lua-5.1.5;
+elif [ "$LUA" == "lua5.2" ]; then
+ rm -rf lua-5.2.4;
+elif [ "$LUA" == "lua5.3" ]; then
+ rm -rf lua-5.3.1;
+fi
diff --git a/core/pkg/tbox.pkg/lib/coverage b/core/pkg/tbox.pkg/lib/coverage
new file mode 120000
index 000000000..30b81dbfd
--- /dev/null
+++ b/core/pkg/tbox.pkg/lib/coverage
@@ -0,0 +1 @@
+release \ No newline at end of file
diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua
index f2d9fe71c..c50013e4b 100644
--- a/core/src/xmake/xmake.lua
+++ b/core/src/xmake/xmake.lua
@@ -29,3 +29,6 @@ target("xmake")
-- add cfunc
add_cfunc("API", "readline", nil, {"readline/readline.h"}, "readline")
+ if is_mode("coverage") then
+ add_cxflags("-coverage", "-fprofile-arcs", "-ftest-coverage")
+ end
diff --git a/core/xmake.lua b/core/xmake.lua
index b53b9a94c..b8fdb4da6 100644
--- a/core/xmake.lua
+++ b/core/xmake.lua
@@ -48,6 +48,11 @@ if is_plat("macosx") then
add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000")
end
+-- for mode coverage
+if is_mode("coverage") then
+ add_ldflags("-coverage", "-fprofile-arcs", "-ftest-coverage")
+end
+
-- add package directories
add_packagedirs("pkg")
diff --git a/tests/tests b/tests/tests
index 5caeb88f9..ae386c0e7 100755
--- a/tests/tests
+++ b/tests/tests
@@ -18,30 +18,22 @@ function exec()
function build()
{
- # enter project
+ # echo project name
echo "build $1"
- cd $1
# build
- exec "xmake f -c"
- exec "xmake "
- exec "xmake p"
-
- # leave project
- cd -
+ exec "xmake f -c -P $1"
+ exec "xmake -P $1"
+ exec "xmake p -P $1"
}
function build_for_iphoenos()
{
- # enter project
+ # echo project name
echo "build $1"
- cd $1
# package all archs for iphoneos
- exec "xmake m package -p iphoneos"
-
- # leave project
- cd -
+ exec "xmake m -P $1 package -p iphoneos"
}
# build for c