File: 02_git.t

package info (click to toggle)
cloc 1.96-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,704 kB
  • sloc: perl: 26,078; cpp: 1,219; ansic: 320; asm: 267; makefile: 237; sh: 185; sql: 144; ruby: 111; cs: 87; java: 81; python: 54; lisp: 50; cobol: 35; f90: 35; haskell: 35; objc: 25; php: 22; pascal: 18; javascript: 15; fortran: 9; ml: 8; xml: 3; tcl: 2
file content (150 lines) | stat: -rwxr-xr-x 5,681 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env perl
use warnings;
use strict;
use Test::More;
use File::Copy "cp";
use Cwd;
my @Tests = (
                {
                    'name' => 'direct count git hash 1',
                    'args' => 'd9b672643d',
                    'ref'  => '../tests/outputs/git_tests/d9b672643d.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'direct count git hash 2',
                    'args' => 'f647093e8be3',
                    'ref'  => '../tests/outputs/git_tests/f647093e8be3.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'tar file f647093e8',
                    'args' => '../../tests/inputs/git_tests/contents_f647093e8.tar.gz',
                    'ref'  => '../tests/outputs/git_tests/contents_f647093e8.tar.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'diff f647093e8 to tar file f647093e8',
                    'args' => '--git --diff f647093e8 ../../tests/inputs/git_tests/contents_f647093e8.tar.gz',
                    'ref'  => '../tests/outputs/git_tests/diff_contents_f647093e8.tar.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'diff f15bf042b f647093e8b',
                    'args' => '--git --diff f15bf042b f647093e8b',
                    'ref'  => '../tests/outputs/git_tests/diff_f15bf042b_f647093e8b.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'diff commit with only deleted file',
                    'args' => '--strip-str-comments --git --diff 04179b6 ae0d26e',
                    'ref'  => '../tests/outputs/git_tests/04179b6_ae0d26e.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'diff commit with only added file',
                    'args' => '--strip-str-comments --git --diff f15bf04 d9b6726',
                    'ref'  => '../tests/outputs/git_tests/f15bf04_d9b6726.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

                {
                    'name' => 'count and diff part I',
                    'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
                    'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.HEAD',
                    'cd'   => 'cloc_submodule_test',
                    'results'  => 'results.yaml.HEAD',
                },

                {
                    'name' => 'count and diff part II',
                    'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
                    'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.HEAD~1',
                    'cd'   => 'cloc_submodule_test',
                    'results'  => 'results.yaml.HEAD~1',
                },

                {
                    'name' => 'count and diff part III',
                    'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
                    'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.diff.HEAD~1.HEAD',
                    'cd'   => 'cloc_submodule_test',
                    'results'  => 'results.yaml.diff.HEAD~1.HEAD',
                },

                {
                    'name' => 'file size filter with --vcs, #599',
                    'args' => '--vcs=git --max-file-size 0.0001 .',
                    'ref'  => '../tests/outputs/issues/599/results.yaml',
                    'cd'   => 'cloc_submodule_test',
                },

            );

my $Verbose = 0;

if (!-d 'cloc_submodule_test') {
    print "-" x 79, "\n";
    print "Directory 'cloc_submodule_test' is not found; git tests skipped.\n";
    print "To enable the tests, create the directory with\n";
    print "    git clone https://github.com/AlDanial/cloc_submodule_test.git\n";
    ok( 1, "git tests skipped during Debian package build");
    print "-" x 79, "\n";
} else {
    my $results  = 'results.yaml';
    my $work_dir = getcwd;
    my $cloc     = "$work_dir/../cloc";   # all-purpose version
#   my $cloc     = "$work_dir/cloc";      # Unix-tuned version
    my $Run = "$cloc --quiet --yaml --out $results ";
    foreach my $t (@Tests) {
        chdir($t->{'cd'}) if defined $t->{'cd'};
        print  $Run . $t->{'args'} if $Verbose;
        system($Run . $t->{'args'});
        my %this = ();
        if (defined $t->{'results'}) {
            ok(-e $t->{'results'}, $t->{'name'} . " created output");
            %this = load_yaml($t->{'results'});
        } else {
            ok(-e $results       , $t->{'name'} . " created output");
            %this = load_yaml($results);
        }
        unlink $results;
        chdir($work_dir) if defined $t->{'cd'};
        my %ref  = load_yaml($t->{'ref'});

        is_deeply(\%ref, \%this, $t->{'name'} . " results match");
    }
}
done_testing();

sub load_yaml { # {{{1
    my ($file, ) = @_;
    my %result = ();
    if (!-r $file) {
        warn "File not found: $file\n";
        return %result;
    }
    open IN, $file or return %result;
    my $section = undef;
    while (<IN>) {
        next if /^\s*#/ or /^--/;
        if (/^\s*'?(.*?)'?\s*:\s*$/) {
            $section = $1;
            next;
        }
        next unless defined $section;
        next if $section eq 'header';
        chomp;
        s/\s+//g;
        my ($K, $V) = split(':');
        $result{$section}{$K} = $V;
    }
    close IN;
    return %result
} # 1}}}