зеркало из https://github.com/mozilla/scribe.git
additional error checking
This commit is contained in:
Родитель
c72107b2b4
Коммит
be5e76abdd
|
@ -6,16 +6,20 @@
|
|||
// - Aaron Meihm ameihm@mozilla.com
|
||||
package scribe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type EVRTest struct {
|
||||
Operation string `json:"operation"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (e *EVRTest) evaluate(c evaluationCriteria) (ret evaluationResult) {
|
||||
func (e *EVRTest) evaluate(c evaluationCriteria) (ret evaluationResult, err error) {
|
||||
debugPrint("evaluate(): evr %v \"%v\", %v \"%v\"\n", c.Identifier, c.TestValue, e.Operation, e.Value)
|
||||
evrop := evrLookupOperation(e.Operation)
|
||||
if evrop == EVROP_UNKNOWN {
|
||||
return
|
||||
return ret, fmt.Errorf("invalid evr operation \"%v\"", e.Operation)
|
||||
}
|
||||
if evrCompare(evrop, c.TestValue, e.Value) {
|
||||
debugPrint("evaluate(): evr comparison operation was true\n")
|
||||
|
|
|
@ -14,9 +14,10 @@ type Regexp struct {
|
|||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (r *Regexp) evaluate(c evaluationCriteria) (ret evaluationResult) {
|
||||
func (r *Regexp) evaluate(c evaluationCriteria) (ret evaluationResult, err error) {
|
||||
var re *regexp.Regexp
|
||||
debugPrint("evaluate(): regexp %v \"%v\", \"%v\"\n", c.Identifier, c.TestValue, r.Value)
|
||||
re, err := regexp.Compile(r.Value)
|
||||
re, err = regexp.Compile(r.Value)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ type genericSource interface {
|
|||
}
|
||||
|
||||
type genericEvaluator interface {
|
||||
evaluate(evaluationCriteria) evaluationResult
|
||||
evaluate(evaluationCriteria) (evaluationResult, error)
|
||||
}
|
||||
|
||||
func (t *Test) getEvaluationInterface() genericEvaluator {
|
||||
|
@ -119,7 +119,12 @@ func (t *Test) runTest(d *Document) error {
|
|||
return t.err
|
||||
}
|
||||
for _, x := range si.getCriteria() {
|
||||
ev.evaluate(x)
|
||||
res, err := ev.evaluate(x)
|
||||
if err != nil {
|
||||
t.err = err
|
||||
return t.err
|
||||
}
|
||||
t.results = append(t.results, res)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Загрузка…
Ссылка в новой задаче