Skip to content

Commit

Permalink
regression test for github issue AlDanial#82
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed May 20, 2016
1 parent 17e9e05 commit 57f26a3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions Unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test-pod:
# Rule: test-code - Check that the counter works
test-code:
t/00_C.t
t/01_opts.t

# Rule: test - Run tests
test: test-perl test-pod test-code
Expand Down
51 changes: 51 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env perl
use warnings;
use strict;
use Test::More;
my @Tests = ( {
'name' => 'exclude dir 1 (github issue #82)',
'args' => '--exclude-dir cc ../tests/inputs/dd',
'ref' => '../tests/outputs/exclude_dir_1.yaml',
},

);

my $Verbose = 0;

my $results = 'results.yaml';
my $Run = "../cloc --quiet --yaml --out $results ";
foreach my $t (@Tests) {
print $Run . $t->{'args'} if $Verbose;
system($Run . $t->{'args'});
ok(-e $results, $t->{'name'} . " created output");
my %ref = load_yaml($t->{'ref'});
my %this = load_yaml($results);
is_deeply(\%ref, \%this, $t->{'name'} . " results match");
}
done_testing();

sub load_yaml {
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 (/^(\w+)\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
}
26 changes: 26 additions & 0 deletions tests/outputs/exclude_dir_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.67
elapsed_seconds : 0.0140111446380615
n_files : 2
n_lines : 374
files_per_second : 142.743512515527
lines_per_second : 26693.0368404036
report_file : ../tests/outputs/exclude_dir_1.yaml
C++ :
nFiles: 1
blank: 49
comment: 55
code: 182
C :
nFiles: 1
blank: 22
comment: 22
code: 44
SUM:
blank: 71
comment: 77
code: 226
nFiles: 2

0 comments on commit 57f26a3

Please sign in to comment.