|
@@ -103,7 +103,6 @@ func (p *ParserAssert) AssertFile(testFile string) error {
|
|
|
p.NbAssert += 1
|
|
|
if !ok {
|
|
|
log.Debugf("%s is FALSE", scanner.Text())
|
|
|
- //fmt.SPrintf(" %s '%s'\n", emoji.RedSquare, scanner.Text())
|
|
|
failedAssert := &AssertFail{
|
|
|
File: p.File,
|
|
|
Line: nbLine,
|
|
@@ -112,10 +111,13 @@ func (p *ParserAssert) AssertFile(testFile string) error {
|
|
|
}
|
|
|
variableRE := regexp.MustCompile(`(?P<variable>[^ =]+) == .*`)
|
|
|
match := variableRE.FindStringSubmatch(scanner.Text())
|
|
|
+ variable := ""
|
|
|
if len(match) == 0 {
|
|
|
log.Infof("Couldn't get variable of line '%s'", scanner.Text())
|
|
|
+ variable = scanner.Text()
|
|
|
+ } else {
|
|
|
+ variable = match[1]
|
|
|
}
|
|
|
- variable := match[1]
|
|
|
result, err := p.EvalExpression(variable)
|
|
|
if err != nil {
|
|
|
log.Errorf("unable to evaluate variable '%s': %s", variable, err)
|
|
@@ -123,6 +125,7 @@ func (p *ParserAssert) AssertFile(testFile string) error {
|
|
|
}
|
|
|
failedAssert.Debug[variable] = result
|
|
|
p.Fails = append(p.Fails, *failedAssert)
|
|
|
+
|
|
|
continue
|
|
|
}
|
|
|
//fmt.Printf(" %s '%s'\n", emoji.GreenSquare, scanner.Text())
|
|
@@ -154,13 +157,14 @@ func (p *ParserAssert) RunExpression(expression string) (interface{}, error) {
|
|
|
env := map[string]interface{}{"results": *p.TestData}
|
|
|
|
|
|
if runtimeFilter, err = expr.Compile(expression, exprhelpers.GetExprOptions(env)...); err != nil {
|
|
|
+ log.Errorf("failed to compile '%s' : %s", expression, err)
|
|
|
return output, err
|
|
|
}
|
|
|
|
|
|
//dump opcode in trace level
|
|
|
log.Tracef("%s", runtimeFilter.Disassemble())
|
|
|
|
|
|
- output, err = expr.Run(runtimeFilter, map[string]interface{}{"results": *p.TestData})
|
|
|
+ output, err = expr.Run(runtimeFilter, env)
|
|
|
if err != nil {
|
|
|
log.Warningf("running : %s", expression)
|
|
|
log.Warningf("runtime error : %s", err)
|
|
@@ -251,8 +255,8 @@ func (p *ParserAssert) AutoGenParserAssert() string {
|
|
|
continue
|
|
|
}
|
|
|
base := fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Unmarshaled["%s"]`, stage, parser, pidx, ekey)
|
|
|
- for _, line := range p.buildUnmarshaledAssert("", eval) {
|
|
|
- ret += base + line
|
|
|
+ for _, line := range p.buildUnmarshaledAssert(base, eval) {
|
|
|
+ ret += line
|
|
|
}
|
|
|
}
|
|
|
ret += fmt.Sprintf(`results["%s"]["%s"][%d].Evt.Whitelisted == %t`+"\n", stage, parser, pidx, result.Evt.Whitelisted)
|
|
@@ -284,7 +288,8 @@ func (p *ParserAssert) buildUnmarshaledAssert(ekey string, eval interface{}) []s
|
|
|
case int:
|
|
|
ret = append(ret, fmt.Sprintf(`%s == %d`+"\n", ekey, val))
|
|
|
case float64:
|
|
|
- ret = append(ret, fmt.Sprintf(`%s == %f`+"\n", ekey, val))
|
|
|
+ ret = append(ret, fmt.Sprintf(`FloatApproxEqual(%s, %f)`+"\n",
|
|
|
+ ekey, val))
|
|
|
default:
|
|
|
log.Warningf("unknown type '%T' for key '%s'", val, ekey)
|
|
|
}
|