summaryrefslogtreecommitdiff
path: root/pkgtools/pkglint/files/substcontext_test.go
blob: 1ea900d0792e7e1d2e02cc2fa8a2d4ee65cf8376 (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
package main

import (
	check "gopkg.in/check.v1"
)

func (s *Suite) TestSubstContext_Incomplete(c *check.C) {
	G.opts.WarnExtra = true
	line := NewLine("Makefile", "1", "dummy", nil)
	ctx := new(SubstContext)

	ctx.Varassign(line, "PKGNAME", "=", "pkgname-1.0")

	c.Check(ctx.id, equals, "")

	ctx.Varassign(line, "SUBST_CLASSES", "+=", "interp")

	c.Check(ctx.id, equals, "interp")

	ctx.Varassign(line, "SUBST_FILES.interp", "=", "Makefile")

	c.Check(ctx.IsComplete(), equals, false)

	ctx.Varassign(line, "SUBST_SED.interp", "=", "s,@PREFIX@,${PREFIX},g")

	c.Check(ctx.IsComplete(), equals, false)

	ctx.Finish(line)

	c.Check(s.Output(), equals, "WARN: Makefile:1: Incomplete SUBST block: SUBST_STAGE.interp missing.\n")
}

func (s *Suite) TestSubstContext_Complete(c *check.C) {
	G.opts.WarnExtra = true
	line := NewLine("Makefile", "1", "dummy", nil)
	ctx := new(SubstContext)

	ctx.Varassign(line, "PKGNAME", "=", "pkgname-1.0")
	ctx.Varassign(line, "SUBST_CLASSES", "+=", "p")
	ctx.Varassign(line, "SUBST_FILES.p", "=", "Makefile")
	ctx.Varassign(line, "SUBST_SED.p", "=", "s,@PREFIX@,${PREFIX},g")

	c.Check(ctx.IsComplete(), equals, false)

	ctx.Varassign(line, "SUBST_STAGE.p", "=", "post-configure")

	c.Check(ctx.IsComplete(), equals, true)

	ctx.Finish(line)

	c.Check(s.Output(), equals, "")
}

func (s *Suite) TestSubstContext_NoClass(c *check.C) {
	s.UseCommandLine(c, "-Wextra")
	line := NewLine("Makefile", "1", "dummy", nil)
	ctx := new(SubstContext)

	ctx.Varassign(line, "UNRELATED", "=", "anything")
	ctx.Varassign(line, "SUBST_FILES.repl", "+=", "Makefile.in")
	ctx.Varassign(line, "SUBST_SED.repl", "+=", "-e s,from,to,g")
	ctx.Finish(line)

	c.Check(s.Output(), equals, ""+
		"WARN: Makefile:1: SUBST_CLASSES should come before the definition of \"SUBST_FILES.repl\".\n"+
		"WARN: Makefile:1: Incomplete SUBST block: SUBST_STAGE.repl missing.\n")
}