1#! /usr/bin/perl 2 3# $OpenBSD: check-path,v 1.5 2011/05/28 13:44:20 espie Exp $ 4 5# unit test the matching of extra-info and @pkgpath between packing-lists. 6 7use Test::Simple tests => 19; 8use OpenBSD::PackingList; 9 10sub make_plist 11{ 12 my $p = OpenBSD::PackingList->new; 13 OpenBSD::PackingElement::ExtraInfo->add($p, shift, '', ''); 14 for my $path (@_) { 15 OpenBSD::PackingElement::PkgPath->add($p, $path); 16 } 17 return $p; 18} 19 20sub symetry 21{ 22 while (my $p = pop @_) { 23 if (!$p->match_pkgpath($p)) { 24 return 0; 25 } 26 for my $p2 (@_) { 27 my $t1 = !$p->match_pkgpath($p2); 28 my $t2 = !$p2->match_pkgpath($p); 29 if ($t1 ^ $t2) { 30 return 0; 31 } 32 } 33 } 34 return 1; 35} 36 37my @p = ( 38 make_plist('p1'), # 0 39 make_plist('p1'), # 1 40 make_plist('p2'), # 2 41 make_plist('p2', 'p1'), # 3 42 make_plist('p3', 'p1'), # 4 43 make_plist('p4,flavor'), # 5 44 make_plist('newp4', 'p4,flavor'), # 6 45 make_plist('newp4', 'p4,otherflavor'), # 7 46 make_plist('p5,f1,f2'), # 8 47 make_plist('newp5', 'p5,f1,f2'), # 9 48 make_plist('newp5', 'p5,f2'), # 10 49 make_plist('newp5', 'p5,f2,f1'), # 11 50 make_plist('newp5', 'other,f1,f2'), # 12 51 make_plist('newp5', 'p5,f1[,f2]'), # 13 52 make_plist('p5,f1'), # 14 53 make_plist('p5,f1,f3'), # 15 54 make_plist('p5,f1,f2,f3'), # 16 55 make_plist('newp5', 'p5,f1,f1,f2'), # 17 56 make_plist('newp5', 'p5[,f1][,f2]'), # 18 57 make_plist('newp5', 'p5[,f1,f2][,f1,f3]'), # 19 58 make_plist('newp5', 'p5[,f1,f4][,f3]'), # 20 59); 60 61ok(symetry(@p), "match_pkgpath is symetric"); 62ok($p[0]->match_pkgpath($p[1]), "same path matches"); 63ok(!$p[0]->match_pkgpath($p[2]), "different paths don't"); 64ok($p[0]->match_pkgpath($p[3]), "look into the list too"); 65ok(!$p[3]->match_pkgpath($p[4]), "extra elements can't match by themselves"); 66ok($p[5]->match_pkgpath($p[6]), "paths with same flavors do match"); 67ok(!$p[5]->match_pkgpath($p[7]), "paths with distinct flavor do not match"); 68ok($p[8]->match_pkgpath($p[9]), "same flavor combo does match"); 69ok(!$p[8]->match_pkgpath($p[10]), "different flavor combo does not match"); 70ok($p[8]->match_pkgpath($p[11]), "reordered flavors should match"); 71ok(!$p[8]->match_pkgpath($p[12]), "same flavor but distinct dir does not match"); 72ok($p[8]->match_pkgpath($p[13]), "optional parts should match"); 73ok($p[14]->match_pkgpath($p[13]), "optional parts should match"); 74ok(!$p[15]->match_pkgpath($p[13]), "detect bad parts"); 75ok(!$p[16]->match_pkgpath($p[13]), "detect bad parts"); 76ok($p[8]->match_pkgpath($p[17]), "duplicate flavors"); 77ok($p[8]->match_pkgpath($p[18]), "several optional parts"); 78ok($p[16]->match_pkgpath($p[19]), "several optional parts"); 79ok(!$p[20]->match_pkgpath($p[14]), "missing flavor"); 80