summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2005-08-16 16:02:10 +0000
committerMarc Espie <espie@cvs.openbsd.org>2005-08-16 16:02:10 +0000
commitd8b40bec45fba475959e014564e321e5ed1c554a (patch)
treef8fcdecb4741253ac5ad3e78f7da8034f048fa08
parente498da34d663495d255d11f004b5b73a506892dd (diff)
make test framework more specific, and use it.
-rw-r--r--regress/usr.sbin/pkg_add/check-name63
1 files changed, 55 insertions, 8 deletions
diff --git a/regress/usr.sbin/pkg_add/check-name b/regress/usr.sbin/pkg_add/check-name
index 2958209f606..8c25efc79e6 100644
--- a/regress/usr.sbin/pkg_add/check-name
+++ b/regress/usr.sbin/pkg_add/check-name
@@ -1,24 +1,71 @@
#! /usr/bin/perl
-# $OpenBSD: check-name,v 1.3 2005/08/16 15:41:56 espie Exp $
+# $OpenBSD: check-name,v 1.4 2005/08/16 16:02:09 espie Exp $
# Written by Marc Espie
# Public domain
-use Test::Simple tests => 5;
+use Test::Simple tests => 12;
use OpenBSD::PkgSpec;
+use OpenBSD::PackageName;
+
+sub check_list
+{
+ my $expected = shift;
+ @_ = sort(@_);
+ if (@$expected != @_) {
+ return 0;
+ }
+ for my $i (0 .. @_ -1) {
+ if ($expected->[$i] ne $_[$i]) {
+ return 0;
+ }
+ }
+ return 1;
+}
@list = qw(py-MxDateTime-2.0.1-py2.1);
-ok(OpenBSD::PkgSpec::match('py-MxDateTime->=2.0-py2.1', @list) == 1,
+ok(check_list(\@list,
+ OpenBSD::PkgSpec::match('py-MxDateTime->=2.0-py2.1', @list)),
'flavor with number');
# packages without a version number should work
my @list = qw(hugs98-Nov2003);
-ok(OpenBSD::PkgSpec::match('hugs98-Nov2003', @list) == 1,
+ok(check_list(\@list,
+ OpenBSD::PkgSpec::match('hugs98-Nov2003', @list)),
'no version number');
@list = qw(foo-1.0 foo-1.0p0 foo-1.0p25);
-my @result = OpenBSD::PkgSpec::match('foo-<1.0p0', @list);
-ok(@result == 1 && $result[0] eq 'foo-1.0',
+ok(check_list([qw(foo-1.0)],
+ OpenBSD::PkgSpec::match('foo-<1.0p0', @list)),
'before 1.0p0 came 1.0');
-ok(OpenBSD::PkgSpec::match('foo-<=1.0p0', @list) == 2,
+ok(check_list([qw(foo-1.0 foo-1.0p0)],
+ OpenBSD::PkgSpec::match('foo-<=1.0p0', @list)),
'1.0 and 1.0p0 both match <=1.0p0');
-ok(OpenBSD::PkgSpec::match('foo-1.0', @list) == 3,
+ok(check_list([qw(foo-1.0 foo-1.0p0 foo-1.0p25)],
+ OpenBSD::PkgSpec::match('foo-1.0', @list)),
'any 1.0p* matches 1.0');
+
+my @pkglist=qw(foo-1.0 bar-2.0 foo-2.5 foobar-2.3-pouet hugs-noversion baz-0.0
+ baz-1.1 baz-25.3 pouet-1.0 pouet-zoinx-1.0 pouet-0.0-foo);
+
+my $hash = OpenBSD::PackageName::compile_stemlist(@pkglist);
+
+ok(check_list([qw(bar-2.0)],
+ $hash->findstem('bar')),
+ 'simple stem lookup');
+ok(check_list([qw(foo-1.0 foo-2.5)],
+ $hash->findstem('foo')),
+ 'simple stem lookup with several results');
+ok(check_list([qw(baz-0.0 baz-1.1 baz-25.3)],
+ $hash->findstem('baz')),
+ 'stem lookup, no duplicates');
+ok(check_list([qw(foobar-2.3-pouet)],
+ $hash->findstem('foobar')),
+ 'stem lookup with flavor');
+ok(check_list([qw(pouet-0.0-foo pouet-1.0)],
+ $hash->findstem('pouet')),
+ 'complicated stem matching');
+ok(check_list([],
+ $hash->findstem('hugs')),
+ 'bogus stem matching with no version');
+ok(check_list([qw(hugs-noversion)],
+ $hash->findstem('hugs-noversion')),
+ 'stem matching with no version');