(expression string)
| 163 | } |
| 164 | |
| 165 | func (p *ParserAssert) RunExpression(expression string) (interface{}, error) { |
| 166 | // debug doesn't make much sense with the ability to evaluate "on the fly" |
| 167 | // var debugFilter *exprhelpers.ExprDebugger |
| 168 | var output any |
| 169 | |
| 170 | logger := log.WithField("file", p.File) |
| 171 | |
| 172 | env := map[string]any{"results": *p.TestData} |
| 173 | opts := exprhelpers.GetExprOptions(env) |
| 174 | opts = append(opts, expr.Function("basename", basename, new(func (string) string))) |
| 175 | |
| 176 | // wrap with basename() in case of datasource_path, for backward compatibility |
| 177 | expression = basenameShim(expression) |
| 178 | |
| 179 | runtimeFilter, err := expr.Compile(expression, opts...) |
| 180 | if err != nil { |
| 181 | logger.Errorf("failed to compile '%s': %s", expression, err) |
| 182 | return output, err |
| 183 | } |
| 184 | |
| 185 | // dump opcode in trace level |
| 186 | logger.Tracef("%s", runtimeFilter.Disassemble()) |
| 187 | |
| 188 | output, err = expr.Run(runtimeFilter, env) |
| 189 | if err != nil { |
| 190 | logger.Warningf("running : %s", expression) |
| 191 | logger.Warningf("runtime error: %s", err) |
| 192 | |
| 193 | return output, fmt.Errorf("while running expression %s: %w", expression, err) |
| 194 | } |
| 195 | |
| 196 | return output, nil |
| 197 | } |
| 198 | |
| 199 | func (p *ParserAssert) EvalExpression(expression string) (string, error) { |
| 200 | output, err := p.RunExpression(expression) |
no test coverage detected