(currentState state, line []byte, output chan<- Event)
| 405 | } |
| 406 | |
| 407 | func parseLine(currentState state, line []byte, output chan<- Event) state { |
| 408 | jsonLine := tryParseJSONLine(line) |
| 409 | if jsonLine != nil { |
| 410 | if jsonLine.Output == nil { |
| 411 | return currentState |
| 412 | } |
| 413 | line = []byte(strings.TrimRight(*jsonLine.Output, "\r\n")) |
| 414 | } |
| 415 | |
| 416 | for _, stateTransition := range stateMachine { |
| 417 | if stateTransition.inputState != currentState { |
| 418 | continue |
| 419 | } |
| 420 | |
| 421 | // Don't match the "package" action against a JSON lines - issue #52 |
| 422 | if jsonLine != nil && stateTransition.action == ActionPackage { |
| 423 | continue |
| 424 | } |
| 425 | |
| 426 | if match := stateTransition.regexp.FindSubmatch(line); len(match) != 0 { |
| 427 | elapsed, err := getTimeElapsed(stateTransition.regexp, match, "Elapsed") |
| 428 | if err == nil { |
| 429 | coverageString := string(extract(stateTransition.regexp, match, "Coverage")) |
| 430 | coverage := -1.0 |
| 431 | if coverageString != "" { |
| 432 | coverage, err = strconv.ParseFloat(coverageString, 64) |
| 433 | if err != nil { |
| 434 | continue |
| 435 | } |
| 436 | } |
| 437 | var coveragePtr *float64 |
| 438 | if coverage >= 0 { |
| 439 | coveragePtr = &coverage |
| 440 | } |
| 441 | |
| 442 | pkg := string(extract(stateTransition.regexp, match, "Package")) |
| 443 | if jsonLine != nil && pkg == "" { |
| 444 | pkg = jsonLine.Package |
| 445 | } |
| 446 | version := string(extract(stateTransition.regexp, match, "Version")) |
| 447 | test := string(extract(stateTransition.regexp, match, "Test")) |
| 448 | if jsonLine != nil && test == "" { |
| 449 | test = jsonLine.Test |
| 450 | } |
| 451 | cached := string(extract(stateTransition.regexp, match, "Cached")) == "cached" |
| 452 | received := time.Now() |
| 453 | if jsonLine != nil && jsonLine.Time != nil { |
| 454 | received = *jsonLine.Time |
| 455 | } |
| 456 | if jsonLine != nil && jsonLine.Elapsed != nil && *jsonLine.Elapsed > 0 { |
| 457 | elapsed = time.Duration(*jsonLine.Elapsed * float64(time.Second)) |
| 458 | } |
| 459 | evt := Event{ |
| 460 | Received: received, |
| 461 | Action: stateTransition.action, |
| 462 | Package: pkg, |
| 463 | Version: version, |
| 464 | Test: test, |
no test coverage detected