Skip to content

Commit

Permalink
Merge pull request #115 from TitanSnow/installtest
Browse files Browse the repository at this point in the history
add tests for install & uninstall
  • Loading branch information
waruqi committed May 25, 2017
2 parents 3768a82 + 67a5ad7 commit 0c98817
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 193 deletions.
20 changes: 7 additions & 13 deletions .travis.yml
Expand Up @@ -13,31 +13,25 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- gcc-5

env:
global:
- LUAROCKS=2.2.2
- LUA=lua5.1

before_install:
- rm install
- source scripts/.travis/setenv_lua.sh
- luarocks install luacov
- luarocks

install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust lua51; fi
- sudo luarocks install luacov || sudo luarocks-5.1 install luacov

script:
- scripts/get.sh __local__
- source ~/.bash_profile
- 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.runner').init({['statsfile']='$PWD/luacov.stats.out',['reportfile']='$PWD/luacov.report.out'})" > 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)
- export XMAKE_PROGRAM_DIR=~/.local/share/xmake
- mv tmp "$XMAKE_PROGRAM_DIR/core/_xmake_main.lua"
- cp core/build/xmake "$XMAKE_PROGRAM_DIR" || sudo cp core/build/xmake "$XMAKE_PROGRAM_DIR"
- xmake lua versioninfo
- xmake lua --backtrace tests/test.lua

