-
Notifications
You must be signed in to change notification settings - Fork 83
/
statuses.go
197 lines (161 loc) · 6.04 KB
/
statuses.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright 2018 The WPT Dashboard Project. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package shared
import "encoding/json"
//
// Shared data types used for string WPT test results in query cache.
//
// TestStatus represents the possible test result statuses.
type TestStatus int64
const (
// TestStatusUnknown is an uninitialized TestStatus and should
// not be used.
TestStatusUnknown TestStatus = 0
// TestStatusPass indicates that all tests completed successfully and passed.
TestStatusPass TestStatus = 1
// TestStatusOK indicates that all tests completed successfully.
TestStatusOK TestStatus = 2
// TestStatusError indicates that some tests did not complete
// successfully.
TestStatusError TestStatus = 3
// TestStatusTimeout indicates that some tests timed out.
TestStatusTimeout TestStatus = 4
// TestStatusNotRun indicates that a test was not run.
TestStatusNotRun TestStatus = 5
// TestStatusFail indicates that a test failed.
TestStatusFail TestStatus = 6
// TestStatusCrash indicates that the WPT test runner crashed attempting to run the test.
TestStatusCrash TestStatus = 7
// TestStatusSkip indicates that the test was disabled for this test run.
TestStatusSkip TestStatus = 8
// TestStatusAssert indicates that a non-fatal assertion failed. This test
// status is supported by, at least, Mozilla.
TestStatusAssert TestStatus = 9
// TestStatusNameUnknown is the string representation for an uninitialized
// TestStatus and should not be used.
TestStatusNameUnknown string = "UNKNOWN"
// TestStatusNamePass is the string representation of a test result where the
// test passed.
TestStatusNamePass string = "PASS"
// TestStatusNameOK is the string represnetation of a test result where the
// test ran completely but may not have passed (and/or not all of its subtests
// passed).
TestStatusNameOK string = "OK"
// TestStatusNameError is the string representation for a test result where
// a test harness error was encountered at test runtime.
TestStatusNameError string = "ERROR"
// TestStatusNameTimeout is the string representation for a test result where
// the test timed out.
TestStatusNameTimeout string = "TIMEOUT"
// TestStatusNameNotRun is the string representation for a test result where
// the test exists but was not run.
TestStatusNameNotRun string = "NOTRUN"
// TestStatusNameFail is the string representation of a test result where the
// test failed.
TestStatusNameFail string = "FAIL"
// TestStatusNameCrash is the string representation of a test result where the
// test runner crashed.
TestStatusNameCrash string = "CRASH"
// TestStatusNameSkip is the string representation of a test result where the
// test was disabled for this test run.
TestStatusNameSkip string = "SKIP"
// TestStatusNameAssert is the string representation of a test result where
// a non-fatal assertion failed. This test status is supported by, at least,
// Mozilla.
TestStatusNameAssert string = "ASSERT"
// TestStatusDefault is the default value used when a status string cannot be
// interpreted.
TestStatusDefault TestStatus = TestStatusUnknown
// TestStatusNameDefault is the default string used when a status value cannot
// be interpreted.
TestStatusNameDefault string = TestStatusNameUnknown
)
var testStatusValues = map[string]TestStatus{
"MISSING": TestStatusUnknown,
TestStatusNameUnknown: TestStatusUnknown,
TestStatusNamePass: TestStatusPass,
TestStatusNameOK: TestStatusOK,
TestStatusNameError: TestStatusError,
TestStatusNameTimeout: TestStatusTimeout,
TestStatusNameNotRun: TestStatusNotRun,
TestStatusNameFail: TestStatusFail,
TestStatusNameCrash: TestStatusCrash,
TestStatusNameSkip: TestStatusSkip,
TestStatusNameAssert: TestStatusAssert,
}
var testStatusNames = map[TestStatus]string{
TestStatusUnknown: TestStatusNameUnknown,
TestStatusPass: TestStatusNamePass,
TestStatusOK: TestStatusNameOK,
TestStatusError: TestStatusNameError,
TestStatusTimeout: TestStatusNameTimeout,
TestStatusNotRun: TestStatusNameNotRun,
TestStatusFail: TestStatusNameFail,
TestStatusCrash: TestStatusNameCrash,
TestStatusSkip: TestStatusNameSkip,
TestStatusAssert: TestStatusNameAssert,
}
// IsPassOrOK is true if the value is TestStatusPass or TestStatusOK
func (s TestStatus) IsPassOrOK() bool {
return s == TestStatusOK || s == TestStatusPass
}
// IsHarnessStatus is true if the value is TestStatusPass or TestStatusError,
// statuses which are used for the harness-level result.
func (s TestStatus) IsHarnessStatus() bool {
return s == TestStatusOK
}
// IsPass is true if the value is TestStatusPass.
func (s TestStatus) IsPass() bool {
return s == TestStatusPass
}
// TestStatusValueFromString returns the enum value associated with str (if
// any), or else TestStatusDefault.
func TestStatusValueFromString(str string) TestStatus {
v, ok := testStatusValues[str]
if !ok {
return TestStatusDefault
}
return v
}
// String returns the string associated with s (if any), or else TestStatusStringDefault.
func (s TestStatus) String() string {
str, ok := testStatusNames[s]
if !ok {
return TestStatusNameDefault
}
return str
}
// UnmarshalJSON is the custom JSON unmarshaler for TestStatus.
func (s *TestStatus) UnmarshalJSON(b []byte) error {
var str string
var err error
if err = json.Unmarshal(b, &str); err == nil {
*s = TestStatusValueFromString(str)
return nil
}
var i int64
if err = json.Unmarshal(b, &i); err == nil {
*s = TestStatus(i)
return nil
}
return err
}
// UnmarshalYAML unmarshals a TestStatus as either a name string or a number.
func (s *TestStatus) UnmarshalYAML(unmarshal func(interface{}) error) (err error) {
var str string
if err = unmarshal(&str); err == nil {
*s = TestStatusValueFromString(str)
return nil
}
var i int64
if err = unmarshal(&i); err == nil {
*s = TestStatus(i)
return nil
}
return err
}
// MarshalYAML serializes TestStatus into a YAML string.
func (s *TestStatus) MarshalYAML() (interface{}, error) {
return s.String(), nil
}