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

mlange-42 / modo / 12976417773

26 Jan 2025 04:29PM UTC coverage: 58.343% (-2.4%) from 60.763%
12976417773

Pull #119

github

web-flow
Merge 6e543a5bd into d643b4693
Pull Request #119: Test markdown files

8 of 90 new or added lines in 4 files covered. (8.89%)

2 existing lines in 1 file now uncovered.

993 of 1702 relevant lines covered (58.34%)

28.57 hits per line

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

76.83
/document/processor.go
1
package document
2

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

10
type Processor struct {
11
        Config             *Config
12
        Template           *template.Template
13
        Formatter          Formatter
14
        Docs               *Docs
15
        ExportDocs         *Docs
16
        allPaths           map[string]bool         // Full paths of all original members. Used to check whether all re-exports could be found.
17
        linkTargets        map[string]elemPath     // Mapping from full (new) member paths to link strings.
18
        linkExports        map[string]string       // Mapping from original to new member paths.
19
        linkExportsReverse map[string]*exportError // Used to check for name collisions through re-exports.
20
        docTests           []*docTest
21
        writer             func(file, text string) error
22
}
23

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

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

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

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

52
// PrepareDocs processes the API docs for subsequent rendering.
53
func (proc *Processor) PrepareDocs(subdir string) error {
6✔
54
        err := proc.ExtractTests(subdir)
6✔
55
        if err != nil {
6✔
56
                return err
×
57
        }
×
58
        // Re-structure according to exports.
59
        err = proc.filterPackages()
6✔
60
        if err != nil {
6✔
61
                return err
×
62
        }
×
63
        // Collect all link target paths.
64
        proc.collectPaths()
6✔
65
        if !proc.Config.UseExports {
9✔
66
                for k := range proc.linkTargets {
16✔
67
                        proc.linkExports[k] = k
13✔
68
                }
13✔
69
        }
70
        // Replaces cross-refs by placeholders.
71
        if err := proc.processLinks(proc.Docs); err != nil {
6✔
72
                return err
×
73
        }
×
74
        return nil
6✔
75
}
76

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

6✔
81
        // Extract doc tests.
6✔
82
        err := proc.extractDocTests()
6✔
83
        if err != nil {
6✔
84
                return err
×
85
        }
×
86
        if proc.Config.TestOutput != "" {
6✔
87
                outPath := path.Join(proc.Config.TestOutput, subdir, proc.Docs.Decl.Name)
×
88
                err = proc.writeDocTests(outPath)
×
89
                if err != nil {
×
90
                        return err
×
91
                }
×
92
        }
93
        return nil
6✔
94
}
95

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

100
func (proc *Processor) warnOrError(pattern string, args ...any) error {
×
NEW
101
        return warnOrError(proc.Config.Strict, pattern, args...)
×
102
}
×
103

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

118
func (proc *Processor) addLinkTarget(elPath, filePath []string, kind string, isSection bool) {
76✔
119
        proc.linkTargets[strings.Join(elPath, ".")] = elemPath{Elements: filePath, Kind: kind, IsSection: isSection}
76✔
120
}
76✔
121

122
func (proc *Processor) addElementPath(elPath, filePath []string, kind string, isSection bool) {
90✔
123
        if isSection && kind != "package" && kind != "module" { // actually, we are want to let aliases pass
117✔
124
                return
27✔
125
        }
27✔
126
        proc.allPaths[strings.Join(elPath, ".")] = true
63✔
127
        _ = filePath
63✔
128
}
129

130
func (proc *Processor) mkDirs(path string) error {
16✔
131
        if proc.Config.DryRun {
20✔
132
                return nil
4✔
133
        }
4✔
134
        if err := os.MkdirAll(path, os.ModePerm); err != nil && !os.IsExist(err) {
12✔
135
                return err
×
136
        }
×
137
        return nil
12✔
138
}
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