Skip to content

Commit af64f51

Browse files
committed
use go-unassert for assertions in CI tests
1 parent c836d1f commit af64f51

File tree

8 files changed

+44
-13
lines changed

8 files changed

+44
-13
lines changed

bin/coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ coverpkg=$(go list ./... | grep -v -E ${coverpkg_ignore} | awk -vORS=, '{ print
1010

1111
# -timeout 30m because the CI is slow
1212
# output file must be called 'coverage.txt' for Codecov
13-
go test -v -timeout 30m -coverprofile=coverage.txt -coverpkg=$coverpkg ./...
13+
go test -v -timeout 30m -coverprofile=coverage.txt -coverpkg=$coverpkg -tags unassert_panic ./...

bin/regression-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -e
44

55
bin/download-test-data.sh default.7z unexpected_end_of_demo.7z regression-set.7z
66

7-
go test ./...
7+
go test -tags unassert_panic ./...

bin/unit-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -e
44

5-
go test -short ./...
5+
go test -tags unassert_panic -short ./...

game_events.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strconv"
66

77
"github.com/golang/geo/r3"
8+
"github.com/markus-wa/go-unassert"
89

910
"github.com/markus-wa/demoinfocs-golang/common"
1011
"github.com/markus-wa/demoinfocs-golang/events"
@@ -20,7 +21,8 @@ func (p *Parser) handleGameEventList(gel *msg.CSVCMsg_GameEventList) {
2021

2122
func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
2223
if p.gameEventDescs == nil {
23-
p.eventDispatcher.Dispatch(events.ParserWarn{Message: "Received GameEvent but event descriptors are missing"})
24+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: "received GameEvent but event descriptors are missing"})
25+
unassert.Error("received GameEvent but event descriptors are missing")
2426
return
2527
}
2628

@@ -37,7 +39,8 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
3739
handler(data)
3840
}
3941
} else {
40-
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("Unknown event %q", desc.Name)})
42+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("unknown event %q", desc.Name)})
43+
unassert.Error("unknown event %q", desc.Name)
4144
}
4245

4346
p.eventDispatcher.Dispatch(events.GenericGameEvent{
@@ -126,6 +129,7 @@ func newGameEventHandler(parser *Parser) gameEventHandler {
126129
"hegrenade_detonate": geh.heGrenadeDetonate, // HE exploded
127130
"hltv_chase": nil, // Don't care
128131
"hltv_fixed": nil, // Dunno
132+
"hltv_message": nil, // No clue
129133
"hltv_status": nil, // Don't know
130134
"inferno_expire": geh.infernoExpire, // Incendiary expired
131135
"inferno_startburn": delay(geh.infernoStartBurn), // Incendiary exploded/started. Delayed because inferno entity is not yet created
@@ -325,10 +329,18 @@ func (geh gameEventHandler) playerHurt(data map[string]*msg.CSVCMsg_GameEventKey
325329

326330
func (geh gameEventHandler) playerBlind(data map[string]*msg.CSVCMsg_GameEventKeyT) {
327331
attacker := geh.gameState().lastFlash.player
332+
projectile := geh.gameState().lastFlash.projectileByPlayer[attacker]
333+
unassert.NotNilf(projectile, "PlayerFlashed.Projectile should never be nil")
334+
335+
if projectile != nil {
336+
unassert.Samef(attacker, projectile.Thrower, "PlayerFlashed.Attacker != PlayerFlashed.Projectile.Thrower")
337+
unassert.Samef(projectile.Weapon, common.EqFlash, "PlayerFlashed.Projectile.Weapon != EqFlash")
338+
}
339+
328340
geh.dispatch(events.PlayerFlashed{
329341
Player: geh.playerByUserID32(data["userid"].GetValShort()),
330342
Attacker: attacker,
331-
Projectile: geh.gameState().lastFlash.projectileByPlayer[attacker],
343+
Projectile: projectile,
332344
})
333345
}
334346

@@ -435,6 +447,7 @@ func (geh gameEventHandler) playerTeam(data map[string]*msg.CSVCMsg_GameEventKey
435447
OldTeamState: geh.gameState().Team(oldTeam),
436448
})
437449
} else {
450+
// TODO: figure out why this happens and whether it's a bug or not
438451
geh.dispatch(events.ParserWarn{
439452
Message: "Player team swap game-event occurred but player is nil",
440453
})

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/golang/geo v0.0.0-20190916061304-5b978397cfec
88
github.com/llgcode/draw2d v0.0.0-20180124133339-274031cf2abe
99
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb // indirect
10+
github.com/markus-wa/go-unassert v0.1.1
1011
github.com/markus-wa/gobitread v0.2.2
1112
github.com/markus-wa/godispatch v1.1.0
1213
github.com/markus-wa/quickhull-go/v2 v2.1.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb h1:61ndUreYSlWFeCY44JxD
1717
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb/go.mod h1:1l8ky+Ew27CMX29uG+a2hNOKpeNYEQjjtiALiBlFQbY=
1818
github.com/markus-wa/go-heatmap v1.0.0 h1:UT3+9Re6Fr6h4Qs7y0QmVjlvbu+92E9tnuqKEhJta08=
1919
github.com/markus-wa/go-heatmap v1.0.0/go.mod h1:mUE6YBiMclq9MYXCb8fLbiWvyZtGglLrfMJ+LSHrlPA=
20+
github.com/markus-wa/go-unassert v0.1.0 h1:SQlhZEu0GmO4kD2zz5wgqLxX5MKl2LZwYRz9thg7keo=
21+
github.com/markus-wa/go-unassert v0.1.0/go.mod h1:XEvrxR+trvZeMDfXcZPvzqGo6eumEtdk5VjNRuvvzxQ=
22+
github.com/markus-wa/go-unassert v0.1.1 h1:Bn7NfuD85DFdUoGQREI3PWNT1m0THYbYazHmOVIPNYQ=
23+
github.com/markus-wa/go-unassert v0.1.1/go.mod h1:XEvrxR+trvZeMDfXcZPvzqGo6eumEtdk5VjNRuvvzxQ=
2024
github.com/markus-wa/gobitread v0.2.2 h1:4Z4oJ8Bf1XnOy6JZ2/9AdFKVAoxdq7awRjrb+j2BeSQ=
2125
github.com/markus-wa/gobitread v0.2.2/go.mod h1:PcWXMH4gx7o2CKslbkFkLyJB/aHW7JVRG3MRZe3PINg=
2226
github.com/markus-wa/godispatch v1.1.0 h1:J8O+hRkOCexDUQevaSKWDtKeZ3+HcmbEUKY1uYraAjY=

parsing.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/gogo/protobuf/proto"
11+
"github.com/markus-wa/go-unassert"
1112

1213
"github.com/markus-wa/demoinfocs-golang/common"
1314
"github.com/markus-wa/demoinfocs-golang/events"
@@ -292,7 +293,8 @@ func (p *Parser) parsePacket() {
292293
if msgName == "" {
293294
// Send a warning if the command is unknown
294295
// This might mean our proto files are out of date
295-
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("Unknown message command %q", cmd)})
296+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("unknown message command %q", cmd)})
297+
unassert.Error("unknown message command %q", cmd)
296298
}
297299

