Skip to content

Commit 7bd3d73

Browse files
committed
workflows/build.yml: add unittests for linux
CMakeLists.txt minor refactoring
1 parent 7cfea77 commit 7bd3d73

File tree

21 files changed

+521
-320
lines changed

21 files changed

+521
-320
lines changed

.github/workflows/build.yml

+41-16
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,15 @@ jobs:
3434
with:
3535
nuget-api-key: ${{ secrets.NuGetAPIKey }}
3636
nuget-version: '5.x'
37+
3738
- run: nuget restore '${{ env.solution }}'
3839

3940
- name: Setup MSBuild
4041
uses: microsoft/[email protected]
4142
with:
4243
vs-version: '16.8'
4344

44-
- name: Build ReHLDS
45-
run: |
46-
msbuild ${{ env.solution }} -p:Configuration="${{ env.buildRelease }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
47-
msbuild ${{ env.solution }} -p:Configuration="${{ env.buildReleasePlay }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
48-
49-
- name: Build and Testing
45+
- name: Build and Run unittests
5046
run: |
5147
msbuild ${{ env.solution }} -p:Configuration="${{ env.buildTest }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
5248
.\"msvc\Test Fixes\swds.exe"
@@ -55,6 +51,11 @@ jobs:
5551
{[Environment]::Exit(1)}
5652
shell: "pwsh"
5753

54+
- name: Build
55+
run: |
56+
msbuild ${{ env.solution }} -p:Configuration="${{ env.buildRelease }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
57+
msbuild ${{ env.solution }} -p:Configuration="${{ env.buildReleasePlay }}" /t:Clean,Build /p:Platform=${{ env.buildPlatform }} /p:PlatformToolset=v140_xp /p:XPDeprecationWarning=false
58+
5859
- name: Move files
5960
run: |
6061
mkdir publish\debug
@@ -112,17 +113,17 @@ jobs:
112113
mv $GITHUB_WORKSPACE/tests/swds.dll .
113114
114115
descs=(
116+
"CS: Multiplayer"
115117
"Half-Life: Physics singleplayer"
116118
"Half-Life: Multiplayer on crossfire map"
117119
"Half-Life: Shooting with several weapons"
118-
"CS: Multiplayer"
119120
)
120121
121122
demos=(
123+
"cstrike-muliplayer-1"
122124
"rehlds-phys-single1"
123125
"crossfire-1-multiplayer-1"
124126
"shooting-hl-1"
125-
"cstrike-muliplayer-1"
126127
)
127128
128129
retVal=0
@@ -168,6 +169,30 @@ jobs:
168169
with:
169170
fetch-depth: 0
170171

