• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 12909016548

22 Jan 2025 01:14PM CUT coverage: 61.572%. Remained the same
12909016548

push

github

web-flow
Fix field name in config template (#96)

987 of 1603 relevant lines covered (61.57%)

29.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/document/processor.go
1
package document
2

3
import (
4
        "fmt"
5
        "log"
6
        "os"
7
        "strings"
8
        "text/template"
9
)
10

11
type Processor struct {
12
        Config             *Config
13
        Template           *template.Template
14
        Formatter          Formatter
15
        Docs               *Docs
16
        ExportDocs         *Docs
17
        allPaths           map[string]bool
18
        linkTargets        map[string]elemPath
19
        linkExports        map[string]string
20
        linkExportsReverse map[string]*exportError
21
        docTests           []*docTest
22
        writer             func(file, text string) error
23
}
24

25
type exportError struct {
26
        NewPath  string
27
        OldPaths []string
28
}
29

30
type docTest struct {
31
        Name   string
32
        Path   []string
33
        Code   []string
34
        Global []string
35
}
36

37
func NewProcessor(docs *Docs, f Formatter, t *template.Template, config *Config) *Processor {
10✔
38
        return NewProcessorWithWriter(docs, f, t, config, func(file, text string) error {
19✔
39
                return os.WriteFile(file, []byte(text), 0644)
9✔
40
        })
9✔
41
}
42

43
func NewProcessorWithWriter(docs *Docs, f Formatter, t *template.Template, config *Config, writer func(file, text string) error) *Processor {
15✔
44
        return &Processor{
15✔
45
                Config:    config,
15✔
46
                Template:  t,
15✔
47
                Formatter: f,
15✔
48
                Docs:      docs,
15✔
49
                writer:    writer,
15✔
50
        }
15✔
51
}
15✔
52

53
// PrepareDocs processes the API docs for subsequent rendering.
54
func (proc *Processor) PrepareDocs() error {
6✔
55
        err := proc.ExtractTests()
6✔
56
        if err != nil {
6✔
57
                return err
×
58
        }
×
59

60
        // Re-structure according to exports.
61
        err = proc.filterPackages()
6✔
62
        if err != nil {
6✔
63
                return err
×
64
        }
×
65
        // Collect all link target paths.
66
        proc.collectPaths()
6✔
67
        if !proc.Config.UseExports {
9✔
68
                for k := range proc.linkTargets {
16✔
69
                        proc.linkExports[k] = k
13✔
70
                }
13✔
71
        }
72
        // Replaces cross-refs by placeholders.
73
        if err := proc.processLinks(proc.Docs); err != nil {
6✔
74
                return err
×
75
        }
×
76
        return nil
6✔
77
}
78

79
func (proc *Processor) ExtractTests() error {
6✔
80
        // Collect the paths of all (sub)-elements in the original structure.
6✔
81
        proc.collectElementPaths()
6✔
82

6✔
83
        // Extract doc tests.
6✔
84
        err := proc.extractDocTests()
6✔
85
        if err != nil {
6✔
86
                return err
×
87
        }
×
88
        if proc.Config.TestOutput != "" {
6✔
89
                err = proc.writeDocTests(proc.Config.TestOutput)
×
90
                if err != nil {
×
91
                        return err
×
92
                }
×
93
        }
94
        return nil
6✔
95
}
96

97
func (proc *Processor) WriteFile(file, text string) error {
33✔
98
        return proc.writer(file, text)
33✔
99
}
33✔
100

101
func (proc *Processor) warnOrError(pattern string, args ...any) error {
×
102
        if proc.Config.Strict {
×
103
                return fmt.Errorf(pattern, args...)
×
104
        }
×
105
        log.Printf("WARNING: "+pattern+"\n", args...)
×
106
        return nil
×
107
}
108

109
func (proc *Processor) addLinkExport(oldPath, newPath []string) {
70✔
110
        pNew := strings.Join(newPath, ".")
70✔
111
        pOld := strings.Join(oldPath, ".")
70✔
112
        if present, ok := proc.linkExportsReverse[pNew]; ok {
70✔
113
                present.OldPaths = append(present.OldPaths, pOld)
×
114
        } else {
70✔
115
                proc.linkExportsReverse[pNew] = &exportError{
70✔
116
                        NewPath:  pNew,
70✔
117
                        OldPaths: []string{pOld},
70✔
118
                }
70✔
119
        }
70✔
120
        proc.linkExports[pOld] = pNew
70✔
121
}
122

123
func (proc *Processor) addLinkTarget(elPath, filePath []string, kind string, isSection bool) {
76✔
124
        proc.linkTargets[strings.Join(elPath, ".")] = elemPath{Elements: filePath, Kind: kind, IsSection: isSection}
76✔
125
}
76✔
126

127
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
90✔
128
        if isSection && kind != "package" && kind != "module" { // actually, we are catching aliases here
117✔
129
                return
27✔
130
        }
27✔
131
        proc.allPaths[strings.Join(elPath, ".")] = true
63✔
132
        _, _ = filePath, kind
63✔
133
}
134

135
func (proc *Processor) mkDirs(path string) error {
16✔
136
        if proc.Config.DryRun {
20✔
137
                return nil
4✔
138
        }
4✔
139
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
12✔
140
                return err
×
141
        }
×
142
        return nil
12✔
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc