1#! /usr/bin/perl 2# $OpenBSD: check-name,v 1.11 2010/01/27 15:41:58 espie Exp $ 3# Written by Marc Espie 4# Public domain 5 6use Test::Simple tests => 20; 7use OpenBSD::Search; 8use OpenBSD::PackageName; 9 10sub check_list 11{ 12 my $expected = shift; 13 @_ = sort(@_); 14 if (@$expected != @_) { 15 print STDERR "length: ", scalar(@$expected)," vs. ", 16 scalar(@_), "\n"; 17 print STDERR join(',', @$expected), "\n"; 18 print STDERR join(',', @_), "\n"; 19 return 0; 20 } 21 for my $i (0 .. @_ -1) { 22 if ($expected->[$i] ne $_[$i]) { 23 print STDERR "$expected->[$i] vs. $_[$i]\n"; 24 return 0; 25 } 26 } 27 return 1; 28} 29 30sub check_pkgspec 31{ 32 my ($s, @list) = @_; 33 34 my $o = OpenBSD::Search::PkgSpec->new($s); 35 return $o->filter(@list); 36} 37 38sub check_name 39{ 40 my $s = shift; 41 return OpenBSD::PackageName->from_string($s)->has_issues; 42} 43 44sub check_order 45{ 46 my @l = map {OpenBSD::PackageName->from_string($_)} @_; 47 while (my $a = shift @l) { 48 for my $b (@l) { 49 if ($a->compare($b) >= 0) { 50 print $a->to_string, " > ", $b->to_string, "\n"; 51 return 0; 52 } 53 } 54 } 55 return 1; 56} 57 58@list = qw(py-MxDateTime-2.0.1-py2.1); 59ok(check_list(\@list, 60 check_pkgspec('py-MxDateTime->=2.0-py2.1', @list)), 61 'flavor with number'); 62@list = qw(foo-1.0 foo-1.0p0 foo-1.0p25); 63ok(check_list([qw(foo-1.0)], 64 check_pkgspec('foo-<1.0p0', @list)), 65 'before 1.0p0 came 1.0'); 66ok(check_list([qw(foo-1.0 foo-1.0p0)], 67 check_pkgspec('foo-<=1.0p0', @list)), 68 '1.0 and 1.0p0 both match <=1.0p0'); 69ok(check_list([qw(foo-1.0 foo-1.0p0 foo-1.0p25)], 70 check_pkgspec('foo-1.0', @list)), 71 'any 1.0p* matches 1.0'); 72@list = qw(foo-1.0rc2); 73ok(check_list(\@list, 74 check_pkgspec('foo-<1.0', @list)), 75 'before 1.0 came 1.0rc2'); 76@list = qw(foo-1.0); 77ok(check_list(\@list, 78 check_pkgspec('foo-<1.0pl1', @list)), 79 'before 1.0pl1 came 1.0'); 80 81my @pkglist=qw(foo-1.0 bar-2.0 foo-2.5 foobar-2.3-pouet hugs-noversion baz-0.0 82 baz-1.1 baz-25.3 pouet-1.0 pouet-zoinx-1.0 pouet-0.0-foo); 83 84my $hash = OpenBSD::PackageName::compile_stemlist(@pkglist); 85 86ok(check_list([qw(bar-2.0)], 87 $hash->find('bar')), 88 'simple stem lookup'); 89ok(check_list([qw(foo-1.0 foo-2.5)], 90 $hash->find('foo')), 91 'simple stem lookup with several results'); 92ok(check_list([qw(baz-0.0 baz-1.1 baz-25.3)], 93 $hash->find('baz')), 94 'stem lookup, no duplicates'); 95ok(check_list([qw(foobar-2.3-pouet)], 96 $hash->find('foobar')), 97 'stem lookup with flavor'); 98ok(check_list([qw(pouet-0.0-foo pouet-1.0)], 99 $hash->find('pouet')), 100 'complicated stem matching'); 101ok(check_list([], 102 $hash->find('hugs')), 103 'bogus stem matching with no version'); 104ok(check_list([qw(hugs-noversion)], 105 $hash->find('hugs-noversion')), 106 'stem matching with no version'); 107ok(OpenBSD::PackageName->from_string('foo-1.0-f2-f1')->to_string 108 eq 'foo-1.0-f1-f2', 109 'canonical names'); 110ok(!OpenBSD::Search::PkgSpec->new('foo-<>1.5')->is_valid, 111 'invalid spec'); 112 113ok(check_list(["is a stem"], check_name("pkgname-without-version")), 114 "pkgname without version"); 115ok(check_list(["flavor 1flavor can't start with digit"], 116 check_name("pkgname-1.0-flavor-1flavor")), 117 "numerical flavor"); 118ok(check_list(["correct order is pNvM"], check_name("pkgname-1.0v0p0")), 119 "mixed up vp"); 120ok(check_list([], check_name("pkgname-1.0p0v0")), "correct name"); 121 122ok(check_order(qw(speex-1.2beta3 speex-1.2rc1 speex-1.2 speex-1.2pl1 123 speex-1.3beta1)), 'check order'); 124