"Fossies" - the Fresh Open Source Software Archive

Member "cloc-1.86/Unix/t/02_git.t" (19 May 2020, 5345 Bytes) of package /linux/privat/cloc-1.86.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "02_git.t": 1.84_vs_1.86.

    1 #!/usr/bin/env perl
    2 use warnings;
    3 use strict;
    4 use Test::More;
    5 use File::Copy "cp";
    6 use Cwd;
    7 my @Tests = (
    8                 {
    9                     'name' => 'direct count git hash 1',
   10                     'args' => 'd9b672643d',
   11                     'ref'  => '../tests/outputs/git_tests/d9b672643d.yaml',
   12                     'cd'   => 'cloc_submodule_test',
   13                 },
   14 
   15                 {
   16                     'name' => 'direct count git hash 2',
   17                     'args' => 'f647093e8be3',
   18                     'ref'  => '../tests/outputs/git_tests/f647093e8be3.yaml',
   19                     'cd'   => 'cloc_submodule_test',
   20                 },
   21 
   22                 {
   23                     'name' => 'tar file f647093e8',
   24                     'args' => '../../tests/inputs/git_tests/contents_f647093e8.tar.gz',
   25                     'ref'  => '../tests/outputs/git_tests/contents_f647093e8.tar.yaml',
   26                     'cd'   => 'cloc_submodule_test',
   27                 },
   28 
   29                 {
   30                     'name' => 'diff f647093e8 to tar file f647093e8',
   31                     'args' => '--git --diff f647093e8 ../../tests/inputs/git_tests/contents_f647093e8.tar.gz',
   32                     'ref'  => '../tests/outputs/git_tests/diff_contents_f647093e8.tar.yaml',
   33                     'cd'   => 'cloc_submodule_test',
   34                 },
   35 
   36                 {
   37                     'name' => 'diff f15bf042b f647093e8b',
   38                     'args' => '--git --diff f15bf042b f647093e8b',
   39                     'ref'  => '../tests/outputs/git_tests/diff_f15bf042b_f647093e8b.yaml',
   40                     'cd'   => 'cloc_submodule_test',
   41                 },
   42 
   43                 {
   44                     'name' => 'diff commit with only deleted file',
   45                     'args' => '--strip-str-comments --git --diff 04179b6 ae0d26e',
   46                     'ref'  => '../tests/outputs/git_tests/04179b6_ae0d26e.yaml',
   47                     'cd'   => 'cloc_submodule_test',
   48                 },
   49 
   50                 {
   51                     'name' => 'diff commit with only added file',
   52                     'args' => '--strip-str-comments --git --diff f15bf04 d9b6726',
   53                     'ref'  => '../tests/outputs/git_tests/f15bf04_d9b6726.yaml',
   54                     'cd'   => 'cloc_submodule_test',
   55                 },
   56 
   57                 {
   58                     'name' => 'count and diff part I',
   59                     'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
   60                     'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.HEAD',
   61                     'cd'   => 'cloc_submodule_test',
   62                     'results'  => 'results.yaml.HEAD',
   63                 },
   64 
   65                 {
   66                     'name' => 'count and diff part II',
   67                     'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
   68                     'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.HEAD~1',
   69                     'cd'   => 'cloc_submodule_test',
   70                     'results'  => 'results.yaml.HEAD~1',
   71                 },
   72 
   73                 {
   74                     'name' => 'count and diff part III',
   75                     'args' => '--strip-str-comments  --git --count-and-diff HEAD~1 HEAD',
   76                     'ref'  => '../tests/outputs/git_tests/count_and_diff.yaml.diff.HEAD~1.HEAD',
   77                     'cd'   => 'cloc_submodule_test',
   78                     'results'  => 'results.yaml.diff.HEAD~1.HEAD',
   79                 },
   80 
   81             );
   82 
   83 my $Verbose = 0;
   84 
   85 if (!-d 'cloc_submodule_test') {
   86     print "-" x 79, "\n";
   87     print "Directory 'cloc_submodule_test' is not found; git tests skipped.\n";
   88     print "To enable the tests, create the directory with\n";
   89     print "    git clone https://github.com/AlDanial/cloc_submodule_test.git\n";
   90     ok( 0, "git tests");
   91     print "-" x 79, "\n";
   92 } else {
   93     my $results  = 'results.yaml';
   94     my $work_dir = getcwd;
   95     my $cloc     = "$work_dir/../cloc";   # all-purpose version
   96 #   my $cloc     = "$work_dir/cloc";      # Unix-tuned version
   97     my $Run = "$cloc --quiet --yaml --out $results ";
   98     foreach my $t (@Tests) {
   99         chdir($t->{'cd'}) if defined $t->{'cd'};
  100         print  $Run . $t->{'args'} if $Verbose;
  101         system($Run . $t->{'args'});
  102         my %this = ();
  103         if (defined $t->{'results'}) {
  104             ok(-e $t->{'results'}, $t->{'name'} . " created output");
  105             %this = load_yaml($t->{'results'});
  106         } else {
  107             ok(-e $results       , $t->{'name'} . " created output");
  108             %this = load_yaml($results);
  109         }
  110         unlink $results;
  111         chdir($work_dir) if defined $t->{'cd'};
  112         my %ref  = load_yaml($t->{'ref'});
  113 
  114         is_deeply(\%ref, \%this, $t->{'name'} . " results match");
  115     }
  116 }
  117 done_testing();
  118 
  119 sub load_yaml { # {{{1
  120     my ($file, ) = @_;
  121     my %result = ();
  122     if (!-r $file) {
  123         warn "File not found: $file\n";
  124         return %result;
  125     }
  126     open IN, $file or return %result;
  127     my $section = undef;
  128     while (<IN>) {
  129         next if /^\s*#/ or /^--/;
  130         if (/^\s*'?(.*?)'?\s*:\s*$/) {
  131             $section = $1;
  132             next;
  133         }
  134         next unless defined $section;
  135         next if $section eq 'header';
  136         chomp;
  137         s/\s+//g;
  138         my ($K, $V) = split(':');
  139         $result{$section}{$K} = $V;
  140     }
  141     close IN;
  142     return %result
  143 } # 1}}}