Expand Down
2 changes: 1 addition & 1 deletion core/src/xmake/machine.c
Expand Up @@ -319,7 +319,7 @@ static tb_bool_t xm_machine_get_program_directory(xm_machine_impl_t* impl, tb_ch
// get the directory
while (size-- > 0)
{
if (data[size] == '\\' || data[size] == '/')
if (data[size] == '\\' || data[size] == '/')
{
data[size] = '\0';
tb_strlcpy(path, data, maxn);
Expand Down
4 changes: 1 addition & 3 deletions core/src/xmake/readline/readline.c
Expand Up @@ -47,9 +47,7 @@ tb_int_t xm_readline_readline(lua_State* lua)
tb_assert_and_check_return_val(lua, 0);

// get the prompt
tb_char_t const* prompt = tb_null;
if (tb_strcmp("nil", luaL_typename(lua, 1)) != 0)
prompt = luaL_checkstring(lua, 1);
tb_char_t const* prompt = luaL_optstring(lua, 1, tb_null);

// call readline
tb_char_t* line = readline(prompt);
Expand Down
2 changes: 0 additions & 2 deletions makefile
Expand Up @@ -68,8 +68,6 @@ install:
@if [ ! -d $(prefix)/bin ]; then mkdir -p $(prefix)/bin; fi
@mv $(xmake_loader) $(xmake_loader_install)
@chmod 777 $(xmake_loader_install)
@# tip
@$(if $(findstring $(prefix)/bin,$(PATH)),,echo 'please export PATH=$$PATH:$(prefix)/bin')
@# remove xmake.out
@if [ -f '/tmp/xmake.out' ]; then rm /tmp/xmake.out; fi
@# ok
Expand Down
1 change: 0 additions & 1 deletion scripts/.travis/copyright

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/.travis/platform.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/.travis/setenv_lua.sh

This file was deleted.

124 changes: 0 additions & 124 deletions scripts/.travis/setup_lua.sh

This file was deleted.

53 changes: 33 additions & 20 deletions scripts/get.sh
Expand Up @@ -98,29 +98,42 @@ then
my_exit 'Build Fail' $rv
fi
fi
PATHclone=$PATH
patharr=($PATHclone)
prefix=
for st in "${patharr[@]}"
do
if [[ "$st" = "$HOME"* ]]
then
cwd=$PWD
mkdir -p "$st"
cd "$st" || continue
echo $$ > $$xmake_getter_test 2>/dev/null || continue
rm $$xmake_getter_test 2>/dev/null || continue
cd .. || continue
mkdir -p share 2>/dev/null || continue
prefix=$(pwd)
cd "$cwd" || my_exit 'Chdir Error'
break
fi
done
# PATHclone=$PATH
# patharr=($PATHclone)
if [ "$prefix" = "" ]
then
prefix=~/.local
fi
# for st in "${patharr[@]}"
# do
# if [[ "$st" = "$HOME"* ]]
# then
# cwd=$PWD
# mkdir -p "$st"
# cd "$st" || continue
# echo $$ > $$xmake_getter_test 2>/dev/null || continue
# rm $$xmake_getter_test 2>/dev/null || continue
# cd .. || continue
# mkdir -p share 2>/dev/null || continue
# prefix=$(pwd)
# cd "$cwd" || my_exit 'Chdir Error'
# break
# fi
# done
if [ "x$prefix" != x ]
then
make -C /tmp/$$xmake_getter --no-print-directory install prefix="$prefix"|| my_exit 'Install Fail'
else
$sudoprefix make -C /tmp/$$xmake_getter --no-print-directory install || my_exit 'Install Fail'
fi
xmake --version
shell_profile(){
if [[ "$SHELL" = */zsh ]]; then echo ~/.zshrc
elif [[ "$SHELL" = */ksh ]]; then echo ~/.kshrc
else echo ~/.bash_profile; fi
}
xmake --version >/dev/null 2>&1 && xmake --version || {
echo "export PATH=$prefix/bin:\$PATH" >> $(shell_profile)
export PATH=$prefix/bin:$PATH
xmake --version
echo -e "Reload shell profile by running \x1b[1msource '$(shell_profile)'\x1b[0m now!"
}
8 changes: 4 additions & 4 deletions tests/build.lua
Expand Up @@ -24,14 +24,14 @@ function main(argv)
os.exec("xmake f --cc=gcc --cxx=g++")
os.exec("xmake m buildtest")
if sudo.has() then
-- sudo.exec("xmake install")
-- sudo.exec("xmake uninstall")
sudo.exec("xmake install")
sudo.exec("xmake uninstall")
end
os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace")
os.exec("xmake m buildtest")
if sudo.has() then
-- sudo.exec("xmake install --all -v --backtrace")
-- sudo.exec("xmake uninstall -v --backtrace")
sudo.exec("xmake install --all -v --backtrace")
sudo.exec("xmake uninstall -v --backtrace")
end
os.exec("xmake m -d buildtest")

Expand Down
6 changes: 1 addition & 5 deletions xmake/core/sandbox/modules/os.lua
Expand Up @@ -48,6 +48,7 @@ sandbox_os.nuldev = os.nuldev
sandbox_os.emptydir = os.emptydir
sandbox_os.programdir = os.programdir
sandbox_os.programfile = os.programfile
sandbox_os.versioninfo = os.versioninfo

-- copy file or directory
function sandbox_os.cp(...)
Expand Down Expand Up @@ -459,11 +460,6 @@ function sandbox_os.uuid(name)
return uuid
end

-- get versioninfo
function sandbox_os.versioninfo()
return os.versioninfo()
end

-- return module
return sandbox_os

4 changes: 2 additions & 2 deletions xmake/modules/privilege/sudo.lua
Expand Up @@ -45,7 +45,7 @@ function _sudo(runner, cmd, ...)
pathenv = pathenv:gsub("\"", "\\\"")

-- run it with administrator permission and preserve parent environment
runner(program .. " PATH=\"" .. pathenv .. "\" " .. cmd, ...)
runner(program .. " env PATH=\"" .. pathenv .. "\" " .. cmd, ...)
else
-- run it with administrator permission
runner(program .. " " .. cmd, ...)
Expand All @@ -64,7 +64,7 @@ function _sudov(runner, shellname, argv)
assert(program, "sudo not found!")

-- run it with administrator permission and preserve parent environment
runner(program, table.join("PATH=" .. os.getenv("PATH"), shellname, argv))
runner(program, table.join("env", "PATH=" .. os.getenv("PATH"), shellname, argv))
end

-- sudo run lua script with administrator permission and arguments list
Expand Down

0 comments on commit 0c98817

Please sign in to comment.