forked from jylitalo/go2md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go2md_test.go
43 lines (40 loc) · 1.11 KB
/
go2md_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"os"
"strings"
"testing"
)
// TestRun generates markdown from pkg and compares it against README.md file.
func TestMain(t *testing.T) {
t.Run("validate output", func(t *testing.T) {
readme, err := os.ReadFile("README.md")
if err != nil {
t.Error("failed to read README.md")
}
os.Args = []string{"go2md", "--output=README2.md"}
main()
readme2, err := os.ReadFile("README2.md")
if err != nil {
t.Error("failed to read README2.md")
}
expected := strings.TrimSpace(string(readme))
received := strings.TrimSpace(string(readme2))
if expected != received {
t.Error("outputs don't match")
expLines := strings.Split(expected, "\n")
recvLines := strings.Split(received, "\n")
if len(expLines) != len(recvLines) {
t.Logf("Number of lines (expected %d vs. received %d", len(expLines), len(recvLines))
}
commonLines := len(expLines)
if commonLines < len(recvLines) {
commonLines = len(recvLines)
}
for i := 0; i < commonLines; i++ {
if expLines[i] != recvLines[i] {
t.Logf("Line #%d: %s vs. %s", i, expLines[i], recvLines[i])
}
}
}
})
}