(testFile string)
| 71 | } |
| 72 | |
| 73 | func (p *ParserAssert) AssertFile(testFile string) error { |
| 74 | file, err := os.Open(p.File) |
| 75 | if err != nil { |
| 76 | return errors.New("failed to open") |
| 77 | } |
| 78 | |
| 79 | if err := p.LoadTest(testFile); err != nil { |
| 80 | return fmt.Errorf("unable to load parser dump file '%s': %w", testFile, err) |
| 81 | } |
| 82 | |
| 83 | scanner := bufio.NewScanner(file) |
| 84 | scanner.Split(bufio.ScanLines) |
| 85 | |
| 86 | nbLine := 0 |
| 87 | |
| 88 | for scanner.Scan() { |
| 89 | nbLine++ |
| 90 | |
| 91 | if scanner.Text() == "" { |
| 92 | continue |
| 93 | } |
| 94 | |
| 95 | ok, err := p.Run(scanner.Text()) |
| 96 | if err != nil { |
| 97 | return fmt.Errorf("unable to run assert '%s': %w", scanner.Text(), err) |
| 98 | } |
| 99 | |
| 100 | p.NbAssert++ |
| 101 | |
| 102 | if !ok { |
| 103 | log.Debugf("%s is FALSE", scanner.Text()) |
| 104 | failedAssert := &AssertFail{ |
| 105 | File: p.File, |
| 106 | Line: nbLine, |
| 107 | Expression: scanner.Text(), |
| 108 | Debug: make(map[string]string), |
| 109 | } |
| 110 | |
| 111 | match := variableRE.FindStringSubmatch(scanner.Text()) |
| 112 | |
| 113 | var variable string |
| 114 | |
| 115 | if len(match) == 0 { |
| 116 | log.Infof("Couldn't get variable of line '%s'", scanner.Text()) |
| 117 | variable = scanner.Text() |
| 118 | } else { |
| 119 | variable = match[1] |
| 120 | } |
| 121 | |
| 122 | result, err := p.EvalExpression(variable) |
| 123 | if err != nil { |
| 124 | log.Errorf("unable to evaluate variable '%s': %s", variable, err) |
| 125 | continue |
| 126 | } |
| 127 | |
| 128 | failedAssert.Debug[variable] = result |
| 129 | p.Fails = append(p.Fails, *failedAssert) |
| 130 |
no test coverage detected