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

import "gopkg.in/check.v1"

func (s *Suite) Test_ChecklinesDistinfo(c *check.C) {
	s.Init(c)
	s.CreateTmpFile("patches/patch-aa", ""+
		"$"+"NetBSD$ line is ignored\n"+
		"patch contents\n")
	s.CreateTmpFile("patches/patch-ab", ""+
		"patch contents\n")
	G.CurrentDir = s.tmpdir

	ChecklinesDistinfo(T.NewLines("distinfo",
		"should be the RCS ID",
		"should be empty",
		"MD5 (distfile.tar.gz) = 12345678901234567890123456789012",
		"SHA1 (distfile.tar.gz) = 1234567890123456789012345678901234567890",
		"SHA1 (patch-aa) = 6b98dd609f85a9eb9c4c1e4e7055a6aaa62b7cc7",
		"SHA1 (patch-ab) = 6b98dd609f85a9eb9c4c1e4e7055a6aaa62b7cc7",
		"SHA1 (patch-nonexistent) = 1234"))

	s.CheckOutputLines(
		"ERROR: distinfo:1: Expected \"$"+"NetBSD$\".",
		"NOTE: distinfo:2: Empty line expected.",
		"ERROR: distinfo:5: Expected SHA1, RMD160, SHA512, Size checksums for \"distfile.tar.gz\", got MD5, SHA1.",
		"WARN: distinfo:7: Patch file \"patch-nonexistent\" does not exist in directory \"patches\".")
}

func (s *Suite) Test_ChecklinesDistinfo_global_hash_mismatch(c *check.C) {
	s.Init(c)
	otherLine := T.NewLine("other/distinfo", 7, "dummy")
	G.Hash = make(map[string]*Hash)
	G.Hash["SHA512:pkgname-1.0.tar.gz"] = &Hash{"asdfasdf", otherLine}

	ChecklinesDistinfo(T.NewLines("distinfo",
		"$"+"NetBSD$",
		"",
		"SHA512 (pkgname-1.0.tar.gz) = 12341234"))

	s.CheckOutputLines(
		"ERROR: distinfo:3: The hash SHA512 for pkgname-1.0.tar.gz is 12341234, which differs from asdfasdf in other/distinfo:7.",
		"ERROR: distinfo:EOF: Expected SHA1, RMD160, SHA512, Size checksums for \"pkgname-1.0.tar.gz\", got SHA512.")
}

func (s *Suite) Test_ChecklinesDistinfo_uncommitted_patch(c *check.C) {
	s.Init(c)
	s.CreateTmpFile("patches/patch-aa", ""+
		"$"+"NetBSD$\n"+
		"\n"+
		"--- oldfile\n"+
		"+++ newfile\n"+
		"@@ -1,1 +1,1 @@\n"+
		"-old\n"+
		"+new\n")
	s.CreateTmpFile("CVS/Entries",
		"/distinfo/...\n")
	G.CurrentDir = s.tmpdir

	ChecklinesDistinfo(T.NewLines(s.tmpdir+"/distinfo",
		"$"+"NetBSD$",
		"",
		"SHA1 (patch-aa) = 5ad1fb9b3c328fff5caa1a23e8f330e707dd50c0"))

	s.CheckOutputLines(
		"WARN: ~/distinfo:3: patches/patch-aa is registered in distinfo but not added to CVS.")
}

func (s *Suite) Test_ChecklinesDistinfo_unrecorded_patches(c *check.C) {
	s.Init(c)
	s.CreateTmpFile("patches/CVS/Entries", "")
	s.CreateTmpFile("patches/patch-aa", "")
	s.CreateTmpFile("patches/patch-src-Makefile", "")
	G.CurrentDir = s.tmpdir

	ChecklinesDistinfo(T.NewLines(s.tmpdir+"/distinfo",
		"$"+"NetBSD$",
		"",
		"SHA1 (distfile.tar.gz) = ...",
		"RMD160 (distfile.tar.gz) = ...",
		"SHA512 (distfile.tar.gz) = ...",
		"Size (distfile.tar.gz) = 1024 bytes"))

	s.CheckOutputLines(
		"ERROR: ~/distinfo: patch \"patches/patch-aa\" is not recorded. Run \""+confMake+" makepatchsum\".",
		"ERROR: ~/distinfo: patch \"patches/patch-src-Makefile\" is not recorded. Run \""+confMake+" makepatchsum\".")
}

func (s *Suite) Test_ChecklinesDistinfo_manual_patches(c *check.C) {
	s.Init(c)
	s.CreateTmpFile("patches/manual-libtool.m4", "")
	G.CurrentDir = s.tmpdir

	ChecklinesDistinfo(T.NewLines(s.tmpdir+"/distinfo",
		"$"+"NetBSD$",
		"",
		"SHA1 (patch-aa) = ..."))

	s.CheckOutputLines(
		"WARN: ~/distinfo:3: Patch file \"patch-aa\" does not exist in directory \"patches\".")
}