source: ProjectBuilder/devel/pb-modules/t/Base.t

Last change on this file was 2275, checked in by Bruno Cornec, 7 years ago

Fix tests so that they really work when Test::More isn't found

File size: 1.7 KB
RevLine 
[1075]1#!/usr/bin/perl -w
2#
3# Tests ProjectBuilder::Base functions
4
5use strict;
[1076]6use ProjectBuilder::Base;
[1075]7
[2275]8my $res;
[1106]9eval
10{
[1147]11 require Test::More;
12 Test::More->import();
[2275]13 $res = $@;
[1147]14 my ($tmv,$tmsv) = split(/\./,$Test::More::VERSION);
15 if ($tmsv lt 87) {
16 die "Test::More is not available in an appropriate version ($tmsv)";
17 }
[1106]18};
19
[1147]20# Test::More appropriate version not found so no test will be performed here
[2275]21if ($res) {
[1109]22 require Test;
[1153]23 Test->import();
[1109]24 plan(tests => 1);
[1147]25 print "# Faking tests as Test::More is not available in an appropriate version\n";
[1106]26 ok(1,1);
[1147]27 exit(0);
[1106]28}
29
[1075]30my $nt = 0;
[1077]31my $test = {
32 # Full URI
33 "svn+ssh://account\@machine.sdom.tld:8080/path/to/file" => ["svn+ssh","account","machine.sdom.tld","8080","/path/to/file"],
34 # Partial URI
35 "http://machine2/path1/to/anotherfile" => ["http","","machine2","","/path1/to/anotherfile"],
36 };
[1075]37
[1077]38my ($scheme, $account, $host, $port, $path);
39foreach my $uri (keys %$test) {
40 ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
[1075]41
[1077]42 is($scheme, $test->{$uri}[0], "pb_get_uri Test protocol $uri");
43 $nt++;
[1075]44
[1077]45 is($account, $test->{$uri}[1], "pb_get_uri Test account $uri");
46 $nt++;
47
48 is($host, $test->{$uri}[2], "pb_get_uri Test host $uri");
49 $nt++;
50
51 is($port, $test->{$uri}[3], "pb_get_uri Test port $uri");
52 $nt++;
53
54 is($path, $test->{$uri}[4], "pb_get_uri Test path $uri");
55 $nt++;
56}
[1075]57
[1077]58$ENV{'TMPDIR'} = "/tmp";
59pb_temp_init();
60like($ENV{'PBTMP'}, qr|/tmp/pb\.[0-9A-z]+|, "pb_temp_init Test");
[1075]61$nt++;
62
[1077]63my $content = "This is content with TABs and spaces and \ncarriage returns\n";
64open(FILE,"> $ENV{'PBTMP'}/test") || die "Unable to create temp file";
65print FILE $content;
66close(FILE);
[1075]67
[1077]68my $cnt = pb_get_content("$ENV{'PBTMP'}/test");
69is($cnt, $content, "pb_get_content Test");
[1075]70$nt++;
71
72done_testing($nt);
Note: See TracBrowser for help on using the repository browser.