| File: | t/lib/ShellTest.pm |
| Coverage: | 100.0% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 2 2 2 | 0 0 0 | use strict; | ||||
| 2 | 2 2 2 | 0 0 0 | use warnings; | ||||
| 3 | |||||||
| 4 | package ShellTest; | ||||||
| 5 | |||||||
| 6 | 2 2 2 | 0 0 0 | use parent 'Test::Class::TestGroup'; | ||||
| 7 | |||||||
| 8 | 2 2 2 | 0 0 0 | use Test::More; | ||||
| 9 | 2 2 2 | 0 0 0 | use Test::BinRegression; | ||||
| 10 | 2 2 2 | 0 0 0 | use File::Slurp 'read_file'; | ||||
| 11 | |||||||
| 12 | 2 2 2 | 0 0 0 | use Code::Statistics::App; | ||||
| 13 | |||||||
| 14 | sub make_fixture : Test(setup) { | ||||||
| 15 | 4 | 0 | my ( $self ) = @_; | ||||
| 16 | |||||||
| 17 | 4 | 0 | $self->{basic_collect_args} = [ qw( | ||||
| 18 | collect | ||||||
| 19 | --dirs=data/shelltest/basic_collect | ||||||
| 20 | --relative_paths | ||||||
| 21 | --foreign_paths=Unix | ||||||
| 22 | --conf_file=data/config/shelltestrc | ||||||
| 23 | --global_conf_file=data/config/does_not_exist | ||||||
| 24 | ) ]; | ||||||
| 25 | |||||||
| 26 | 4 | 0 | return; | ||||
| 27 | 2 2 2 | 0 0 0 | } | ||||
| 28 | |||||||
| 29 | sub basic_collect : TestGroup { | ||||||
| 30 | 2 | 0 | my ( $self ) = @_; | ||||
| 31 | |||||||
| 32 | 2 2 | 0 0 | local @ARGV = @{ $self->{basic_collect_args} }; | ||||
| 33 | |||||||
| 34 | 2 | 0 | $self->check_codestat_shell_app_against( "data/json/basic_collect.json" ); | ||||
| 35 | |||||||
| 36 | 2 | 0 | ok( -e 'codestat.out', 'output file is generated' ); | ||||
| 37 | |||||||
| 38 | ok_regression( | ||||||
| 39 | 2 | 0 | sub { $self->get_codestat_out_file }, | ||||
| 40 | 2 | 0 | "data/json/basic_collect.json", | ||||
| 41 | 'dumped file matches expected output' | ||||||
| 42 | ); | ||||||
| 43 | |||||||
| 44 | 2 | 0 | @ARGV = qw( report --quiet --file_ignore=;Ignored ); | ||||
| 45 | |||||||
| 46 | 2 | 0 | $self->check_codestat_shell_app_against( "data/json/basic_report.json" ); | ||||
| 47 | |||||||
| 48 | 2 | 0 | unlink( 'codestat.out' ); | ||||
| 49 | |||||||
| 50 | 2 | 0 | return; | ||||
| 51 | 2 2 2 | 0 0 0 | } | ||||
| 52 | |||||||
| 53 | sub nodump_collect : TestGroup { | ||||||
| 54 | 2 | 0 | my ( $self ) = @_; | ||||
| 55 | |||||||
| 56 | 2 | 0 | local @ARGV = ( | ||||
| 57 | 2 | 0 | @{$self->{basic_collect_args}}, | ||||
| 58 | qw( --no_dump ) | ||||||
| 59 | ); | ||||||
| 60 | |||||||
| 61 | 2 | 0 | $self->check_codestat_shell_app_against( "data/json/basic_collect.json" ); | ||||
| 62 | |||||||
| 63 | 2 | 0 | ok( !-e 'codestat.out', '--no_dump does not generate a file' ); | ||||
| 64 | |||||||
| 65 | 2 | 0 | return; | ||||
| 66 | 2 2 2 | 0 0 0 | } | ||||
| 67 | |||||||
| 68 | sub check_codestat_shell_app_against { | ||||||
| 69 | 6 | 0 | my ( $self, $file ) = @_; | ||||
| 70 | |||||||
| 71 | ok_regression( | ||||||
| 72 | sub { | ||||||
| 73 | 6 | 0 | my $result = Code::Statistics::App->run; | ||||
| 74 | 6 | 0 | return $result; | ||||
| 75 | }, | ||||||
| 76 | 6 | 0 | $file, | ||||
| 77 | 'returned string matches expected output', | ||||||
| 78 | 'binmode', | ||||||
| 79 | ); | ||||||
| 80 | |||||||
| 81 | 6 | 0 | return; | ||||
| 82 | } | ||||||
| 83 | |||||||
| 84 | sub get_codestat_out_file { | ||||||
| 85 | 2 | 0 | my $result = read_file('codestat.out'); | ||||
| 86 | 2 | 0 | return $result; | ||||
| 87 | } | ||||||
| 88 | |||||||
| 89 | 1; | ||||||