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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
package pkglint
import "gopkg.in/check.v1"
func (s *Suite) Test_CheckLinesDistinfo__parse_errors(c *check.C) {
t := s.Init(c)
t.Chdir("category/package")
t.CreateFileLines("patches/patch-aa",
CvsID+" line is ignored for computing the SHA1 hash",
"patch contents")
t.CreateFileLines("patches/patch-ab",
"patch contents")
lines := t.SetUpFileLines("distinfo",
"should be the CVS ID",
"should be empty",
"MD5 (distfile-1.0.tar.gz) = 12345678901234567890123456789012",
"SHA1 (distfile-1.0.tar.gz) = 1234567890123456789012345678901234567890",
"SHA1 (patch-aa) = 6b98dd609f85a9eb9c4c1e4e7055a6aaa62b7cc7",
"Size (patch-aa) = 104",
"SHA1 (patch-ab) = 6b98dd609f85a9eb9c4c1e4e7055a6aaa62b7cc7",
"Another invalid line",
"SHA1 (patch-nonexistent) = 1234")
pkg := NewPackage(".")
CheckLinesDistinfo(pkg, lines)
t.CheckOutputLines(
"ERROR: distinfo:1: Expected \"$"+"NetBSD$\".",
"NOTE: distinfo:1: Empty line expected above this line.",
"ERROR: distinfo:1: Invalid line: should be the CVS ID",
"ERROR: distinfo:2: Invalid line: should be empty",
"ERROR: distinfo:8: Invalid line: Another invalid line",
"ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got MD5, SHA1.",
"ERROR: distinfo:5: Expected SHA1 hash for patch-aa, got SHA1, Size.",
"WARN: distinfo:9: Patch file \"patch-nonexistent\" does not exist in directory \"patches\".")
}
func (s *Suite) Test_CheckLinesDistinfo__DISTINFO_FILE(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package",
"DISTINFO_FILE=\t${.CURDIR}/../../category/package/distinfo",
"PATCHDIR=\t${.CURDIR}/../../category/package/patches")
t.Chdir("category/package")
t.CreateFileDummyPatch("patches/patch-dummy_txt")
t.CreateFileLines("patches/CVS/Entries",
"/other/1.1/modified//")
t.CreateFileLines("distinfo",
CvsID,
"",
"SHA1 (patch-dummy_txt) = 2388e84518db54eaa827c68f191d9a87e90f7f00")
t.CreateFileLines("CVS/Entries",
"/distinfo/1.1/modified//")
t.FinishSetUp()
G.Check(".")
t.CheckOutputLines(
"WARN: distinfo:3: ../../category/package/patches/patch-dummy_txt " +
"is registered in distinfo but not added to CVS.")
}
func (s *Suite) Test_distinfoLinesChecker_parse__trailing_empty_line(c *check.C) {
t := s.Init(c)
lines := t.SetUpFileLines("distinfo",
CvsID,
"")
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"NOTE: ~/distinfo:2: Trailing empty lines.")
}
func (s *Suite) Test_distinfoLinesChecker_parse__empty_file(c *check.C) {
t := s.Init(c)
lines := t.SetUpFileLines("distinfo",
CvsID)
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"NOTE: ~/distinfo:1: Empty line expected below this line.")
}
func (s *Suite) Test_distinfoLinesChecker_parse__commented_first_line(c *check.C) {
t := s.Init(c)
// This mismatch can happen for inexperienced pkgsrc users.
// It's not easy to keep all these different file types apart.
lines := t.SetUpFileLines("distinfo",
PlistCvsID)
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"ERROR: ~/distinfo:1: Expected \""+CvsID+"\".",
"NOTE: ~/distinfo:1: Empty line expected above this line.",
"ERROR: ~/distinfo:1: Invalid line: "+PlistCvsID)
}
func (s *Suite) Test_distinfoLinesChecker_parse__completely_empty_file(c *check.C) {
t := s.Init(c)
lines := t.SetUpFileLines("distinfo",
nil...)
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"NOTE: ~/distinfo:EOF: Empty line expected above this line.")
}
// When the distinfo file and the patches are placed in the same package,
// their diagnostics use short relative paths.
func (s *Suite) Test_distinfoLinesChecker_check__distinfo_and_patches_in_separate_directory(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package",
"DISTINFO_FILE=\t../../other/common/distinfo",
"PATCHDIR=\t../../other/common/patches")
t.Remove("category/package/distinfo")
t.CreateFileLines("other/common/patches/CVS/Entries")
t.CreateFileDummyPatch("other/common/patches/patch-aa")
t.CreateFileDummyPatch("other/common/patches/patch-only-in-patches")
t.SetUpFileLines("other/common/distinfo",
CvsID,
"",
"SHA1 (patch-aa) = ...",
"SHA1 (patch-only-in-distinfo) = ...")
t.Chdir("category/package")
t.FinishSetUp()
G.checkdirPackage(".")
t.CheckOutputLines(
"ERROR: ../../other/common/distinfo:3: SHA1 hash of patches/patch-aa differs "+
"(distinfo has ..., patch file has 9a93207561abfef7e7550598c5a08f2c3226995b).",
"WARN: ../../other/common/distinfo:4: Patch file \"patch-only-in-distinfo\" "+
"does not exist in directory \"patches\".",
"ERROR: ../../other/common/distinfo: Patch \"patches/patch-only-in-patches\" "+
"is not recorded. Run \""+confMake+" makepatchsum\".")
}
func (s *Suite) Test_distinfoLinesChecker_check__manual_patches(c *check.C) {
t := s.Init(c)
t.Chdir("category/package")
t.CreateFileLines("patches/manual-libtool.m4")
lines := t.SetUpFileLines("distinfo",
CvsID,
"",
"SHA1 (patch-aa) = ...")
CheckLinesDistinfo(nil, lines)
// When a distinfo file is checked on its own, without belonging to a package,
// the PATCHDIR is not known and therefore no diagnostics are logged.
t.CheckOutputEmpty()
pkg := NewPackage(".")
CheckLinesDistinfo(pkg, lines)
// When a distinfo file is checked in the context of a package,
// the PATCHDIR is known, therefore the check is active.
t.CheckOutputLines(
"WARN: distinfo:3: Patch file \"patch-aa\" does not exist in directory \"patches\".")
}
// PHP modules that are not PECL use the distinfo file from lang/php* but
// their own patches directory. Therefore the distinfo file refers to missing
// patches. Since this strange situation is caused by the pkgsrc
// infrastructure, there is nothing a package author can do.
//
// XXX: Re-check the documentation for this test.
func (s *Suite) Test_distinfoLinesChecker_check__missing_php_patches(c *check.C) {
t := s.Init(c)
t.SetUpPkgsrc()
t.CreateFileLines("licenses/unknown-license")
t.CreateFileLines("lang/php/ext.mk",
MkCvsID,
"",
"PHPEXT_MK= # defined",
"PHPPKGSRCDIR= ../../lang/php72",
"LICENSE?= unknown-license",
"COMMENT?= Some PHP package",
"GENERATE_PLIST+=# none",
"",
".if !defined(PECL_VERSION)",
"DISTINFO_FILE= ${.CURDIR}/${PHPPKGSRCDIR}/distinfo",
".endif",
".if defined(USE_PHP_EXT_PATCHES)",
"PATCHDIR= ${.CURDIR}/${PHPPKGSRCDIR}/patches",
".endif")
t.CreateFileDummyPatch("lang/php72/patches/patch-php72")
t.CreateFileLines("lang/php72/distinfo",
CvsID,
"",
"SHA1 (patch-php72) = 9bd4352244636c587db21abfbb99bb34ded1e333")
t.CreateFileLines("archivers/php-bz2/Makefile",
MkCvsID,
"",
"USE_PHP_EXT_PATCHES=\tyes",
"",
".include \"../../lang/php/ext.mk\"",
".include \"../../mk/bsd.pkg.mk\"")
t.CreateFileLines("archivers/php-bz2/DESCR",
"Description")
t.FinishSetUp()
G.Check(t.File("archivers/php-bz2"))
t.CheckOutputEmpty()
t.CreateFileLines("archivers/php-zlib/Makefile",
MkCvsID,
"",
".include \"../../lang/php/ext.mk\"",
".include \"../../mk/bsd.pkg.mk\"")
t.CreateFileLines("archivers/php-zlib/DESCR",
"Description")
G.Check(t.File("archivers/php-zlib"))
t.CheckOutputEmpty()
}
func (s *Suite) Test_distinfoLinesChecker_checkFilename(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"SHA1 (ok-1.0.tar.gz) = 1234",
"RMD160 (ok-1.0.tar.gz) = 1234",
"SHA512 (ok-1.0.tar.gz) = 1234",
"Size (ok-1.0.tar.gz) = 1234",
"SHA1 (not-ok.tar.gz) = 1234",
"RMD160 (not-ok.tar.gz) = 1234",
"SHA512 (not-ok.tar.gz) = 1234",
"Size (not-ok.tar.gz) = 1234",
"SHA1 (non-versioned/not-ok.tar.gz) = 1234",
"RMD160 (non-versioned/not-ok.tar.gz) = 1234",
"SHA512 (non-versioned/not-ok.tar.gz) = 1234",
"Size (non-versioned/not-ok.tar.gz) = 1234",
"SHA1 (versioned-1/ok.tar.gz) = 1234",
"RMD160 (versioned-1/ok.tar.gz) = 1234",
"SHA512 (versioned-1/ok.tar.gz) = 1234",
"Size (versioned-1/ok.tar.gz) = 1234")
t.Chdir("category/package")
t.FinishSetUp()
G.Check(".")
t.CheckOutputLines(
"WARN: distinfo:7: Distfiles without version number "+
"should be placed in a versioned DIST_SUBDIR.",
"WARN: distinfo:11: Distfiles without version number "+
"should be placed in a versioned DIST_SUBDIR.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__nonexistent_distfile_called_patch(c *check.C) {
t := s.Init(c)
t.Chdir("category/package")
lines := t.SetUpFileLines("distinfo",
CvsID,
"",
"MD5 (patch-5.3.tar.gz) = 12345678901234567890123456789012",
"SHA1 (patch-5.3.tar.gz) = 1234567890123456789012345678901234567890")
pkg := NewPackage(".")
CheckLinesDistinfo(pkg, lines)
// Even though the filename starts with "patch-" and therefore looks like
// a patch, it is a normal distfile because it has other hash algorithms
// than exactly SHA1.
t.CheckOutputLines(
"ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums " +
"for \"patch-5.3.tar.gz\", got MD5, SHA1.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__wrong_distfile_algorithms(c *check.C) {
t := s.Init(c)
t.Chdir("category/package")
lines := t.SetUpFileLines("distinfo",
CvsID,
"",
"MD5 (distfile.tar.gz) = 12345678901234567890123456789012",
"SHA1 (distfile.tar.gz) = 1234567890123456789012345678901234567890")
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums " +
"for \"distfile.tar.gz\", got MD5, SHA1.")
}
// This case only happens when a distinfo file is checked on its own,
// without any reference to a pkgsrc package. Additionally the distfile
// must start with the patch- prefix and the algorithms must be wrong
// for both distfile or patch.
//
// This test only demonstrates the edge case.
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__ambiguous_distfile(c *check.C) {
t := s.Init(c)
t.SetUpCommandLine("--explain")
t.Chdir("category/package")
lines := t.SetUpFileLines("distinfo",
CvsID,
"",
"MD5 (patch-4.2.tar.gz) = 12345678901234567890123456789012")
CheckLinesDistinfo(nil, lines)
t.CheckOutputLines(
"ERROR: distinfo:3: Wrong checksum algorithms MD5 for patch-4.2.tar.gz.",
"",
"\tDistfiles that are downloaded from external sources must have the",
"\tchecksum algorithms SHA1, RMD160, SHA512, Size.",
"",
"\tPatch files from pkgsrc must have only the SHA1 hash.",
"")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__wrong_patch_algorithms(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.Chdir("category/package")
t.CreateFileDummyPatch("patches/patch-aa")
t.SetUpFileLines("distinfo",
CvsID,
"",
"MD5 (patch-aa) = 12345678901234567890123456789012",
"SHA1 (patch-aa) = 1234567890123456789012345678901234567890")
t.FinishSetUp()
G.Check(".")
t.CheckOutputLines(
"ERROR: distinfo:3: Expected SHA1 hash for patch-aa, got MD5, SHA1.",
"ERROR: distinfo:4: SHA1 hash of patches/patch-aa differs "+
"(distinfo has 1234567890123456789012345678901234567890, "+
"patch file has 9a93207561abfef7e7550598c5a08f2c3226995b).")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__missing_patch_with_distfile_checksums(c *check.C) {
t := s.Init(c)
lines := t.SetUpFileLines("distinfo",
CvsID,
"",
"SHA1 (patch-aa) = ...",
"RMD160 (patch-aa) = ...",
"SHA512 (patch-aa) = ...",
"Size (patch-aa) = ... bytes")
CheckLinesDistinfo(nil, lines)
// The file name certainly looks like a pkgsrc patch, but there
// is no corresponding file in the file system, and there is no
// current package to correctly determine the PATCHDIR. Therefore
// pkglint doesn't know whether this is a distfile or a missing
// patch file and doesn't warn at all.
t.CheckOutputEmpty()
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__existing_patch_with_distfile_checksums(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"SHA1 (patch-aa) = ...",
"RMD160 (patch-aa) = ...",
"SHA512 (patch-aa) = ...",
"Size (patch-aa) = ... bytes")
t.CreateFileDummyPatch("category/package/patches/patch-aa")
t.FinishSetUp()
G.Check(t.File("category/package"))
// Even though the checksums in the distinfo file look as if they
// refer to a distfile, there is a patch file in the file system
// that matches the distinfo lines. When checking a pkgsrc package
// (as opposed to checking a distinfo file on its own), this means
// that the distinfo lines clearly refer to that patch file and not
// to a distfile.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1 hash for patch-aa, got SHA1, RMD160, SHA512, Size.",
"ERROR: ~/category/package/distinfo:3: "+
"SHA1 hash of patches/patch-aa differs (distinfo has ..., "+
"patch file has 9a93207561abfef7e7550598c5a08f2c3226995b).")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__missing_patch_with_wrong_algorithms(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.SetUpFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (patch-aa) = ...")
t.FinishSetUp()
G.Check(t.File("category/package"))
// Patch files usually have the SHA1 hash or none at all if they are fresh.
// In all other cases pkglint assumes that the file is a distfile,
// therefore it requires the usual distfile checksum algorithms here.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: " +
"Expected SHA1, RMD160, SHA512, Size checksums for \"patch-aa\", got RMD160.")
}
// When there is at least one correct hash for a distfile and the distfile
// has already been downloaded to pkgsrc/distfiles, which is the standard
// distfiles location, running pkglint --autofix adds the missing hashes.
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_hashes_for_existing_distfile(c *check.C) {
t := s.Init(c)
t.SetUpCommandLine("-Wall", "--explain")
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"Size (package-1.0.txt) = 13 bytes",
"CRC32 (package-1.0.txt) = asdf")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
// This run is only used to verify that the RMD160 hash is correct, and if
// it should ever differ, the correct hash will appear in an error message.
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got RMD160, Size, CRC32.",
"ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.",
"ERROR: ~/category/package/distinfo:3: Missing SHA512 hash for package-1.0.txt.")
t.SetUpCommandLine("-Wall", "--autofix", "--show-autofix", "--source")
G.Check(t.File("category/package"))
// Since the file exists in the distfiles directory, pkglint checks the
// hash right away. It also adds the missing hashes since this file is
// not a patch file.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.",
"AUTOFIX: ~/category/package/distinfo:3: "+
"Inserting a line \"SHA1 (package-1.0.txt) "+
"= cd50d19784897085a8d0e3e413f8612b097c03f1\" "+
"above this line.",
"+\tSHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1",
">\tRMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"",
"ERROR: ~/category/package/distinfo:3: Missing SHA512 hash for package-1.0.txt.",
"AUTOFIX: ~/category/package/distinfo:3: "+
"Inserting a line \"SHA512 (package-1.0.txt) "+
"= f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f"+
"268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c\" below this line.",
"+\tSHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1",
">\tRMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"+\tSHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f"+
"268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c")
t.SetUpCommandLine("-Wall")
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: " +
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " +
"got SHA1, RMD160, SHA512, Size, CRC32.")
}
// When some of the hashes for a distfile are missing, pkglint can calculate
// them. In order to do this, the distfile needs to be downloaded first. This
// often requires manual work, otherwise it would have been done already.
//
// Since the distfile has not been downloaded in this test case, pkglint can
// only explain how to download the distfile.
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_hashes_for_nonexistent_distfile(c *check.C) {
t := s.Init(c)
t.SetUpCommandLine("-Wall", "--explain")
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"Size (package-1.0.txt) = 13 bytes",
"CRC32 (package-1.0.txt) = asdf")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got RMD160, Size, CRC32.",
"",
"\tTo add the missing lines to the distinfo file, run",
"\t\t"+confMake+" distinfo",
"\tfor each variant of the package until all distfiles are downloaded",
"\tto ${PKGSRCDIR}/distfiles.",
"",
"\tThe variants are typically selected by setting EMUL_PLATFORM or",
"\tsimilar variables in the command line.",
"",
"\tAfter that, run \"cvs update -C distinfo\" to revert the distinfo file",
"\tto the previous state, since the above commands have removed some of",
"\tthe entries.",
"",
"\tAfter downloading all possible distfiles, run \"pkglint --autofix\",",
"\twhich will find the downloaded distfiles and add the missing hashes",
"\tto the distinfo file.",
"")
t.SetUpCommandLine("-Wall", "--autofix", "--show-autofix", "--source")
G.Check(t.File("category/package"))
// Since the distfile does not exist, pkglint cannot fix anything.
t.CheckOutputEmpty()
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__wrong_distfile_hash(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (package-1.0.txt) = 1234wrongHash1234")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got RMD160.",
"ERROR: ~/category/package/distinfo:3: "+
"The RMD160 checksum for \"package-1.0.txt\" is 1234wrongHash1234 in distinfo, "+
"1a88147a0344137404c63f3b695366eab869a98a in ../../distfiles/package-1.0.txt.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__no_usual_algorithm(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"MD5 (package-1.0.txt) = 1234wrongHash1234")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: " +
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " +
"got MD5.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__top_algorithms_missing(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"SHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7"+
"d41f0974d3e3122f268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c",
"Size (package-1.0.txt) = 13 bytes")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got SHA512, Size.",
"ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.",
"ERROR: ~/category/package/distinfo:3: Missing RMD160 hash for package-1.0.txt.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__bottom_algorithms_missing(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"SHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1",
"RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got SHA1, RMD160.",
"ERROR: ~/category/package/distinfo:4: Missing SHA512 hash for package-1.0.txt.",
"ERROR: ~/category/package/distinfo:4: Missing Size hash for package-1.0.txt.")
t.SetUpCommandLine("-Wall", "--autofix")
G.Check(t.File("category/package"))
t.CheckOutputLines(
"AUTOFIX: ~/category/package/distinfo:4: "+
"Inserting a line \"SHA512 (package-1.0.txt) = f65f341b35981fda842b"+
"09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f268fc79d5a4af66358f513"+
"3885cd1c165c916f80ab25e5d8d95db46f803c782c\" below this line.",
"AUTOFIX: ~/category/package/distinfo:4: "+
"Inserting a line \"Size (package-1.0.txt) = 13 bytes\" below this line.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__algorithms_in_wrong_order(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"SHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1",
"Size (package-1.0.txt) = 13 bytes",
"SHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7"+
"d41f0974d3e3122f268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
// This case doesn't happen in practice, therefore there's no autofix for it.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: " +
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " +
"got RMD160, SHA1, Size, SHA512.")
}
func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__some_algorithms_in_wrong_order(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a",
"Size (package-1.0.txt) = 13 bytes",
"SHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7"+
"d41f0974d3e3122f268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c")
t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()
G.Check(t.File("category/package"))
// This case doesn't happen in practice, therefore there's no autofix for it.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+
"got RMD160, Size, SHA512.",
"ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.")
}
func (s *Suite) Test_distinfoLinesChecker_checkUnrecordedPatches(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.Chdir("category/package")
t.CreateFileLines("patches/CVS/Entries")
t.CreateFileDummyPatch("patches/patch-aa")
t.CreateFileDummyPatch("patches/patch-src-Makefile")
t.SetUpFileLines("distinfo",
CvsID,
"",
"SHA1 (distfile.tar.gz) = ...",
"RMD160 (distfile.tar.gz) = ...",
"SHA512 (distfile.tar.gz) = ...",
"Size (distfile.tar.gz) = 1024 bytes")
t.FinishSetUp()
G.checkdirPackage(".")
t.CheckOutputLines(
"WARN: distinfo:3: Distfiles without version number should be placed in a versioned DIST_SUBDIR.",
"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\".")
}
// When checking the complete pkgsrc tree, pkglint has all information it needs
// to check whether different packages use the same distfile but require
// different hashes for it.
//
// In such a case, typically one of the packages should put its distfiles into
// a DIST_SUBDIR.
func (s *Suite) Test_distinfoLinesChecker_checkGlobalDistfileMismatch(c *check.C) {
t := s.Init(c)
t.SetUpPkgsrc()
t.SetUpPackage("category/package1")
t.SetUpPackage("category/package2")
t.CreateFileLines("category/package1/distinfo",
CvsID,
"",
"SHA512 (distfile-1.0.tar.gz) = 1234567811111111",
"SHA512 (distfile-1.1.tar.gz) = 1111111111111111",
"SHA512 (patch-4.2.tar.gz) = 1234567812345678")
t.CreateFileLines("category/package2/distinfo",
CvsID,
"",
"SHA512 (distfile-1.0.tar.gz) = 1234567822222222",
"SHA512 (distfile-1.1.tar.gz) = 1111111111111111",
"SHA512 (encoding-error.tar.gz) = 12345678abcdefgh")
t.CreateFileLines("Makefile",
MkCvsID,
"",
"COMMENT=\tThis is pkgsrc",
"",
"SUBDIR+=\tcategory")
t.CreateFileLines("category/Makefile",
MkCvsID,
"",
"COMMENT=\tUseful programs",
"",
"SUBDIR+=\tpackage1",
"SUBDIR+=\tpackage2",
"",
".include \"../mk/misc/category.mk\"")
t.Main("-r", "-Wall", "-Call", ".")
t.CheckOutputLines(
"ERROR: ~/category/package1/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.",
"ERROR: ~/category/package1/distinfo:4: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.",
"ERROR: ~/category/package1/distinfo:5: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"patch-4.2.tar.gz\", got SHA512.",
"ERROR: ~/category/package2/distinfo:3: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.",
"ERROR: ~/category/package2/distinfo:3: "+
"The SHA512 hash for distfile-1.0.tar.gz is 1234567822222222, "+
"which conflicts with 1234567811111111 in ../../category/package1/distinfo:3.",
"ERROR: ~/category/package2/distinfo:4: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.",
"ERROR: ~/category/package2/distinfo:5: "+
"Expected SHA1, RMD160, SHA512, Size checksums for \"encoding-error.tar.gz\", got SHA512.",
"ERROR: ~/category/package2/distinfo:5: "+
"The SHA512 hash for encoding-error.tar.gz contains a non-hex character.",
"WARN: ~/licenses/gnu-gpl-v2: This license seems to be unused.",
"8 errors and 1 warning found.",
t.Shquote("(Run \"pkglint -e -r -Wall -Call %s\" to show explanations.)", "."))
// Ensure that hex.DecodeString does not waste memory here.
t.CheckEquals(len(G.InterPackage.hashes["SHA512:distfile-1.0.tar.gz"].hash), 8)
t.CheckEquals(cap(G.InterPackage.hashes["SHA512:distfile-1.0.tar.gz"].hash), 8)
}
func (s *Suite) Test_distinfoLinesChecker_checkUncommittedPatch__bad(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.Chdir("category/package")
t.CreateFileDummyPatch("patches/patch-aa")
t.CreateFileLines("CVS/Entries",
"/distinfo//modified//")
t.SetUpFileLines("distinfo",
CvsID,
"",
"SHA1 (patch-aa) = 9a93207561abfef7e7550598c5a08f2c3226995b")
t.FinishSetUp()
G.checkdirPackage(".")
t.CheckOutputLines(
"WARN: distinfo:3: patches/patch-aa is registered in distinfo but not added to CVS.")
}
func (s *Suite) Test_distinfoLinesChecker_checkUncommittedPatch__good(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.Chdir("category/package")
t.CreateFileDummyPatch("patches/patch-aa")
t.CreateFileLines("CVS/Entries",
"/distinfo//modified//")
t.CreateFileLines("patches/CVS/Entries",
"/patch-aa//modified//")
t.SetUpFileLines("distinfo",
CvsID,
"",
"SHA1 (patch-aa) = 9a93207561abfef7e7550598c5a08f2c3226995b")
t.FinishSetUp()
G.checkdirPackage(".")
t.CheckOutputEmpty()
}
// The distinfo file and the patches are usually placed in the package
// directory. By defining PATCHDIR or DISTINFO_FILE, a package can define
// that they are somewhere else in pkgsrc.
func (s *Suite) Test_distinfoLinesChecker_checkPatchSha1__relative_path_in_distinfo(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package",
"DISTINFO_FILE=\t../../other/common/distinfo",
"PATCHDIR=\t../../devel/patches/patches")
t.Remove("category/package/distinfo")
t.CreateFileLines("devel/patches/patches/CVS/Entries")
t.CreateFileDummyPatch("devel/patches/patches/patch-aa")
t.CreateFileDummyPatch("devel/patches/patches/patch-only-in-patches")
t.SetUpFileLines("other/common/distinfo",
CvsID,
"",
"SHA1 (patch-aa) = ...",
"SHA1 (patch-only-in-distinfo) = ...")
t.Chdir("category/package")
t.FinishSetUp()
G.checkdirPackage(".")
t.CheckOutputLines(
"ERROR: ../../other/common/distinfo:3: SHA1 hash of ../../devel/patches/patches/patch-aa differs "+
"(distinfo has ..., patch file has 9a93207561abfef7e7550598c5a08f2c3226995b).",
"WARN: ../../other/common/distinfo:4: Patch file \"patch-only-in-distinfo\" "+
"does not exist in directory \"../../devel/patches/patches\".",
"ERROR: ../../other/common/distinfo: Patch \"../../devel/patches/patches/patch-only-in-patches\" "+
"is not recorded. Run \""+confMake+" makepatchsum\".")
}
func (s *Suite) Test_distinfoLinesChecker_checkPatchSha1(c *check.C) {
t := s.Init(c)
pkg := NewPackage(t.File("category/package"))
distinfoLine := t.NewLine(t.File("category/package/distinfo"), 5, "")
checker := distinfoLinesChecker{pkg, nil, "", false, nil, nil}
checker.checkPatchSha1(distinfoLine, "patch-nonexistent", "distinfo-sha1")
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:5: Patch patch-nonexistent does not exist.")
}
func (s *Suite) Test_distinfoFileInfo_filename(c *check.C) {
t := s.Init(c)
info := distinfoFileInfo{
isPatch: no,
hashes: []distinfoHash{{
line: t.NewLine("irrelevant", 12345, "irrelevant"),
filename: "distinfo",
algorithm: "irrelevant",
hash: "irrelevant",
}},
}
t.CheckEquals(info.filename(), RelPath("distinfo"))
}
func (s *Suite) Test_distinfoFileInfo_line(c *check.C) {
t := s.Init(c)
line := t.NewLine("irrelevant", 12345, "irrelevant")
info := distinfoFileInfo{
isPatch: no,
hashes: []distinfoHash{{
line: line,
filename: "irrelevant",
algorithm: "irrelevant",
hash: "irrelevant",
}},
}
t.CheckEquals(info.line(), line)
}
func (s *Suite) Test_distinfoFileInfo_algorithms(c *check.C) {
t := s.Init(c)
info := distinfoFileInfo{
isPatch: no,
hashes: []distinfoHash{
{
line: t.NewLine("irrelevant", 12345, "irrelevant"),
filename: "irrelevant",
algorithm: "SHA1",
hash: "irrelevant",
},
{
line: t.NewLine("irrelevant", 12346, "irrelevant"),
filename: "irrelevant",
algorithm: "Size",
hash: "irrelevant",
},
},
}
t.CheckEquals(info.algorithms(), "SHA1, Size")
}
// The check for versioned distfiles only makes sense if the file
// has the usual hashes for distfiles.
func (s *Suite) Test_distinfoFileInfo_hasDistfileAlgorithms__code_coverage(c *check.C) {
t := s.Init(c)
t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"other (dist-a.tar.gz) = 1234",
"RMD160 (dist-a.tar.gz) = 1234",
"SHA512 (dist-a.tar.gz) = 1234",
"Size (dist-a.tar.gz) = 1234",
"SHA1 (dist-b.tar.gz) = 1234",
"other (dist-b.tar.gz) = 1234",
"SHA512 (dist-b.tar.gz) = 1234",
"Size (dist-b.tar.gz) = 1234",
"SHA1 (dist-c.tar.gz) = 1234",
"RMD160 (dist-c.tar.gz) = 1234",
"other (dist-c.tar.gz) = 1234",
"Size (dist-c.tar.gz) = 1234",
"SHA1 (dist-d.tar.gz) = 1234",
"RMD160 (dist-d.tar.gz) = 1234",
"SHA512 (dist-d.tar.gz) = 1234",
"other (dist-d.tar.gz) = 1234")
t.Chdir("category/package")
t.FinishSetUp()
G.Check(".")
t.CheckOutputLines(
"ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums for "+
"\"dist-a.tar.gz\", got other, RMD160, SHA512, Size.",
"ERROR: distinfo:7: Expected SHA1, RMD160, SHA512, Size checksums for "+
"\"dist-b.tar.gz\", got SHA1, other, SHA512, Size.",
"ERROR: distinfo:11: Expected SHA1, RMD160, SHA512, Size checksums for "+
"\"dist-c.tar.gz\", got SHA1, RMD160, other, Size.",
"ERROR: distinfo:15: Expected SHA1, RMD160, SHA512, Size checksums for "+
"\"dist-d.tar.gz\", got SHA1, RMD160, SHA512, other.")
}
func (s *Suite) Test_computePatchSha1Hex(c *check.C) {
t := s.Init(c)
test := func(expectedHash string, lines ...string) {
fileLines := t.NewLines("irrelevant", lines...)
hash := computePatchSha1Hex(fileLines)
t.CheckEquals(hash, expectedHash)
}
// The well-known hash for an empty string.
test(
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
nil...,
)
// Any line containing "$" + "NetBSD" is ignored for computing
// the hash since the CVS IDs are irrelevant. This assumes that
// the patch hunks themselves do not contain CVS IDs, and this
// is checked in PatchChecker.checktextCvsID.
test(
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
CvsID,
CvsID+"$",
// This is not a CVS ID since the final '$' is missing, but it is
// close enough. See mk/checksum/distinfo.awk, function patchsum.
"Some text $"+"NetBSD-2020",
)
test(
// == sha1Hex("--- old\n+++ new\n")
"bb5a3903635415d367f47c02990e031469ab0346",
"--- old",
"+++ new",
)
}
|