Skip to content

Commit

Permalink
Merge pull request #20 from sharifelgamal/testing
Browse files Browse the repository at this point in the history
strip away whitespace characters for parsing
  • Loading branch information
medyagh authored Jan 13, 2021
2 parents 13a2d47 + 0cfecfa commit b8c0318
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/medyagh/gopogh

go 1.13

require github.com/GeertJohan/go.rice v1.0.0
require github.com/GeertJohan/go.rice v1.0.2
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
Expand All @@ -11,6 +13,8 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
Expand Down
10 changes: 7 additions & 3 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package parser

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"os"
Expand All @@ -10,7 +11,7 @@ import (
"github.com/medyagh/gopogh/pkg/models"
)

// parseJSON is a very forgiving JSON parser.
// ParseJSON is a very forgiving JSON parser.
func ParseJSON(path string) ([]models.TestEvent, error) {
f, err := os.Open(path)
if err != nil {
Expand All @@ -23,7 +24,10 @@ func ParseJSON(path string) ([]models.TestEvent, error) {
for scanner.Scan() {
// Go's -json output is line-by-line JSON events
b := scanner.Bytes()
if b[0] == '{' {
// Windows encodes its logs with nonsense \x00 characters, causing parsing to break entirely
// stripping these characters away is harmless and fixes the issue.
b = bytes.ReplaceAll(b, []byte("\x00"), []byte(""))
if len(b) > 0 && b[0] == '{' {
ev := models.TestEvent{}
err = json.Unmarshal(b, &ev)
if err != nil {
Expand All @@ -39,7 +43,7 @@ func ParseJSON(path string) ([]models.TestEvent, error) {
return events, err
}

// group events by their test name
// ProcessEvents group events by their test name
func ProcessEvents(evs []models.TestEvent) []models.TestGroup {
gm := map[string]int{}
groups := []models.TestGroup{}
Expand Down

0 comments on commit b8c0318

Please sign in to comment.