summaryrefslogtreecommitdiff
path: root/pkgtools/pkglint/files/toplevel_test.go
blob: 33278d30ad3d7b0bc083aecaf1b8455f4482ec57 (plain)
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
154
155
156
157
package pkglint

import "gopkg.in/check.v1"

func (s *Suite) Test_CheckdirToplevel(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"SUBDIR+= x11",
		"SUBDIR+=\tarchivers",
		"SUBDIR+=\tccc",
		"SUBDIR+=\tccc",
		"#SUBDIR+=\tignoreme",
		"SUBDIR+=\tnonexisting", // This doesn't happen in practice, therefore no warning.
		"SUBDIR+=\tbbb",
		"SUBDIR+=\t${SITE_SPECIFIC_PKGS}")
	t.CreateFileLines("archivers/Makefile")
	t.CreateFileLines("bbb/Makefile")
	t.CreateFileLines("ccc/Makefile")
	t.CreateFileLines("x11/Makefile")
	t.SetUpVartypes()

	CheckdirToplevel(t.File("."))

	t.CheckOutputLines(
		"ERROR: ~/Makefile:6: Each subdir must only appear once.",
		"WARN: ~/Makefile:7: \"ignoreme\" commented out without giving a reason.",
		"WARN: ~/Makefile:9: bbb should come before ccc.",

		// This warning is at the very end because mklines.Check() is called at the end.
		// Ideally it would be at the same place as the other warning from Makefile:3.
		"NOTE: ~/Makefile:3: This variable value should be aligned "+
			"with tabs, not spaces, to column 17 instead of 10.")
}

func (s *Suite) Test_CheckdirToplevel__recursive(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("mk/misc/category.mk",
		MkCvsID)
	t.SetUpPackage("category/package",
		"UNKNOWN=\tvalue")
	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"SUBDIR+=\tcategory")
	t.CreateFileLines("category/Makefile",
		MkCvsID,
		"",
		"COMMENT=\tThe category",
		"",
		"SUBDIR+=\tpackage",
		"",
		".include \"../mk/misc/category.mk\"")

	t.Main("-Wall", "-r", ".")

	t.CheckOutputLines(
		"WARN: ~/category/package/Makefile:20: UNKNOWN is defined but not used.",
		"1 warning found.",
		t.Shquote("(Run \"pkglint -e -Wall -r %s\" to show explanations.)", "."))
}

func (s *Suite) Test_CheckdirToplevel__recursive_inter_package(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("mk/misc/category.mk",
		MkCvsID)
	t.SetUpPackage("category/package",
		"UNKNOWN=\tvalue")
	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"SUBDIR+=\tcategory")
	t.CreateFileLines("category/Makefile",
		MkCvsID,
		"",
		"COMMENT=\tThe category",
		"",
		"SUBDIR+=\tpackage",
		"",
		".include \"../mk/misc/category.mk\"")

	t.Main("-Wall", "-Call", "-r", ".")

	t.CheckOutputLines(
		"WARN: ~/category/package/Makefile:20: UNKNOWN is defined but not used.",
		"WARN: ~/licenses/gnu-gpl-v2: This license seems to be unused.",
		"2 warnings found.",
		t.Shquote("(Run \"pkglint -e -Wall -Call -r %s\" to show explanations.)", "."))
}

func (s *Suite) Test_CheckdirToplevel__indentation(c *check.C) {
	t := s.Init(c)

	t.SetUpPkgsrc()
	t.CreateFileLines("category1/Makefile")
	t.CreateFileLines("category2/Makefile")
	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"SUBDIR+=\tcategory1",
		"SUBDIR+=\t\tcategory2")

	t.Main("-Wall", ".")

	t.CheckOutputLines(
		"NOTE: ~/Makefile:4: This variable value should be aligned to column 17 instead of 25.",
		"Looks fine.",
		t.Shquote("(Run \"pkglint -e -Wall %s\" to show explanations.)", "."),
		t.Shquote("(Run \"pkglint -fs -Wall %s\" to show what can be fixed automatically.)", "."),
		t.Shquote("(Run \"pkglint -F -Wall %s\" to automatically fix some issues.)", "."))
}

func (s *Suite) Test_Toplevel_checkSubdir__sorting_x11(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"SUBDIR+=\tx11",
		"SUBDIR+=\tsysutils",
		"SUBDIR+=\tarchivers")
	t.CreateFileLines("archivers/Makefile")
	t.CreateFileLines("sysutils/Makefile")
	t.CreateFileLines("x11/Makefile")
	t.SetUpVartypes()

	CheckdirToplevel(t.File("."))

	t.CheckOutputLines(
		"WARN: ~/Makefile:4: sysutils should come before x11.",
		"WARN: ~/Makefile:5: archivers should come before sysutils.")
}

func (s *Suite) Test_Toplevel_checkSubdir__commented_without_reason(c *check.C) {
	t := s.Init(c)

	t.CreateFileLines("Makefile",
		MkCvsID,
		"",
		"#SUBDIR+=\taaa",
		"#SUBDIR+=\tbbb\t#",
		"#SUBDIR+=\tccc\t# reason")
	t.CreateFileLines("aaa/Makefile")
	t.CreateFileLines("bbb/Makefile")
	t.CreateFileLines("ccc/Makefile")
	t.SetUpVartypes()

	CheckdirToplevel(t.File("."))

	t.CheckOutputLines(
		"WARN: ~/Makefile:3: \"aaa\" commented out without giving a reason.",
		"WARN: ~/Makefile:4: \"bbb\" commented out without giving a reason.")
}