Repository: markus-wa/demoinfocs-golang
Pull request #285 (2021-05-14 11:21:37)

tests: make sure only known parser warnings occur in the test demo set

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) Report
> Merging [#285](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (a056da1) into [master](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/6831f8257ab2bfef7d08e6070eea6f3e9227451a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) (6831f82) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285/graphs/tree.svg?width=650&height=150&src=pr&token=20emCaZRHz&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)

```diff
@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
+ Coverage   92.05%   92.06%   +0.01%     
==========================================
  Files          29       29              
  Lines        2466     2470       +4     
==========================================
+ Hits         2270     2274       +4     
  Misses        144      144              
  Partials       52       52              
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/events/events.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3MvZXZlbnRzL2V2ZW50cy5nbw==) | `87.50% <ø> (ø)` | |
| [pkg/demoinfocs/game\_events.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus#diff-cGtnL2RlbW9pbmZvY3MvZ2FtZV9ldmVudHMuZ28=) | `93.69% <100.00%> (+0.05%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Last update [6831f82...a056da1](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/285?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Markus).


Patch:
diff --git a/pkg/demoinfocs/events/events.go b/pkg/demoinfocs/events/events.go
index e22ea92..ac7f69d 100644
--- a/pkg/demoinfocs/events/events.go
+++ b/pkg/demoinfocs/events/events.go
@@ -503,8 +503,10 @@ type StringTableCreated struct {
 type WarnType int
 
 const (
-	WarnTypeUndefined       = iota
-	WarnTypeBombsiteUnknown // may occur on de_grind for bombsite B as the bounding box of the bombsite is wrong
+	WarnTypeUndefined                  = iota
+	WarnTypeBombsiteUnknown            // may occur on de_grind for bombsite B as the bounding box of the bombsite is wrong
+	WarnTypeTeamSwapPlayerNil          // TODO: figure out why this happens
+	WarnTypeGameEventBeforeDescriptors // may occur in POV demos
 )
 
 // ParserWarn signals that a non-fatal problem occurred during parsing.
diff --git a/pkg/demoinfocs/game_events.go b/pkg/demoinfocs/game_events.go
index d170d73..178aa7d 100644
--- a/pkg/demoinfocs/game_events.go
+++ b/pkg/demoinfocs/game_events.go
@@ -20,7 +20,10 @@ func (p *parser) handleGameEventList(gel *msg.CSVCMsg_GameEventList) {
 
 func (p *parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
 	if p.gameEventDescs == nil {
-		p.eventDispatcher.Dispatch(events.ParserWarn{Message: "received GameEvent but event descriptors are missing"})
+		p.eventDispatcher.Dispatch(events.ParserWarn{
+			Message: "received GameEvent but event descriptors are missing",
+			Type:    events.WarnTypeGameEventBeforeDescriptors,
+		})
 
 		return
 	}
@@ -571,6 +574,7 @@ func (geh gameEventHandler) playerTeam(data map[string]*msg.CSVCMsg_GameEventKey
 		// TODO: figure out why this happens and whether it's a bug or not
 		geh.dispatch(events.ParserWarn{
 			Message: "Player team swap game-event occurred but player is nil",
+			Type:    events.WarnTypeTeamSwapPlayerNil,
 		})
 	}
 }


Test patch:
diff --git a/pkg/demoinfocs/demoinfocs_test.go b/pkg/demoinfocs/demoinfocs_test.go
index 0404db4..1fce8db 100644
--- a/pkg/demoinfocs/demoinfocs_test.go
+++ b/pkg/demoinfocs/demoinfocs_test.go
@@ -361,9 +361,28 @@ func TestDemoSet(t *testing.T) {
 
 				p := demoinfocs.NewParser(f)
 
-				p.RegisterEventHandler(func(event events.GenericGameEvent) {
-					if event.Name == "bot_takeover" {
-						t.Log(event.Data)
+				p.RegisterEventHandler(func(warn events.ParserWarn) {
+					switch warn.Type {
+					case events.WarnTypeBombsiteUnknown:
+						if p.Header().MapName == "de_grind" {
+							t.Log("expected known issue with bomb sites on de_grind occurred:", warn.Message)
+
+							return
+						}
+
+					case events.WarnTypeTeamSwapPlayerNil:
+						t.Log("expected known issue with team swaps occurred", warn.Message)
+						return
+
+					case events.WarnTypeGameEventBeforeDescriptors:
+						if strings.Contains(name, "POV-orbit-skytten-vs-cloud9-gfinity15sm1-nuke.dem") {
+							t.Log("expected known issue for POV demos occurred:", warn.Message)
+
+							return
+						}
+
+					default:
+						t.Error("unexpected parser warning occurred:", warn.Message)
 					}
 				})