File: 10-new_fail.t

package info (click to toggle)
libgit-repository-perl 1.325-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 376 kB
  • sloc: perl: 661; makefile: 7
file content (78 lines) | stat: -rw-r--r-- 2,254 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use strict;
use warnings;
use Test::More;
use Test::Requires::Git;
use Test::Git;
use Cwd qw( abs_path );
use File::Temp qw( tempdir );
use File::Spec;
use File::Path;
use Git::Repository;

plan tests => 12;

# a place to put a git repository
my $dir = abs_path( tempdir( CLEANUP => 1 ) );
my $missing = File::Spec->catdir( $dir, 'missing' );
my $gitdir  = File::Spec->catdir( $dir, '.git' );

# clean up the environment
delete @ENV{qw( GIT_DIR GIT_WORK_TREE )};
$ENV{LC_ALL} = 'C';

# FAIL - missing repository directory
ok( !eval { Git::Repository->new( git_dir => $missing ) },
    'Missing repository directory' );
like( $@, qr/^directory not found: (?:\Q$missing\E)? /, '... expected error message' );

# FAIL - missing working copy directory
ok( !eval { Git::Repository->new( work_tree => $missing ) },
    'Missing work_tree directory' );
like( $@, qr/^directory not found: (?:\Q$missing\E)? /, '... expected error message' );

# FAIL - repository is not a git repository
ok( !eval { Git::Repository->new( git_dir => $dir ) },
    'repository directory is not a git repository'
);
like(
    $@,
    qr/^fatal: not a git repository/i,    # error from git itself
    '... expected error message'
);

# FAIL - working copy is not a git working copy
SKIP: {
    my $tmp = File::Spec->tmpdir();
    skip "$tmp is already a working copy for some git repository", 2
        if eval { Git::Repository->new( work_tree => $tmp ) };
    ok( !eval { Git::Repository->new( work_tree => $dir ) },
        'work_tree directory is not a git working copy'
    );
    like(
        $@,
        qr/^fatal: not a git repository/i,    # error from git itself
        '... expected error message'
    );
}

# FAIL - working copy is not a git working copy
mkpath($gitdir);
ok( !eval {
        Git::Repository->new( work_tree => $dir, git_dir => $gitdir );
    },
    'work_tree\'s repository directory is not a git repository'
);
like(
    $@,
    qr/^fatal: not a git repository/i,    # error from git itself
    '... expected error message'
);

# FAIL - extra parameters
ok( !eval {
        Git::Repository->new( work_tree => $dir, extra => 'stuff' );
    },
    'unknown extra parameter'
);
like( $@, qr/^Unknown parameters: extra /, '... expected error message' );