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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
package pkglint
import "gopkg.in/check.v1"
func (s *Suite) Test_NewLines(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"text")
t.CheckEquals(lines.Filename, NewCurrPathString("filename"))
}
func (s *Suite) Test_Lines_Len(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"one",
"two",
"three")
t.CheckEquals(lines.Len(), 3)
}
func (s *Suite) Test_Lines_LastLine(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"text")
whole := lines.LastLine()
t.CheckEquals(whole.String(), "filename:1: text")
}
func (s *Suite) Test_Lines_EOFLine(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"text")
whole := lines.EOFLine()
// The text of the line after the ': ' is empty.
t.CheckEquals(whole.String(), "filename:EOF: ")
}
func (s *Suite) Test_Lines_Whole(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"text")
whole := lines.Whole()
// The lineno between the '::' is empty.
// The text of the line after the ': ' is empty as well.
t.CheckEquals(whole.String(), "filename:: ")
}
func (s *Suite) Test_Lines_SaveAutofixChanges(c *check.C) {
t := s.Init(c)
doTest := func(autofix bool) {
lines := t.SetUpFileLines("filename",
"before")
fix := lines.Lines[0].Autofix()
fix.Notef("Replacing.")
fix.Replace("before", "after")
fix.Apply()
lines.SaveAutofixChanges()
}
t.ExpectDiagnosticsAutofix(
doTest,
"NOTE: ~/filename:1: Replacing.",
"AUTOFIX: ~/filename:1: Replacing \"before\" with \"after\".")
}
func (s *Suite) Test_Lines_CheckCvsID(c *check.C) {
t := s.Init(c)
lines := t.NewLines("filename",
"$"+"NetBSD: dummy $",
"$"+"NetBSD$",
"$"+"Id: dummy $",
"$"+"Id$",
"$"+"FreeBSD$")
for i := range lines.Lines {
lines.CheckCvsID(i, ``, "")
}
t.CheckOutputLines(
"ERROR: filename:3: Expected \"$"+"NetBSD$\".",
"ERROR: filename:4: Expected \"$"+"NetBSD$\".",
"ERROR: filename:5: Expected \"$"+"NetBSD$\".")
}
// Since pkgsrc-wip uses Git as version control system, the CVS-specific
// IDs don't make sense there. More often than not, the expanded form
// "$NetBSD:" is a copy-and-paste mistake rather than an intentional
// documentation of the file's history. Therefore, pkgsrc-wip files should
// only use the unexpanded form.
func (s *Suite) Test_Lines_CheckCvsID__wip(c *check.C) {
t := s.Init(c)
G.Experimental = true
t.SetUpPkgsrc()
t.SetUpPackage("wip/package")
t.CreateFileLines("wip/package/file1.mk",
"# $"+"NetBSD: dummy $")
t.CreateFileLines("wip/package/file2.mk",
"# $"+"NetBSD$")
t.CreateFileLines("wip/package/file3.mk",
"# $"+"Id: dummy $")
t.CreateFileLines("wip/package/file4.mk",
"# $"+"Id$")
t.CreateFileLines("wip/package/file5.mk",
"# $"+"FreeBSD$")
t.FinishSetUp()
G.Check(t.File("wip/package"))
t.CheckOutputLines(
"NOTE: ~/wip/package/file1.mk:1: Expected exactly \"# $"+"NetBSD$\".",
"ERROR: ~/wip/package/file3.mk:1: Expected \"# $"+"NetBSD$\".",
"ERROR: ~/wip/package/file4.mk:1: Expected \"# $"+"NetBSD$\".",
"ERROR: ~/wip/package/file5.mk:1: Expected \"# $"+"NetBSD$\".")
G.Logger.Opts.Autofix = true
G.Check(t.File("wip/package"))
t.CheckOutputLines(
"AUTOFIX: ~/wip/package/file1.mk:1: Replacing \"# $"+"NetBSD: dummy $\" with \"# $"+"NetBSD$\".",
"AUTOFIX: ~/wip/package/file3.mk:1: Inserting a line \"# $"+"NetBSD$\" above this line.",
"AUTOFIX: ~/wip/package/file4.mk:1: Inserting a line \"# $"+"NetBSD$\" above this line.",
"AUTOFIX: ~/wip/package/file5.mk:1: Inserting a line \"# $"+"NetBSD$\" above this line.")
// In production mode, this error is disabled since it doesn't provide
// enough benefit compared to the work it would produce.
//
// To make it useful, the majority of pkgsrc-wip packages would first
// have to follow this style.
G.Testing = false
G.Check(t.File("wip/package"))
t.CheckOutputEmpty()
}
|