Permalink
Browse files

tests: convert to Test::More

  • Loading branch information...
1 parent c8d3ae8 commit 5b98f6e2c42f3cb73b612fb178ac5ad97a2d65d2 @marschap marschap committed Oct 14, 2012
Showing with 220 additions and 258 deletions.
  1. +8 −15 t/00ldif-entry.t
  2. +5 −3 t/01canon_dn.t
  3. +13 −17 t/02filter.t
  4. +12 −16 t/03schema.t
  5. +14 −12 t/04refloop.t
  6. +6 −13 t/05dsml.t
  7. +7 −4 t/06constant.t
  8. +8 −5 t/40connect.t
  9. +8 −5 t/41populate.t
  10. +8 −5 t/42search.t
  11. +8 −5 t/43modify.t
  12. +8 −5 t/44schema.t
  13. +8 −5 t/45dse.t
  14. +29 −28 t/46ssl.t
  15. +8 −5 t/47ipc.t
  16. +7 −7 t/48url.t
  17. +26 −23 t/49lwp.t
  18. +31 −44 t/70sortctrl.t
  19. +6 −41 t/common.pl
View
@@ -4,8 +4,7 @@ BEGIN {
require "t/common.pl";
}
-
-print "1..16\n";
+use Test::More tests => 16;
use Net::LDAP::LDIF;
@@ -162,19 +161,13 @@ ok(!compare($cmpfile,$outfile), $cmpfile);
$e->add('name' => 'Graham Barr');
$e->add('name;en-us' => 'Bob');
-print "not " unless
-ok(
- join(":",sort $e->attributes)
- eq
- "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber",
- "attributes");
-
-print "not " unless
-ok(
- join(":",sort $e->attributes(nooptions => 1))
- eq
- "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber",
- "attributes - nooptions");
+is(join(":",sort $e->attributes),
+ "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:name;en-us:o:postaladdress:second:st:streetaddress:telephonenumber",
+ 'attributes');
+
+is(join(":",sort $e->attributes(nooptions => 1)),
+ "associateddomain:counting:description:first:l:lastmodifiedby:lastmodifiedtime:name:o:postaladdress:second:st:streetaddress:telephonenumber",
+ "attributes - nooptions");
$r = $e->get_value('name', asref => 1);
ok(($r and @$r == 1 and $r->[0] eq 'Graham Barr'), "name eq Graham Barr");
View
@@ -1,5 +1,6 @@
#!perl
+use Test::More;
use Net::LDAP::Util qw(canonical_dn);
# Each line has an opcode and a DN, opcode are
@@ -10,8 +11,9 @@ use Net::LDAP::Util qw(canonical_dn);
my @tests = map { /^(\w+)\s+(.*)/ } <DATA>;
-print "1..", scalar(@tests)>>1, "\n";
-my $testno = 0;
+plan tests => scalar(@tests) >> 1;
+
+
my $refdn;
while(my($op,$dn) = splice(@tests,0,2)) {
@@ -50,7 +52,7 @@ while(my($op,$dn) = splice(@tests,0,2)) {
warn "Bad opcode $op\n";
}
- print +($failed ? "not ok " : "ok "),++$testno,"\n";
+ ok(!$failed, "$dn is " . (($op eq 'bad') ? 'illegal' : 'legal'));
}
View
@@ -1,6 +1,7 @@
#!perl
# Testcase contributed by Julian Onions <Julian.Onions@nexor.co.uk>
+use Test::More;
use Net::LDAP::Filter;
use Net::LDAP::ASN qw(Filter);
use Convert::ASN1 qw(asn_dump);
@@ -9,7 +10,9 @@ my $asn = $Filter;
my @tests = do { local $/=""; <DATA> };
-print "1..", 4*scalar(@tests), "\n";
+plan tests => 4 * scalar(@tests);
+
+
my $testno = 0;
my $test;
foreach $test (@tests) {
@@ -24,30 +27,23 @@ foreach $test (@tests) {
my $binary = pack("H*", join("", map { /\w+/g } $ber =~ /:((?: [\dA-Fa-f]{2}){1,16})/g));
- $testno ++;
- print "# ",$filter,"\n";
- $filt = new Net::LDAP::Filter $filter or print "not ";
- print "ok $testno\n";
- $testno ++;
- my $data = $asn->encode($filt) or print "# ",$asn->error,"\nnot ";
- print "ok $testno\n";
- $testno ++;
+ my $filt = new Net::LDAP::Filter $filter;
+ isa_ok($filt, Net::LDAP::Filter, "$filter");;
+
+ my $data = $asn->encode($filt);
+ ok($data, "$filter ASN.1 encode(".($asn->error || 0).')');
+
+ is($data, $binary, "$filter asn_dump");
unless($data eq $binary) {
- require Data::Dumper;
- print Data::Dumper::Dumper($filt);
+ note explain($filt);
print "got ", unpack("H*", $data), "\n";
asn_dump(\*STDOUT, $data);
print "wanted ", unpack("H*", $binary), "\n";
asn_dump(\*STDOUT, $binary);
-
- print "not "
}
- print "ok $testno\n";
- $testno ++;
my $str = $filt->as_string;
- print "# ", $str,"\nnot " unless $str eq $filter_out;
- print "ok $testno\n";
+ is($str, $filter_out, "$filter as_string");
}
__DATA__
View
@@ -1,40 +1,36 @@
#!perl -w
-use Net::LDAP::Schema;
-print "1..7\n";
+use Test::More tests => 7;
+use Net::LDAP::Schema;
my $schema = Net::LDAP::Schema->new( "data/schema.in" ) or die "Cannot open schema";
-print "ok 1\n";
+isa_ok($schema, Net::LDAP::Schema, 'load schema file');
my @atts = $schema->all_attributes();
-print "not " unless @atts == 55;
-print "ok 2\n";
-
+is(@atts, 55, 'number of attribute types in schema');
print "The schema contains ", scalar @atts, " attributes\n";
my @ocs = $schema->all_objectclasses();
-print "not " unless @ocs == 22;
-print "ok 3\n";
+is(@ocs, 22, 'number of object classes in schema');
print "The schema contains ", scalar @ocs, " object classes\n";
@atts = $schema->must( "person" );
-print "not " unless join(' ', sort map $_->{name}, @atts) eq join(' ',sort qw(cn sn objectClass));
-print "ok 4\n";
+is(join(' ', sort map $_->{name}, @atts), join(' ',sort qw(cn sn objectClass)), 'mandatory attributes');
print "The 'person' OC must have these attributes [",
join( ",", map $_->{name}, @atts ),
"]\n";
+
@atts = $schema->may( "mhsOrganizationalUser" );
-print "not " if @atts;
-print "ok 5\n";
+ok(!@atts, 'optional attributes');
print "The 'mhsOrganizationalUser' OC may have these attributes [",
join( ",", map $_->{name}, @atts ),
"]\n";
-print "not " if defined $schema->attribute('distinguishedName')->{max_length};
-print "ok 6\n";
+ok(! defined($schema->attribute('distinguishedName')->{max_length}), 'infinite length attribute type');
-print "not " unless $schema->attribute('userPassword')->{max_length} == 128;
-print "ok 7\n";
+is($schema->attribute('userPassword')->{max_length}, 128, 'attribute type max. length');
use Data::Dumper;
print Dumper($schema);
+
+0;
View
@@ -1,24 +1,24 @@
#!perl
+use Test::More;
+
use Net::LDAP qw(LDAP_UNAVAILABLE);
my $devnull = eval { require File::Spec; File::Spec->devnull } || "/dev/null";
-unless (-e $devnull) {
- print "1..0 # Skip no null device\n";
- exit;
-}
-print "1..5\n";
+(-e $devnull)
+? plan tests => 5
+: plan skip_all => 'no null device';
+
$::destroy = 0;
{
my $ldap = Net::LDAP::Dummy->new("host", async => 1);
$ldap->bind; # create an internal ref loop
- require Data::Dumper, print Data::Dumper::Dumper($ldap->inner)
- if $ENV{TEST_VERBOSE};
+ note explain($ldap->inner) if $ENV{TEST_VERBOSE};
}
-print $::destroy ? "ok 1\n" : "not ok 1\n";
+ok($::destroy, '');
my $ref;
my $mesg;
@@ -27,13 +27,15 @@ $::destroy = 0;
my $ldap = Net::LDAP::Dummy->new("host", async => 1);
$mesg = $ldap->bind; # create an internal ref loop
$ref = $ldap->inner->outer;
- print +($ref == $ldap) ? "not ok 2\n" : "ok 2\n";
+ is($ref == $ldap, '');
}
-print $::destroy ? "not ok 3\n" : "ok 3\n";
+ok(!$::destroy, '');
+
$ref = undef;
-print +($mesg->code == LDAP_UNAVAILABLE) ? "ok 4\n" : "not ok 4\n";
+ok($mesg->code == LDAP_UNAVAILABLE, '');
+
undef $mesg;
-print $::destroy ? "ok 5\n" : "not ok 5\n";
+ok($::destroy, '');
package Net::LDAP::Dummy;
View
@@ -1,26 +1,19 @@
#!perl
+use Test::More;
use File::Compare;
-BEGIN {
- require "t/common.pl";
-}
+BEGIN { require "t/common.pl" }
-unless (eval { require XML::SAX::Base; 1}) {
- print "1..0 # XML::SAX::Base not installed\n";
- exit;
-}
-unless (eval { require XML::SAX::Writer; 1}) {
- print "1..0 # XML::SAX::Writer not installed\n";
- exit;
-}
+(eval { require XML::SAX::Base } && eval { require XML::SAX::Writer })
+? plan tests => 1
+: plan skip_all => 'XML::SAX::Base and XML::SAX::Writer need to be installed';
+
require Net::LDAP::LDIF;
require Net::LDAP::DSML;
-print "1..1\n";
-
my $infile = "data/00-in.ldif";
my $outfile1 = "$TEMPDIR/05-out1.dsml";
my $cmpfile1 = "data/05-cmp.dsml";
View
@@ -1,5 +1,7 @@
#!perl -w
+use Test::More;
+
BEGIN {
for (1,2) { require Net::LDAP::Constant; }
}
@@ -107,12 +109,13 @@ my @constant = qw(
LDAP_REFERRAL_LIMIT_EXCEEDED
);
-print "1..", scalar(@constant),"\n";
+plan tests => scalar(@constant);
+
+
my $i = 0;
-while(my $const = $constant[$i]) {
+while (my $const = $constant[$i]) {
my $name = ldap_error_name($i);
$const = sprintf("LDAP error code %d(0x%02X)",$i,$i) unless $const =~ /\D/;
- print "not " if !$name or $name ne $const;
+ ok($name && $name eq $const, "$const");
++$i;
- print "ok $i # $name $const\n";
}
View
@@ -1,11 +1,14 @@
#!perl
-BEGIN {
- require "t/common.pl";
- start_server();
-}
+use Test::More;
+
+BEGIN { require "t/common.pl" }
+
+
+start_server()
+? plan tests => 3
+: plan skip_all => 'no server';
-print "1..3\n";
$ldap = client();
ok($ldap, 'client with IPv4/IPv6 auto-selection' .
View
@@ -1,11 +1,14 @@
#!perl
-BEGIN {
- require "t/common.pl";
- start_server();
-}
+use Test::More;
+
+BEGIN { require "t/common.pl" }
+
+
+start_server()
+? plan tests => 7
+: plan skip_all => 'no server';
-print "1..7\n";
$ldap = client();
ok($ldap, "client");
View
@@ -1,11 +1,14 @@
#!perl
-BEGIN {
- require "t/common.pl";
- start_server();
-}
+use Test::More;
+
+BEGIN { require "t/common.pl" }
+
+
+start_server()
+? plan tests => 15
+: plan skip_all => 'no server';
-print "1..15\n";
$ldap = client();
ok($ldap, "client");
View
@@ -1,11 +1,14 @@
#!perl
-BEGIN {
- require "t/common.pl";
- start_server();
-}
+use Test::More;
+
+BEGIN { require "t/common.pl" }
+
+
+start_server()
+? plan tests => 7
+: plan skip_all => 'no server';
-print "1..7\n";
$ldap = client();
ok($ldap, "client");
View
@@ -1,11 +1,14 @@
#!perl
-BEGIN {
- require "t/common.pl";
- start_server(version => 3);
-}
+use Test::More;
+
+BEGIN { require "t/common.pl" }
+
+
+start_server(version => 3)
+? plan tests => 4
+: plan skip_all => 'no server';
-print "1..4\n";
$ldap = client();
ok($ldap, "client");
Oops, something went wrong.

0 comments on commit 5b98f6e

Please sign in to comment.