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
Line 
1#!/usr/bin/perl -w
2#
3# Tests ProjectBuilder::Base functions
4
5use strict;
6use ProjectBuilder::Base;
7
8my $res;
9eval
10{
11 require Test::More;
12 Test::More->import();
13 $res = $@;
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 }
18};
19
20# Test::More appropriate version not found so no test will be performed here
21if ($res) {
22 require Test;
23 Test->import();
24 plan(tests => 1);
25 print "# Faking tests as Test::More is not available in an appropriate version\n";
26 ok(1,1);
27 exit(0);
28}
29
30my $nt = 0;
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 };
37
38my ($scheme, $account, $host, $port, $path);
39foreach my $uri (keys %$test) {
40 ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
41
42 is($scheme, $test->{$uri}[0], "pb_get_uri Test protocol $uri");
43 $nt++;
44
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}
57
58$ENV{'TMPDIR'} = "/tmp";
59pb_temp_init();
60like($ENV{'PBTMP'}, qr|/tmp/pb\.[0-9A-z]+|, "pb_temp_init Test");
61$nt++;
62
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);
67
68my $cnt = pb_get_content("$ENV{'PBTMP'}/test");
69is($cnt, $content, "pb_get_content Test");
70$nt++;
71
72done_testing($nt);
Note: See TracBrowser for help on using the repository browser.