298300
// Handle additional net-messages as defined by the user

user_messages.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package demoinfocs
33
import (
44
"fmt"
55

6-
events "github.com/markus-wa/demoinfocs-golang/events"
7-
msg "github.com/markus-wa/demoinfocs-golang/msg"
6+
"github.com/markus-wa/go-unassert"
7+
8+
"github.com/markus-wa/demoinfocs-golang/events"
9+
"github.com/markus-wa/demoinfocs-golang/msg"
810
)
911

1012
func (p *Parser) handleUserMessage(um *msg.CSVCMsg_UserMessage) {
@@ -51,7 +53,8 @@ func (umh userMessageHandler) sayText(um *msg.CSVCMsg_UserMessage) {
5153
st := new(msg.CCSUsrMsg_SayText)
5254
err := st.Unmarshal(um.MsgData)
5355
if err != nil {
54-
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("Failed to decode SayText message: %s", err.Error())})
56+
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("failed to decode SayText message: %s", err.Error())})
57+
unassert.Error("failed to decode SayText message: %s", err.Error())
5558
}
5659

5760
umh.dispatch(events.SayText{
@@ -66,7 +69,8 @@ func (umh userMessageHandler) sayText2(um *msg.CSVCMsg_UserMessage) {
6669
st := new(msg.CCSUsrMsg_SayText2)
6770
err := st.Unmarshal(um.MsgData)
6871
if err != nil {
69-
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("Failed to decode SayText2 message: %s", err.Error())})
72+
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("failed to decode SayText2 message: %s", err.Error())})
73+
unassert.Error("failed to decode SayText2 message: %s", err.Error())
7074
}
7175

7276
umh.dispatch(events.SayText2{
@@ -91,17 +95,24 @@ func (umh userMessageHandler) sayText2(um *msg.CSVCMsg_UserMessage) {
9195

9296
case "#CSGO_Coach_Join_T": // Ignore these
9397
case "#CSGO_Coach_Join_CT":
98+
case "#Cstrike_Name_Change":
99+
case "Cstrike_Chat_T_Loc":
100+
case "Cstrike_Chat_CT_Loc":
101+
case "Cstrike_Chat_T_Dead":
102+
case "Cstrike_Chat_CT_Dead":
94103

95104
default:
96-
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("Skipped sending ChatMessageEvent for SayText2 with unknown MsgName %q", st.MsgName)})
105+
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("skipped sending ChatMessageEvent for SayText2 with unknown MsgName %q", st.MsgName)})
106+
unassert.Error("skipped sending ChatMessageEvent for SayText2 with unknown MsgName %q", st.MsgName)
97107
}
98108
}
99109

100110
func (umh userMessageHandler) rankUpdate(um *msg.CSVCMsg_UserMessage) {
101111
st := new(msg.CCSUsrMsg_ServerRankUpdate)
102112
err := st.Unmarshal(um.MsgData)
103113
if err != nil {
104-
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("Failed to decode ServerRankUpdate message: %s", err.Error())})
114+
umh.dispatch(events.ParserWarn{Message: fmt.Sprintf("failed to decode ServerRankUpdate message: %s", err.Error())})
115+
unassert.Error("failed to decode ServerRankUpdate message: %s", err.Error())
105116
}
106117

107118
for _, v := range st.RankUpdate {

0 commit comments

Comments
 (0)