"Fossies" - the Fresh Open Source Software Archive

Member "cloc-1.86/Unix/t/01_opts.t" (19 May 2020, 22260 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 "01_opts.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 #use YAML qw(LoadFile);
    8 my @Tests = (
    9                 {
   10                     'name' => '--exclude-dir 1 (baseline for github issue #82)',
   11                     'args' => '--exclude-dir cc ../tests/inputs/dd',
   12                     'ref'  => '../tests/outputs/exclude_dir_1.yaml',
   13                 },
   14                 {
   15                     'name' => '--exclude-dir 2 (github issue #82)',
   16                     'cd'   => '../tests/inputs/dd',
   17                     'args' => '--exclude-dir cc *',
   18                     'ref'  => '../tests/outputs/exclude_dir_1.yaml',
   19                 },
   20                 {
   21                     'name' => '--not-match-d',
   22                     'cd'   => '../tests/inputs/dd',
   23                     'args' => '--not-match-d cc *',
   24                     'ref'  => '../tests/outputs/exclude_dir_1.yaml',
   25                 },
   26                 {
   27                     'name' => '--not-match-d (github issue #114 T1)',
   28                     'cd'   => '../tests/inputs',
   29                     'args' => '--by-file issues/114',
   30                     'ref'  => '../tests/outputs/issues/114/T1.yaml',
   31                 },
   32                 {
   33                     'name' => '--not-match-d (github issue #114 T2)',
   34                     'cd'   => '../tests/inputs',
   35                     'args' => '--by-file --not-match-d bar issues/114',
   36                     'ref'  => '../tests/outputs/issues/114/T2.yaml',
   37                 },
   38                 {
   39                     'name' => '--not-match-d (github issue #114 T3)',
   40                     'cd'   => '../tests/inputs',
   41                     'args' => '--by-file --not-match-d bee issues/114',
   42                     'ref'  => '../tests/outputs/issues/114/T3.yaml',
   43                 },
   44                 {
   45                     'name' => '--not-match-d (github issue #114 T4)',
   46                     'cd'   => '../tests/inputs',
   47                     'args' => '--by-file --not-match-d bar/bee issues/114',
   48                     'ref'  => '../tests/outputs/issues/114/T4.yaml',
   49                 },
   50                 {
   51                     'name' => '--not-match-d (github issue #114 T5)',
   52                     'cd'   => '../tests/inputs',
   53                     'args' => '--by-file --fullpath --not-match-d   bar issues/114',
   54                     'ref'  => '../tests/outputs/issues/114/T5.yaml',
   55                 },
   56                 {
   57                     'name' => '--not-match-d (github issue #114 T6)',
   58                     'cd'   => '../tests/inputs',
   59                     'args' => '--by-file --fullpath --not-match-d ./bar issues/114',
   60                     'ref'  => '../tests/outputs/issues/114/T6.yaml',
   61                 },
   62                 {
   63                     'name' => '--not-match-d (github issue #114 T7)',
   64                     'cd'   => '../tests/inputs',
   65                     'args' => '--by-file --fullpath --not-match-d bar/bee issues/114',
   66                     'ref'  => '../tests/outputs/issues/114/T7.yaml',
   67                 },
   68 #               {
   69 #                   'name' => 'git submodule handling (github issue #131 T1)',
   70 #                   'cd'   => '../tests/inputs',
   71 #                   'args' => 'issues/131',
   72 #                   'ref'  => '../tests/outputs/issues/131/T1.yaml',
   73 #               },
   74 #               {
   75 #                   'name' => 'git submodule handling (github issue #131 T2)',
   76 #                   'cd'   => '../tests/inputs',
   77 #                   'args' => '--vcs git issues/131',
   78 #                   'ref'  => '../tests/outputs/issues/131/T2.yaml',
   79 #               },
   80                 {
   81                     'name' => 'all files (github issue #132 T1)',
   82                     'cd'   => '../tests/inputs',
   83                     'args' => 'issues/132',
   84                     'ref'  => '../tests/outputs/issues/132/T1.yaml',
   85                 },
   86                 {
   87                     'name' => '--vcs git issues/132 (github issue #132 T2)',
   88                     'cd'   => '../tests/inputs',
   89                     'args' => '--vcs git issues/132',
   90                     'ref'  => '../tests/outputs/issues/132/T2.yaml',
   91                 },
   92                 {
   93                     'name' => '--vcs-git --exclude-dir ignore_dir (github issue #132 T3)',
   94                     'cd'   => '../tests/inputs/issues/132',
   95                     'args' => '--vcs git --exclude-dir ignore_dir .',
   96                     'ref'  => '../tests/outputs/issues/132/T3.yaml',
   97                 },
   98                 {
   99                     'name' => '--vcs git --fullpath --not-match-d issues/132/ignore_dir (github issue #132 T4)',
  100                     'cd'   => '../tests/inputs',
  101                     'args' => '--vcs git --fullpath --not-match-d issues/132/ignore_dir issues/132',
  102                     'ref'  => '../tests/outputs/issues/132/T4.yaml',
  103                 },
  104                 {
  105                     'name' => '--vcs git --match-f C-Ansi (github issue #132 T5)',
  106                     'cd'   => '../tests/inputs',
  107                     'args' => '--vcs git --match-f C-Ansi issues/132',
  108                     'ref'  => '../tests/outputs/issues/132/T5.yaml',
  109                 },
  110                 {
  111                     'name' => '--vcs git --match-f "\.c$" (github issue #132 T6)',
  112                     'cd'   => '../tests/inputs',
  113                     'args' => '--vcs git --match-f "\.c$" issues/132',
  114                     'ref'  => '../tests/outputs/issues/132/T6.yaml',
  115                 },
  116                 {
  117                     'name' => '--vcs "find X" (github issue #147)',
  118                     'cd'   => '../tests/inputs',
  119                     'args' => '--vcs "find foo_bar"',
  120                     'ref'  => '../tests/outputs/issues/147/T1.yaml',
  121                 },
  122                 {
  123                     'name' => '--read-lang-def w/remove_between_general (github issue #166)',
  124                     'cd'   => '../tests/inputs/issues/166',
  125                     'args' => '--read-lang-def X fake.thy',
  126                     'ref'  => '../tests/outputs/issues/166/fake.thy.yaml',
  127                 },
  128                 {
  129                     'name' => '--read-lang-def w/triple_extension',
  130                     'cd'   => '../tests/inputs',
  131                     'args' => '--read-lang-def triple_lang_def.txt custom.triple.extension.js',
  132                     'ref'  => '../tests/outputs/custom.triple.extension.js.yaml',
  133                 },
  134                 {
  135                     'name' => 'Forth balanced parentheses #1 (github issue #183)',
  136                     'cd'   => '../tests/inputs/issues/183',
  137                     'args' => 'file.fth',
  138                     'ref'  => '../tests/outputs/issues/183/file.fth.yaml',
  139                 },
  140                 {
  141                     'name' => 'Forth balanced parentheses #2 (github issue #183)',
  142                     'cd'   => '../tests/inputs/issues/183',
  143                     'args' => 'eval1957.SACunidir.fr',
  144                     'ref'  => '../tests/outputs/issues/183/eval1957.SACunidir.fr.yaml',
  145                 },
  146                 {
  147                     'name' => 'diff identical files (github issue #280)',
  148                     'cd'   => '../tests/inputs/issues/280',
  149                     'args' => '--diff L R',
  150                     'ref'  => '../tests/outputs/issues/280/280.yaml',
  151                 },
  152                 {
  153                     'name' => 'diff identical files by file (github issue #280)',
  154                     'cd'   => '../tests/inputs/issues/280',
  155                     'args' => '--by-file --diff L R',
  156                     'ref'  => '../tests/outputs/issues/280/280_by_file.yaml',
  157                 },
  158 
  159                 {
  160                     'name' => '--follow-links, --not-match-d, --fullpath  1/6 (github issue #286)',
  161                     'cd'   => '../tests/inputs/issues/286',
  162                     'args' => '               --not-match-d ignore_subdir                    project',
  163                     'ref'  => '../tests/outputs/issues/286/1.yaml',
  164                 },
  165 
  166                 {
  167                     'name' => '--follow-links, --not-match-d, --fullpath  2/6 (github issue #286)',
  168                     'cd'   => '../tests/inputs/issues/286',
  169                     'args' => '--follow-links --not-match-d ignore_subdir                    project',
  170 
  171                     'ref'  => '../tests/outputs/issues/286/2.yaml',
  172                 },
  173 
  174                 {
  175                     'name' => '--follow-links, --not-match-d, --fullpath  3/6 (github issue #286)',
  176                     'cd'   => '../tests/inputs/issues/286',
  177                     'args' => '               --not-match-d ignore_subdir --fullpath         project',
  178 
  179                     'ref'  => '../tests/outputs/issues/286/3.yaml',
  180                 },
  181 
  182                 {
  183                     'name' => '--follow-links, --not-match-d, --fullpath  4/6 (github issue #286)',
  184                     'cd'   => '../tests/inputs/issues/286',
  185                     'args' => '--follow-links --not-match-d ignore_subdir --fullpath         project',
  186                     'ref'  => '../tests/outputs/issues/286/4.yaml',
  187                 },
  188 
  189                 {
  190                     'name' => '--follow-links, --not-match-d, --fullpath  5/6 (github issue #286)',
  191                     'cd'   => '../tests/inputs/issues/286',
  192                     'args' => '               --not-match-d project/ignore_subdir --fullpath project',
  193                     'ref'  => '../tests/outputs/issues/286/5.yaml',
  194                 },
  195 
  196                 {
  197                     'name' => '--follow-links, --not-match-d, --fullpath  6/6 (github issue #286)',
  198                     'cd'   => '../tests/inputs/issues/286',
  199                     'args' => '--follow-links --not-match-d project/ignore_subdir --fullpath project',
  200                     'ref'  => '../tests/outputs/issues/286/6.yaml',
  201                 },
  202 
  203                 {
  204                     'name' => '--include-ext m,lua (github issue #296)',
  205                     'cd'   => '../tests/inputs/issues/296',
  206                     'args' => '--include-ext m,lua .',
  207                     'ref'  => '../tests/outputs/issues/296/results.yaml',
  208                 },
  209 
  210                 {
  211                     'name' => '--strip-str-comments (github issue #245)',
  212                     'cd'   => '../tests/inputs/issues/245',
  213                     'args' => '--strip-str-comments .',
  214                     'ref'  => '../tests/outputs/issues/245/CRS.scala.yaml',
  215                 },
  216 
  217                 {
  218                     'name' => 'YAML --by-file output with unusual filename (github issue #312)',
  219                     'cd'   => '../tests/inputs/issues/312',
  220                     'args' => '--by-file .',
  221                     'ref'  => '../tests/outputs/issues/312/results.yaml',
  222                 },
  223 
  224                 {
  225                     'name' => 'custom Smarty definition (github issue #327)',
  226                     'cd'   => '../tests/inputs/issues/327',
  227                     'args' => '--force-lang-def=lang.config example.smarty2',
  228                     'ref'  => '../tests/outputs/issues/327/results.yaml',
  229                 },
  230 
  231                 {
  232                     'name' => 'UTF-8 output file encoding',
  233                     'cd'   => '../tests/inputs/issues/318',
  234                     'args' => '--by-file --file-encoding utf8 R*.cs',
  235                     'ref'  => '../tests/inputs/issues/318/Rcs.yaml',  # results in input dir
  236                 },
  237 
  238                 {
  239                     'name' => 'distinguish TeX from VB (github issue #341)',
  240                     'cd'   => '../tests/inputs/issues/341',
  241                     'args' => '.',
  242                     'ref'  => '../tests/outputs/issues/341/results.yaml',
  243                 },
  244 
  245                 {
  246                     'name' => '--strip-str-comments (github issue #350)',
  247                     'cd'   => '../tests/inputs/issues/350',
  248                     'args' => '--strip-str-comments .',
  249                     'ref'  => '../tests/outputs/issues/350/fs.go.yaml',
  250                 },
  251 
  252                 {
  253                     'name' => 'Java comments in strings, issue #365',
  254                     'cd'   => '../tests/inputs/issues/365',
  255                     'args' => 'RSpecTests.java',
  256                     'ref'  => '../tests/outputs/issues/365/results.yaml',
  257                 },
  258 
  259                 {
  260                     'name' => 'Arduino IDE 0xA0 characters',
  261                     'cd'   => '../tests/inputs/issues/370',
  262                     'args' => 'arduino_issue_370.ino',
  263                     'ref'  => '../tests/outputs/issues/370/results.yaml',
  264                 },
  265 
  266                 {
  267                     'name' => 'Python docstrings --docstring-as-code',
  268                     'cd'   => '../tests/inputs/issues/375',
  269                     'args' => '--docstring-as-code docstring.py',
  270                     'ref'  => '../tests/outputs/issues/375/results.yaml',
  271                 },
  272 
  273                 {
  274                     'name' => 'Perl v. Prolog',
  275                     'cd'   => '../tests/inputs/issues/380',
  276                     'args' => 'wrapper.pl',
  277                     'ref'  => '../tests/outputs/issues/380/wrapper.pl.yaml',
  278                 },
  279 
  280                 {
  281                     'name' => 'Java comments and continuation lines issue 381',
  282                     'cd'   => '../tests/inputs/issues/381',
  283                     'args' => 'issue381.java',
  284                     'ref'  => '../tests/outputs/issues/381/issue381.java.yaml',
  285                 },
  286 
  287                 {
  288                     'name' => 'C comments w/ backslashed quote in strings issue 381',
  289                     'cd'   => '../tests/inputs/issues/381',
  290                     'args' => '--strip-str-comments issue381.c',
  291                     'ref'  => '../tests/outputs/issues/381/issue381.c.yaml',
  292                 },
  293 
  294                 {
  295                     'name' => '--exclude-content issue 396',
  296                     'cd'   => '../tests/inputs',
  297                     'args' => '--exclude-content Lambda acpclust.R sample.R utilities.R',
  298                     'ref'  => '../tests/outputs/issues/396/excl.yaml',
  299                 },
  300 
  301                 {
  302                     'name' => '--exclude-content w/--diff issue 396',
  303                     'cd'   => '../tests/inputs/issues/280',
  304                     'args' => '--exclude-content Copyright --diff L R',
  305                     'ref'  => '../tests/outputs/issues/396/excl_diff.yaml',
  306                 },
  307 
  308                 {
  309                     'name' => 'Python with /* in strings issue 405',
  310                     'cd'   => '../tests/inputs/issues/405',
  311                     'args' => 'globs.py',
  312                     'ref'  => '../tests/outputs/issues/405/globs.py.yaml',
  313                 },
  314 
  315                 {
  316                     'name' => '--exclude-dir and --follow-link, #407 1/3',
  317                     'cd'   => '../tests/inputs/issues/407',
  318                     'args' => '--follow-link --exclude-dir Test count_dir',
  319                     'ref'  => '../tests/outputs/issues/407/results1.yaml',
  320                 },
  321 
  322                 {
  323                     'name' => '--exclude-dir and --follow-link, #407 2/3',
  324                     'cd'   => '../tests/inputs/issues/407',
  325                     'args' => '--exclude-dir Test level2',
  326                     'ref'  => '../tests/outputs/issues/407/results2.yaml',
  327                 },
  328 
  329                 {
  330                     'name' => '--exclude-dir and --follow-link, #407 3/3',
  331                     'cd'   => '../tests/inputs/issues/407',
  332                     'args' => '--follow-link --exclude-dir Test level2',
  333                     'ref'  => '../tests/outputs/issues/407/results3.yaml',
  334                 },
  335 
  336                 {
  337                     'name' => 'doubly counted she-bang line, #408',
  338                     'cd'   => '../tests/inputs/issues/408',
  339                     'args' => 'badly_named_ruby.pl',
  340                     'ref'  => '../tests/outputs/issues/408/badly_named_ruby.yaml',
  341                 },
  342 
  343                 {
  344                     'name' => 'case insensitive file ext, #420',
  345                     'cd'   => '../tests/inputs/issues/420',
  346                     'args' => '--ignore-case-ext .',
  347                     'ref'  => '../tests/outputs/issues/420/results.yaml',
  348                 },
  349 
  350                 {
  351                     'name' => 'diff with --exclude-list-file, #433',
  352                     'cd'   => '../tests/inputs/issues/433',
  353                     'args' => '--exclude-list-file excl.txt --by-file --follow-links --diff L R
  354                     ',
  355                     'ref'  => '../tests/outputs/issues/433/results.yaml',
  356                 },
  357                 {
  358                     'name' => 'JavaScript comment in string, #454',
  359                     'cd'   => '../tests/inputs/issues/454',
  360                     'args' => '--strip-str-comments createServer.js',
  361                     'ref'  => '../tests/outputs/issues/454/createServer.js.yaml',
  362                 },
  363                 {
  364                     'name' => 'XML with no extension, #456',
  365                     'cd'   => '../tests/inputs/issues/456',
  366                     'args' => 'XML_no_ext',
  367                     'ref'  => '../tests/outputs/issues/456/XML_no_ext.yaml',
  368                 },
  369                 {
  370                     'name' => 'XML with unusual extension, #456',
  371                     'cd'   => '../tests/inputs/issues/456',
  372                     'args' => 'XML_weird_ext.profile',
  373                     'ref'  => '../tests/outputs/issues/456/XML_weird_ext.profile.yaml',
  374                 },
  375                 {
  376                     'name' => 'ignore Algorithm::Diff::sdiff() failures, #463',
  377                     'cd'   => '../tests/inputs/issues/463',
  378                     'args' => '--diff left.C right.C',
  379                     'ref'  => '../tests/outputs/issues/463/diff.yaml',
  380                 },
  381                 {
  382                     'name' => 'diff list input format 1, #455',
  383                     'cd'   => '../',
  384                     'args' => '--diff-list-file tests/inputs/issues/455/list.txt',
  385                     'ref'  => '../tests/outputs/issues/455/list.yaml',
  386                 },
  387                 {
  388                     'name' => 'diff list input format 2, #455',
  389                     'cd'   => '../',
  390                     'args' => '--diff-list-file tests/inputs/issues/455/list_align.txt',
  391                     'ref'  => '../tests/outputs/issues/455/list_align.yaml',
  392                 },
  393                 {
  394                     'name' => 'replace_regex with null, #472',
  395                     'cd'   => '../tests/inputs/issues/472',
  396                     'args' => '--force-lang-def lua_def.txt not_really.lua',
  397                     'ref'  => '../tests/outputs/issues/472/not_really.lua.yaml',
  398                 },
  399                 {
  400                     'name' => '--exclude-lang --diff 1/3, #476',
  401                     'cd'   => '../tests/inputs/issues/476',
  402                     'args' => '--diff A B',
  403                     'ref'  => '../tests/outputs/issues/476/all.yaml',
  404                 },
  405                 {
  406                     'name' => '--exclude-lang --diff 2/3, #476',
  407                     'cd'   => '../tests/inputs/issues/476',
  408                     'args' => "--exclude-lang 'Fortran 90' --diff A B",
  409                     'ref'  => '../tests/outputs/issues/476/no_fortran.yaml',
  410                 },
  411                 {
  412                     'name' => '--exclude-lang --diff 3/3, #476',
  413                     'cd'   => '../tests/inputs/issues/476',
  414                     'args' => "--exclude-lang C++ --diff A B",
  415                     'ref'  => '../tests/outputs/issues/476/no_cpp.yaml',
  416                 },
  417                 # Next test, 482, requires an empty directory B.  Git
  418                 # does not like this so create it at runtime.
  419                 {
  420                     'name' => '--include-lang --diff, #482',
  421                     'cd'   => '../tests/inputs/issues/482',
  422                     'args' => '--include-lang C --diff A B',
  423                     'ref'  => '../tests/outputs/issues/482/results.yaml',
  424                 },
  425 
  426 #               {
  427 #                   'name' => '--count-and--diff with --out',
  428 #                   'cd'   => '../tests/inputs/issues/220',
  429 #                   'args' => '--count-and-diff ../../aa ../../dd',
  430 #                   'ref'  => '../tests/outputs/issues/220/rpt.yaml.diff..._.._aa..._.._dd',
  431 #               },
  432             );
  433 
  434 # Create test input for issue #132 which needs data not in the git repo.
  435 # Silently fail if file/dir already exists.
  436 mkdir "../tests/inputs/issues/132/ignore_git";
  437 cp    "../tests/inputs/hi.py", "../tests/inputs/issues/132/ignore_git/";
  438 
  439 my $missing_dir = "../tests/inputs/issues/482/B";
  440 if (!-d $missing_dir) {
  441     mkdir $missing_dir;
  442 }
  443 
  444 my $Verbose = 0;
  445 
  446 my $results = 'results.yaml';
  447 my $work_dir = getcwd;
  448 my $cloc     = "$work_dir/../cloc";   # all-purpose version
  449 #my $cloc     = "$work_dir/cloc";      # Unix-tuned version
  450 my $Run = "$cloc --quiet --yaml --out $results ";
  451 foreach my $t (@Tests) {
  452     chdir($t->{'cd'}) if defined $t->{'cd'};
  453     print "Run  dir= ", cwd(), "\n" if $Verbose;
  454     print  $Run . $t->{'args'} if $Verbose;
  455     system($Run . $t->{'args'});
  456     ok(-e $results, $t->{'name'} . " created output");
  457     my %this = load_yaml($results);
  458     unlink $results unless $Verbose;
  459     chdir($work_dir) if defined $t->{'cd'};
  460     print "Load dir= ", cwd(), "\n" if $Verbose;
  461     my %ref  = load_yaml($t->{'ref'});
  462 
  463 #   my $REF = LoadFile($t->{'ref'});  # using official YAML module
  464 #   is_deeply($REF , \%this, $t->{'name'} . " results match");
  465 
  466 #   use Data::Dumper;
  467 #   print Dumper(\%ref);
  468 #   print Dumper(\%this);
  469 
  470     is_deeply(\%ref, \%this, $t->{'name'} . " results match");
  471 }
  472 done_testing();
  473 
  474 sub load_yaml { # {{{1
  475     my ($file, ) = @_;
  476     my %result = ();
  477     if (!-r $file) {
  478         warn "File not found: $file\n";
  479         return %result;
  480     }
  481     open IN, $file or return %result;
  482     my $section = undef;
  483     while (<IN>) {
  484         next if /^\s*#/ or /^--/;
  485         if (/^\s*'?(.*?)'?\s*:\s*$/) {
  486             $section = $1;
  487             next;
  488         }
  489         next unless defined $section;
  490         next if $section eq 'header';
  491         chomp;
  492         s/\s+//g;
  493         my ($K, $V) = split(':');
  494         $result{$section}{$K} = $V;
  495     }
  496     close IN;
  497     return %result
  498 } # 1}}}