172+
- name: Build and Run unittests
173+
run: |
174+
rm -rf build && CC=icc CXX=icpc cmake -DCMAKE_BUILD_TYPE=Unittests -B build && cmake --build build -j8
175+
retVal=0
176+
export LD_LIBRARY_PATH="rehlds/lib/linux32:$LD_LIBRARY_PATH"
177+
./build/rehlds/engine_i486 2> /dev/null > result.log || retVal=$?
178+
while read line; do
179+
if [[ ${line} == *"Warning in test"* ]] ; then
180+
echo -e "\e[2;38m$line"
181+
elif [[ ${line} == *"Failure in test"* ]] ; then
182+
echo -e "\e[1;31m$line"
183+
else
184+
echo -e "\e[0;33m$line"
185+
fi
186+
done <<< $(cat result.log)
187+
188+
if [ $retVal -ne 0 ] && [ $retVal -ne 3 ]; then
189+
echo -e "\e[30;41mExit code: $retVal\e[0m"
190+
exit 1 # Unittest failed
191+
else
192+
echo -e "\e[30;43mExit code: $retVal\e[0m"
193+
fi
194+
shell: bash
195+
171196
- name: Build using Intel C++ Compiler
172197
run: |
173198
rm -rf build && CC=icc CXX=icpc cmake -B build && cmake --build build -j8
@@ -244,14 +269,14 @@ jobs:
244269
- name: Reading appversion.h
245270
run: |
246271
if [ -e appversion.h ]; then
247-
APP_VERSION=$(cat appversion.h | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g')
248-
if [ $? -ne 0 ]; then
249-
APP_VERSION=""
250-
else
251-
# Remove quotes
252-
APP_VERSION=$(echo $APP_VERSION | xargs)
253-
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
254-
fi
272+
APP_VERSION=$(cat appversion.h | grep -wi '#define APP_VERSION_STRD' | sed -e 's/#define APP_VERSION_STRD[ \t\r\n\v\f]\+\(.*\)/\1/i' -e 's/\r//g')
273+
if [ $? -ne 0 ]; then
274+
APP_VERSION=""
275+
else
276+
# Remove quotes
277+
APP_VERSION=$(echo $APP_VERSION | xargs)
278+
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
279+
fi
255280
fi
256281
rm -f appversion.h
257282

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.bat
44
*.log
55
*.lnk
6+
*.aps
67
**/msvc/Debug*
78
**/msvc/Release*
89
**/msvc/Tests

CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ add_custom_target(appversion DEPENDS
1010
)
1111

1212
add_subdirectory(rehlds)
13-
add_subdirectory(rehlds/dedicated)
14-
add_subdirectory(rehlds/filesystem)
15-
add_subdirectory(rehlds/HLTV)
13+
14+
if (NOT CMAKE_BUILD_TYPE MATCHES Unittests)
15+
add_subdirectory(rehlds/dedicated)
16+
add_subdirectory(rehlds/filesystem)
17+
add_subdirectory(rehlds/HLTV)
18+
endif()

dep/cppunitlite/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(cppunitlite CXX)
3+
4+
add_library(cppunitlite STATIC)
5+
6+
target_sources(cppunitlite PRIVATE
7+
src/Test.cpp
8+
src/TestResult.cpp
9+
src/TestRegistry.cpp
10+
src/Assertions.cpp
11+
src/MainAdapter.cpp
12+
)
13+
14+
target_include_directories(cppunitlite PRIVATE
15+
"${PROJECT_SOURCE_DIR}/src"
16+
"${PROJECT_SOURCE_DIR}/include"
17+
)
18+
19+
target_compile_definitions(cppunitlite PRIVATE
20+
_GLIBCXX_USE_CXX11_ABI=0
21+
)
22+
23+
target_compile_options(cppunitlite PRIVATE
24+
-m32
25+
)

dep/cppunitlite/include/cppunitlite/GradleAdapter.h dep/cppunitlite/include/cppunitlite/MainAdapter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
class GradleAdapter {
3+
class MainAdapter {
44
public:
55
int writeAllTestsInfoToFile(const char* fname);
66
int runTest(const char* groupName, const char* testName);

dep/cppunitlite/include/cppunitlite/Test.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class Test
2020
void setNext(Test *test);
2121
Test *getNext () const;
2222
void run(TestResult& result);
23-
23+
2424
const char* getName() {
2525
return name_.c_str();
2626
}
2727

2828
const char* getGroup() {
2929
return group_.c_str();
3030
}
31-
31+
3232
int getTimeout() {
3333
return timeout_;
3434
}
@@ -47,7 +47,7 @@ class Test
4747
{ public: testGroup##testName##Test () : Test (#testName , #testGroup , testTimeout) {} \
4848
void runInternal (); } \
4949
testGroup##testName##Instance; \
50-
void testGroup##testName##Test::runInternal()
50+
void testGroup##testName##Test::runInternal()
5151

5252

5353

dep/cppunitlite/msvc/cppunitlite.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
<ItemGroup>
1414
<ClInclude Include="..\include\cppunitlite\Assertions.h" />
1515
<ClInclude Include="..\include\cppunitlite\Failure.h" />
16-
<ClInclude Include="..\include\cppunitlite\GradleAdapter.h" />
16+
<ClInclude Include="..\include\cppunitlite\MainAdapter.h" />
1717
<ClInclude Include="..\include\cppunitlite\Test.h" />
1818
<ClInclude Include="..\include\cppunitlite\TestHarness.h" />
1919
<ClInclude Include="..\include\cppunitlite\TestRegistry.h" />
2020
<ClInclude Include="..\include\cppunitlite\TestResult.h" />
2121
</ItemGroup>
2222
<ItemGroup>
2323
<ClCompile Include="..\src\Assertions.cpp" />
24-
<ClCompile Include="..\src\GradleAdapter.cpp" />
24+
<ClCompile Include="..\src\MainAdapter.cpp" />
2525
<ClCompile Include="..\src\Test.cpp" />
2626
<ClCompile Include="..\src\TestRegistry.cpp" />
2727
<ClCompile Include="..\src\TestResult.cpp" />

dep/cppunitlite/msvc/cppunitlite.vcxproj.filters

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<ClInclude Include="..\include\cppunitlite\TestResult.h">
2828
<Filter>include</Filter>
2929
</ClInclude>
30-
<ClInclude Include="..\include\cppunitlite\GradleAdapter.h">
30+
<ClInclude Include="..\include\cppunitlite\MainAdapter.h">
3131
<Filter>include</Filter>
3232
</ClInclude>
3333
</ItemGroup>
@@ -44,7 +44,7 @@
4444
<ClCompile Include="..\src\TestResult.cpp">
4545
<Filter>src</Filter>
4646
</ClCompile>
47-
<ClCompile Include="..\src\GradleAdapter.cpp">
47+
<ClCompile Include="..\src\MainAdapter.cpp">
4848
<Filter>src</Filter>
4949
</ClCompile>
5050
</ItemGroup>

dep/cppunitlite/src/GradleAdapter.cpp dep/cppunitlite/src/MainAdapter.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include <stdlib.h>
33
#include <string.h>
44

5-
#include "cppunitlite/GradleAdapter.h"
5+
#include "cppunitlite/MainAdapter.h"
66
#include "cppunitlite/Test.h"
77
#include "cppunitlite/TestRegistry.h"
88

9-
int GradleAdapter::writeAllTestsInfoToFile(const char* fname) {
9+
int MainAdapter::writeAllTestsInfoToFile(const char* fname) {
1010
FILE* outFile = fopen(fname, "w");
1111
if (outFile == NULL) {
1212
return 1;
@@ -33,7 +33,7 @@ int GradleAdapter::writeAllTestsInfoToFile(const char* fname) {
3333
return 0;
3434
}
3535

36-
int GradleAdapter::runTest(const char* groupName, const char* testName) {
36+
int MainAdapter::runTest(const char* groupName, const char* testName) {
3737
Test* curTest = TestRegistry::getFirstTest();
3838
while (curTest != NULL) {
3939
if (!strcmp(groupName, curTest->getGroup()) && !strcmp(testName, curTest->getName())) {
@@ -61,7 +61,7 @@ int GradleAdapter::runTest(const char* groupName, const char* testName) {
6161
}
6262
}
6363

64-
int GradleAdapter::runGroup(const char* groupName) {
64+
int MainAdapter::runGroup(const char* groupName) {
6565
Test* curTest = TestRegistry::getFirstTest();
6666
int ranTests = 0;
6767
int warnTest = 0;
@@ -101,7 +101,7 @@ int GradleAdapter::runGroup(const char* groupName) {
101101
return 0;
102102
}
103103

104-
int GradleAdapter::runAllTests() {
104+
int MainAdapter::runAllTests() {
105105
Test* curTest = TestRegistry::getFirstTest();
106106
int ranTests = 0;
107107
int warnTest = 0;
@@ -131,7 +131,7 @@ int GradleAdapter::runAllTests() {
131131
return 0;
132132
}
133133

134-
int GradleAdapter::testsEntryPoint(int argc, char* argv[]) {
134+
int MainAdapter::testsEntryPoint(int argc, char* argv[]) {
135135
if (argc < 2 || !strcmp(argv[1], "-all")) {
136136
return runAllTests();
137137
}

dep/cppunitlite/src/Test.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
#include "cppunitlite/Failure.h"
66

77
#include <exception>
8+
#include <iostream>
89
#include <sstream>
910

1011

11-
Test::Test (const char* testName, const char* testGroup, int timeout)
12+
Test::Test (const char* testName, const char* testGroup, int timeout)
1213
: name_ (testName), group_ (testGroup), timeout_(timeout)
1314
{
1415
next_ = NULL;
@@ -23,13 +24,14 @@ Test *Test::getNext() const
2324

2425

2526
void Test::setNext(Test *test)
26-
{
27+
{
2728
next_ = test;
2829
}
2930

3031
void Test::run(TestResult &result) {
3132
try {
3233
runInternal();
34+
std::cout << "Test::run() > " << group_ << "::" << name_ << " Passed" << std::endl;
3335
} catch (TestFailException &e) {
3436
result.addFailure(Failure(e, name_));
3537
} catch (std::exception &e) {

0 commit comments

Comments
 (0)