File: test.go

package info (click to toggle)
golang-github-mfridman-tparse 0.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,780 kB
  • sloc: makefile: 53; sh: 41
file content (50 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package parse

import (
	"sort"
)

// Test represents a single, unique, package test.
type Test struct {
	Name    string
	Package string
	Events  []*Event
}

// Elapsed indicates how long a given test ran (in seconds), by scanning for the largest
// elapsed value from all events.
func (t *Test) Elapsed() float64 {
	var f float64
	for _, e := range t.Events {
		if e.Elapsed > f {
			f = e.Elapsed
		}
	}
	return f
}

// Status reports the outcome of the test represented as a single Action: pass, fail or skip.
func (t *Test) Status() Action {
	// sort by time and scan for an action in reverse order.
	// The first action we come across (in reverse order) is
	// the outcome of the test, which will be one of pass|fail|skip.
	t.SortEvents()
	for i := len(t.Events) - 1; i >= 0; i-- {
		switch t.Events[i].Action {
		case ActionPass:
			return ActionPass
		case ActionSkip:
			return ActionSkip
		case ActionFail:
			return ActionFail
		}
	}
	return ActionFail
}

// SortEvents sorts test events by elapsed time in ascending order, i.e., oldest to newest.
func (t *Test) SortEvents() {
	sort.Slice(t.Events, func(i, j int) bool {
		return t.Events[i].Time.Before(t.Events[j].Time)
	})
}