File: 23-quiet.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 (67 lines) | stat: -rw-r--r-- 1,876 bytes parent folder | download
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
use strict;
use warnings;
use Test::More;
use Test::Requires::Git;
use Test::Git;
use Git::Repository;

test_requires_git '1.5.0.rc4';

# clean up the environment
delete @ENV{qw( GIT_DIR GIT_WORK_TREE )};
$ENV{LC_ALL}              = 'C';
$ENV{GIT_AUTHOR_NAME}     = 'Test Author';
$ENV{GIT_AUTHOR_EMAIL}    = 'test.author@example.com';
$ENV{GIT_COMMITTER_NAME}  = 'Test Committer';
$ENV{GIT_COMMITTER_EMAIL} = 'test.committer@example.com';
$ENV{GIT_CONFIG_NOSYSTEM} = 1;
delete $ENV{XDG_CONFIG_HOME};
delete $ENV{HOME};

# a place to put a git repository
my @init;
push @init, init => [ '-q' ] if Git::Repository->version_ge('1.5.2.3');
my $r = test_repository(@init);

# PREV will be replaced by the result of the previous command
my @tests = (
    [ [ qw( mktree ),           { input => '' } ] ],
    [ [ qw( commit-tree PREV ), { input => 'empty tree' } ] ],
    [ [qw( update-ref refs/heads/master PREV )] ],
    [ [qw( checkout -b slave )], qr/^Switched to a new branch ['"]slave['"] at / ],
    [ [qw( checkout master )], qr/^Switched to branch ['"]master['"] at / ],
    [ [ qw( checkout slave ), { quiet => 1 } ] ],
    [ [ qw( checkout master ), { quiet => 1 } ] ],
);

plan tests => scalar @tests;

my $PREV;
for my $t (@tests) {
    my ( $args, $re ) = @$t;

    # capture warnings
    my @warnings;
    local $SIG{__WARN__} = sub { push @warnings, shift };

    # replace the args
    $args = [ map $_ eq 'PREV' ? $PREV : $_, @$args ];

    # run the command
    $PREV = $r->run(@$args);

    # format the command for test output
    my $cmd = join ' ', 'git', map {
        my $v = $_;
        ref $v ? "{ @{[map{qq'$_ => $v->{$_}'}sort keys %$v]} }" : $v
    } @$args;

    # run the actual test
    if ($re) {
        like( $warnings[0], $re, "Got the expected warning for: $cmd" );
    }
    else {
        is( @warnings, 0, "No warning for: $cmd" );
    }
}