Skip to content

Commit 2ef874d

Browse files
authored
Run basic native tests using hl2sdk-mock in CI (#2015)
This tests the sorting.inc API similar to the existing test plugin in the plugins/testsuite folder. Tests fail if the srcds output contains "FAIL".
1 parent cb85415 commit 2ef874d

File tree

3 files changed

+462
-1
lines changed

3 files changed

+462
-1
lines changed

.github/workflows/mocktest.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: hl2sdk-mock tests
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- '[0-9]+.[0-9]+-dev'
7+
pull_request:
8+
branches:
9+
- master
10+
- '[0-9]+.[0-9]+-dev'
11+
jobs:
12+
mock:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
name: Clone sourcemod
17+
with:
18+
submodules: recursive
19+
path: sourcemod
20+
21+
- uses: actions/checkout@v3
22+
name: Clone metamod-source
23+
with:
24+
repository: alliedmodders/metamod-source
25+
submodules: recursive
26+
path: metamod-source
27+
28+
- uses: actions/checkout@v3
29+
name: Clone hl2sdk-mock
30+
with:
31+
repository: alliedmodders/hl2sdk-mock
32+
submodules: recursive
33+
path: hl2sdk-mock
34+
35+
- uses: actions/setup-python@v4
36+
name: Setup Python 3.10
37+
with:
38+
python-version: "3.10"
39+
40+
- name: Install AMBuild
41+
run: |
42+
python -m pip install --upgrade pip setuptools wheel
43+
pip install git+https://github.com/alliedmodders/ambuild
44+
45+
- name: Build MetaMod:Source
46+
working-directory: metamod-source
47+
run: |
48+
python configure.py --enable-optimize --sdks=mock --targets=x86_64
49+
ambuild objdir
50+
51+
- name: Build SourceMod
52+
working-directory: sourcemod
53+
run: |
54+
python configure.py --no-mysql --enable-optimize --sdks=mock --targets=x86_64
55+
ambuild objdir
56+
57+
- name: Build hl2sdk-mock
58+
working-directory: hl2sdk-mock
59+
run: |
60+
python configure.py --enable-optimize --targets=x86_64
61+
ambuild objdir
62+
63+
- name: Setup gamedir
64+
working-directory: hl2sdk-mock
65+
shell: bash
66+
run: |
67+
mkdir ../gamedir
68+
./build_gamedir.sh ../gamedir ../metamod-source/objdir/package
69+
./build_gamedir.sh ../gamedir ../sourcemod/objdir/package
70+
71+
- name: Compile testsuite
72+
working-directory: hl2sdk-mock
73+
shell: bash
74+
run: |
75+
mkdir ../gamedir/addons/sourcemod/plugins/optional
76+
77+
for f in ../sourcemod/plugins/testsuite/mock/*.sp; do
78+
echo "Compiling $(basename $f)"
79+
../gamedir/addons/sourcemod/scripting/spcomp64 -i ../gamedir/addons/sourcemod/scripting/include -o "../gamedir/addons/sourcemod/plugins/optional/$(basename $f .sp).smx" -E "$f"
80+
done
81+
82+
- name: Test
83+
working-directory: hl2sdk-mock
84+
shell: bash
85+
run: |
86+
for f in ../gamedir/addons/sourcemod/plugins/optional/*.smx; do
87+
echo "==================================="
88+
echo "Running $(basename $f)..."
89+
echo "==================================="
90+
timeout 60 ./objdir/dist/x86_64/srcds -game_dir ../gamedir +map de_thunder -command "sm plugins load optional/$(basename $f)" -run -run-ticks 20 |
91+
{
92+
failed=0
93+
while IFS= read -r line; do
94+
echo "$line"
95+
if [[ "$line" == *"FAIL"* ]]; then
96+
failed=1
97+
fi
98+
done
99+
if [ "$failed" = "1" ]; then
100+
echo "$(basename $f) failed."
101+
exit 1
102+
fi
103+
}
104+
done

plugins/include/testing.inc

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ stock void SetTestContext(const char[] context)
3838
strcopy(TestContext, sizeof(TestContext), context);
3939
}
4040

41-
stock void AssertEq(const char[] text, int cell1, int cell2)
41+
stock void AssertEq(const char[] text, any cell1, any cell2)
4242
{
4343
TestNumber++;
4444
if (cell1 == cell2)
@@ -52,6 +52,39 @@ stock void AssertEq(const char[] text, int cell1, int cell2)
5252
}
5353
}
5454

55+
stock void AssertArrayEq(const char[] text, const any[] value, const any[] expected, int len)
56+
{
57+
TestNumber++;
58+
for (int i = 0; i < len; ++i)
59+
{
60+
if (value[i] != expected[i])
61+
{
62+
PrintToServer("[%d] %s FAIL: %s should be %d at index %d, got %d", TestNumber, TestContext, text, expected[i], i, value[i]);
63+
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
64+
break;
65+
}
66+
}
67+
PrintToServer("[%d] %s: '%s' arrays are equal OK", TestNumber, TestContext, text);
68+
}
69+
70+
stock void AssertArray2DEq(const char[] text, const any[][] value, const any[][] expected, int len, int innerlen)
71+
{
72+
TestNumber++;
73+
for (int i=0; i < len; ++i)
74+
{
75+
for (int j=0; j < innerlen; ++j)
76+
{
77+
if (value[i][j] != expected[i][j])
78+
{
79+
PrintToServer("[%d] %s FAIL: %s should be %d at index [%d][%d], got %d", TestNumber, TestContext, text, expected[i][j], i, j, value[i][j]);
80+
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
81+
break;
82+
}
83+
}
84+
}
85+
PrintToServer("[%d] %s: '%s' 2D arrays are equal OK", TestNumber, TestContext, text);
86+
}
87+
5588
stock void AssertFalse(const char[] text, bool value)
5689
{
5790
TestNumber++;
@@ -93,3 +126,18 @@ stock void AssertStrEq(const char[] text, const char[] value, const char[] expec
93126
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
94127
}
95128
}
129+
130+
stock void AssertStrArrayEq(const char[] text, const char[][] value, const char[][] expected, int len)
131+
{
132+
TestNumber++;
133+
for (int i = 0; i < len; ++i)
134+
{
135+
if (!StrEqual(value[i], expected[i]))
136+
{
137+
PrintToServer("[%d] %s FAIL: %s should be '%s' at index %d, got '%s'", TestNumber, TestContext, text, expected[i], i, value[i]);
138+
ThrowError("test %d (%s in %s) failed", TestNumber, text, TestContext);
139+
break;
140+
}
141+
}
142+
PrintToServer("[%d] %s: '%s' arrays are equal OK", TestNumber, TestContext, text);
143+
}

0 commit comments

Comments
 (0)