extractLogs parses the "// want" comments in src into a slice of logLine structs.
(src []byte)
| 860 | // extractLogs parses the "// want" comments in src |
| 861 | // into a slice of logLine structs. |
| 862 | func extractLogs(src []byte) ([]logLine, error) { |
| 863 | fset := token.NewFileSet() |
| 864 | f, err := parser.ParseFile(fset, "", src, parser.ParseComments) |
| 865 | if err != nil { |
| 866 | return nil, errtrace.Wrap(fmt.Errorf("parse: %w", err)) |
| 867 | } |
| 868 | |
| 869 | var logs []logLine |
| 870 | for _, c := range f.Comments { |
| 871 | for _, l := range c.List { |
| 872 | _, lit, ok := strings.Cut(l.Text, "// want:") |
| 873 | if !ok { |
| 874 | continue |
| 875 | } |
| 876 | |
| 877 | pos := fset.Position(l.Pos()) |
| 878 | s, err := strconv.Unquote(lit) |
| 879 | if err != nil { |
| 880 | return nil, errtrace.Wrap(fmt.Errorf("%s:bad string literal: %s", pos, lit)) |
| 881 | } |
| 882 | |
| 883 | logs = append(logs, logLine{Line: pos.Line, Msg: s}) |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | sort.Slice(logs, func(i, j int) bool { |
| 888 | return logs[i].Line < logs[j].Line |
| 889 | }) |
| 890 | |
| 891 | return logs, nil |
| 892 | } |
| 893 | |
| 894 | func parseLogOutput(file, s string) ([]logLine, error) { |
| 895 | var logs []logLine |
no test coverage detected