drogon/test.sh

196 lines
4.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2019-12-07 17:43:00 +08:00
echo "First arg:"
echo $1
os='linux'
if [ "$1" = "-w" ]; then
os='windows'
fi
src_dir=$(pwd)
echo "OS:" $os
if [ $os = "linux" ]; then
drogon_ctl_exec=$(pwd)/build/drogon_ctl/drogon_ctl
else
drogon_ctl_exec=$(pwd)/build/drogon_ctl/Debug/drogon_ctl.exe
export PATH=$PATH:$src_dir/install/bin
fi
echo ${drogon_ctl_exec}
2021-05-27 20:09:57 +08:00
cd build/lib/tests/
2019-03-26 15:25:22 +08:00
if [ $os = "windows" ]; then
cd Debug
fi
make_flags=''
cmake_gen=''
parallel=1
# simulate ninja's parallelism
case $(nproc) in
2021-03-13 19:13:54 +08:00
1)
parallel=$(($(nproc) + 1))
;;
2021-03-13 19:13:54 +08:00
2)
parallel=$(($(nproc) + 1))
;;
2021-03-13 19:13:54 +08:00
*)
parallel=$(($(nproc) + 2))
;;
esac
if [ $os = "linux" ]; then
if [ -f /bin/ninja ]; then
cmake_gen='-G Ninja'
else
make_flags="$make_flags -j$parallel"
fi
fi
2021-05-27 20:09:57 +08:00
#Make integration_test_server run as a daemon
if [ $os = "linux" ]; then
sed -i -e "s/\"run_as_daemon.*$/\"run_as_daemon\": true\,/" config.example.json
fi
2019-03-26 15:25:22 +08:00
sed -i -e "s/\"relaunch_on_error.*$/\"relaunch_on_error\": true\,/" config.example.json
sed -i -e "s/\"threads_num.*$/\"threads_num\": 0\,/" config.example.json
sed -i -e "s/\"use_brotli.*$/\"use_brotli\": true\,/" config.example.json
2019-03-26 15:25:22 +08:00
2021-05-27 20:09:57 +08:00
if [ ! -f "integration_test_client" ]; then
2019-03-26 15:25:22 +08:00
echo "Build failed"
exit -1
fi
2021-05-27 20:09:57 +08:00
if [ ! -f "integration_test_server" ]; then
2019-03-26 15:25:22 +08:00
echo "Build failed"
exit -1
fi
2021-05-27 20:09:57 +08:00
killall -9 integration_test_server
./integration_test_server &
2019-04-07 12:15:02 +08:00
sleep 4
2021-05-27 20:09:57 +08:00
echo "Running the integration test"
./integration_test_client -s
2019-03-26 15:25:22 +08:00
2019-12-07 17:43:00 +08:00
if [ $? -ne 0 ]; then
2021-05-27 20:09:57 +08:00
echo "Integration test failed"
2019-03-26 15:25:22 +08:00
exit -1
fi
2021-05-27 20:09:57 +08:00
killall -9 integration_test_server
2019-03-31 00:27:12 +08:00
#Test drogon_ctl
2021-05-27 20:09:57 +08:00
echo "Testing drogon_ctl"
2019-04-06 23:06:38 +08:00
rm -rf drogon_test
${drogon_ctl_exec} create project drogon_test
2019-03-31 00:27:12 +08:00
ls -la
2019-03-31 00:27:12 +08:00
cd drogon_test/controllers
${drogon_ctl_exec} create controller Test::SimpleCtrl
${drogon_ctl_exec} create controller -h Test::HttpCtrl
${drogon_ctl_exec} create controller -w Test::WebsockCtrl
${drogon_ctl_exec} create controller SimpleCtrl
${drogon_ctl_exec} create controller -h HttpCtrl
${drogon_ctl_exec} create controller -w WebsockCtrl
2019-03-31 00:27:12 +08:00
2019-12-07 17:43:00 +08:00
if [ ! -f "Test_SimpleCtrl.h" -o ! -f "Test_SimpleCtrl.cc" -o ! -f "Test_HttpCtrl.h" -o ! -f "Test_HttpCtrl.cc" -o ! -f "Test_WebsockCtrl.h" -o ! -f "Test_WebsockCtrl.cc" ]; then
2019-03-31 00:27:12 +08:00
echo "Failed to create controllers"
exit -1
fi
2019-12-07 17:43:00 +08:00
if [ ! -f "SimpleCtrl.h" -o ! -f "SimpleCtrl.cc" -o ! -f "HttpCtrl.h" -o ! -f "HttpCtrl.cc" -o ! -f "WebsockCtrl.h" -o ! -f "WebsockCtrl.cc" ]; then
echo "Failed to create controllers"
exit -1
fi
2019-03-31 00:27:12 +08:00
cd ../filters
${drogon_ctl_exec} create filter Test::TestFilter
2019-03-31 00:27:12 +08:00
2019-12-07 17:43:00 +08:00
if [ ! -f "Test_TestFilter.h" -o ! -f "Test_TestFilter.cc" ]; then
2019-03-31 00:27:12 +08:00
echo "Failed to create filters"
exit -1
fi
2019-05-05 15:43:17 +08:00
cd ../plugins
${drogon_ctl_exec} create plugin Test::TestPlugin
2019-05-05 15:43:17 +08:00
2019-12-07 17:43:00 +08:00
if [ ! -f "Test_TestPlugin.h" -o ! -f "Test_TestPlugin.cc" ]; then
2019-05-05 15:43:17 +08:00
echo "Failed to create plugins"
exit -1
fi
cd ../views
2021-03-13 19:13:54 +08:00
echo "Hello, world!" >>hello.csp
2019-03-31 00:27:12 +08:00
cd ../build
if [ $os = "windows" ]; then
conan install $src_dir -s compiler="Visual Studio" -s compiler.version=16 -sbuild_type=Debug -g cmake_paths
cmake_gen="$cmake_gen -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake -DCMAKE_INSTALL_PREFIX=$src_dir/install"
fi
2021-02-17 09:58:33 +08:00
cmake .. $cmake_gen
2019-03-31 00:27:12 +08:00
2019-12-07 17:43:00 +08:00
if [ $? -ne 0 ]; then
2021-05-27 20:09:57 +08:00
echo "Failed to run CMake for example project"
2019-03-31 00:27:12 +08:00
exit -1
fi
cmake --build . -- $make_flags
2019-03-31 00:27:12 +08:00
2019-12-07 17:43:00 +08:00
if [ $? -ne 0 ]; then
2019-03-31 00:27:12 +08:00
echo "Error in testing"
exit -1
fi
if [ $os = "linux" ]; then
if [ ! -f "drogon_test" ]; then
echo "Failed to build drogon_test"
exit -1
fi
else
if [ ! -f "Debug\drogon_test.exe" ]; then
echo "Failed to build drogon_test"
exit -1
fi
2019-03-31 00:27:12 +08:00
fi
2019-03-31 18:30:06 +08:00
cd ../../
rm -rf drogon_test
2021-02-17 09:58:33 +08:00
if [ "$1" = "-t" ]; then
2019-12-07 17:43:00 +08:00
#unit testing
2021-05-27 20:09:57 +08:00
cd ../../
2019-12-07 17:43:00 +08:00
echo "Unit testing"
cmake --build . --target test -- $make_flags
2019-12-07 17:43:00 +08:00
if [ $? -ne 0 ]; then
echo "Error in unit testing"
exit -1
fi
if [ -f "./orm_lib/tests/db_test" ]; then
echo "Test database"
2021-05-27 20:09:57 +08:00
./orm_lib/tests/db_test -s
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
2021-03-13 19:13:54 +08:00
if [ -f "./nosql_lib/redis/tests/redis_test" ]; then
echo "Test redis"
2021-05-27 20:09:57 +08:00
./nosql_lib/redis/tests/redis_test -s
2021-03-13 19:13:54 +08:00
if [ $? -ne 0 ]; then
echo "Error in testing"
exit -1
fi
fi
fi
2019-03-31 00:27:12 +08:00
echo "Everything is ok!"
2019-03-26 15:25:22 +08:00
exit 0