Adding unit tests to Travis CI (#310)

This commit is contained in:
An Tao 2019-12-07 17:43:00 +08:00 committed by GitHub
parent 5bb54cd4cf
commit 6571e55631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 59 deletions

View File

@ -332,7 +332,7 @@ set(INCLUDING_DIRS ${INS_STRING})
configure_file(${PROJECT_SOURCE_DIR}/cmake/templates/config.h.in
${PROJECT_BINARY_DIR}/drogon/config.h @ONLY)
if(MAKE_TESTING)
if(BUILD_TESTING)
add_subdirectory(lib/tests)
if(PostgreSQL_FOUND)
add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test)

View File

@ -28,7 +28,7 @@ function build_drogon() {
echo "Start building drogon ..."
if [ $1 -eq 1 ]; then
cmake .. -DMAKE_TESTING=YES
cmake .. -DBUILD_TESTING=YES
else
cmake ..
fi

10
test.sh
View File

@ -1,4 +1,5 @@
#!/bin/bash
cd build/examples/
#Make webapp run as a daemon
@ -113,8 +114,15 @@ cd ../../
rm -rf drogon_test
if [ "$1" = "-t" ]; then
echo "Test database"
#unit testing
cd ../
echo "Unit testing"
make test
if [ $? -ne 0 ]; then
echo "Error in unit testing"
exit -1
fi
echo "Test database"
./orm_lib/tests/db_test
if [ $? -ne 0 ]; then
echo "Error in testing"

View File

@ -1,11 +1,9 @@
add_executable(msgbuffer_unittest MsgBufferUnittest.cpp)
add_executable(timer_unittest TimerUnittest.cpp)
add_executable(drobject_unittest DrObjectUnittest.cpp)
add_executable(gzip_unittest GzipUnittest.cpp)
set(UNITTEST_TARGETS
msgbuffer_unittest
timer_unittest
drobject_unittest
gzip_unittest)
set_property(TARGET ${UNITTEST_TARGETS}

View File

@ -1,42 +0,0 @@
#include <trantor/net/EventLoop.h>
#include <gtest/gtest.h>
#include <string>
#include <iostream>
using namespace trantor;
using namespace std::literals;
EventLoop loop;
TEST(TimerTest, RunEvery)
{
size_t count{0};
std::chrono::steady_clock::time_point tp{std::chrono::steady_clock::now()};
loop.runEvery(0.1s, [&count, tp] {
++count;
if (count == 10)
{
auto d = std::chrono::steady_clock::now() - tp;
auto err = d > 1s ? d - 1s : 1s - d;
auto msErr =
std::chrono::duration_cast<std::chrono::milliseconds>(err)
.count();
EXPECT_LT(msErr, 100LL);
loop.quit();
return;
}
std::this_thread::sleep_for(0.02s);
});
loop.runAfter(0.35s, [tp] {
auto d = std::chrono::steady_clock::now() - tp;
auto err = d > 0.35s ? d - 0.35s : 0.35s - d;
auto msErr =
std::chrono::duration_cast<std::chrono::milliseconds>(err).count();
EXPECT_LT(msErr, 30LL);
});
loop.loop();
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}