source: devel/pb-modules/t/Base.t @ 1106

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