| @@ -1,62 +1,95 @@ | | | @@ -1,62 +1,95 @@ |
1 | #! @PERL@ | | 1 | #! @PERL@ |
2 | # $NetBSD: pkglint.t,v 1.2 2013/01/20 02:57:37 schmonz Exp $ | | 2 | # $NetBSD: pkglint.t,v 1.3 2013/01/20 03:50:05 schmonz Exp $ |
3 | # | | 3 | # |
4 | | | 4 | |
5 | require 'pkglint.pl'; # so we can test its internals | | 5 | require 'pkglint.pl'; # so we can test its internals |
6 | $main::program = 'pkglint.pl'; # because it self-greps for vartypes | | 6 | $main::program = 'pkglint.pl'; # because it self-greps for vartypes |
7 | | | 7 | |
8 | package PkgLint::Test; # pkglint.pl uses 'main', so we mustn't | | 8 | package PkgLint::Test; # pkglint.pl uses 'main', so we mustn't |
9 | | | 9 | |
10 | use Test::More tests => 17; | | 10 | use Test::More tests => 28; |
11 | use Test::Trap; | | 11 | use Test::Trap; |
12 | | | 12 | |
13 | use warnings; | | 13 | use warnings; |
14 | use strict; | | 14 | use strict; |
15 | | | 15 | |
16 | sub test_unit { | | 16 | sub test_unit { |
17 | my ($unit, $params, $exitcode, $stdout_re, $stderr_re) = @_; | | 17 | my ($unit, $params, $exitcode, $stdout_re, $stderr_re) = @_; |
18 | | | 18 | |
19 | my @results = trap { $unit->(@{$params}) }; | | 19 | my @results = trap { $unit->(@{$params}) }; |
20 | | | 20 | |
21 | if (defined $exitcode) { | | 21 | if (defined $exitcode) { |
22 | is($trap->exit, $exitcode, qq{exits $exitcode}); | | 22 | is($trap->exit, $exitcode, qq{exits $exitcode}); |
23 | } else { | | 23 | } else { |
24 | is($trap->exit, undef, q{doesn't exit}); | | 24 | is($trap->exit, undef, q{doesn't exit}); |
25 | } | | 25 | } |
26 | like($trap->stdout, qr/$stdout_re/, qq{stdout matches $stdout_re}); | | 26 | like($trap->stdout, qr/$stdout_re/, qq{stdout matches $stdout_re}); |
27 | like($trap->stderr, qr/$stderr_re/, qq{stderr matches $stderr_re}); | | 27 | like($trap->stderr, qr/$stderr_re/, qq{stderr matches $stderr_re}); |
28 | | | 28 | |
29 | return @results; | | 29 | return @results; |
30 | } | | 30 | } |
31 | | | 31 | |
32 | sub test_get_vartypes_basictypes { | | 32 | sub test_get_vartypes_basictypes { |
33 | my $unit = \&main::get_vartypes_basictypes; | | 33 | my $unit = \&main::get_vartypes_basictypes; |
34 | | | 34 | |
35 | my @results = test_unit($unit, undef, undef, '^$', '^$'); | | 35 | my @results = test_unit($unit, undef, undef, '^$', '^$'); |
36 | my %types = %{$results[0]}; | | 36 | my %types = %{$results[0]}; |
37 | is($types{YesNo_Indirectly}, 1, q{a couple expected types are here}); | | | |
38 | is($types{BuildlinkDepmethod}, 1, q{a couple expected types are here}); | | 37 | is($types{BuildlinkDepmethod}, 1, q{a couple expected types are here}); |
| | | 38 | is($types{YesNo_Indirectly}, 1, q{a couple expected types are here}); |
| | | 39 | } |
| | | 40 | |
| | | 41 | sub test_get_vartypes_map { |
| | | 42 | my $unit = \&main::get_vartypes_map; |
| | | 43 | |
| | | 44 | my @results = test_unit($unit, undef, undef, '^$', '^$'); |
| | | 45 | my %map = %{$results[0]}; |
| | | 46 | is($map{'BSD_MAKE_ENV'}->basic_type(), 'ShellWord', |
| | | 47 | q{a couple expected vars are typed right}); |
| | | 48 | is($map{'USE_BUILTIN.*'}->basic_type(), 'YesNo_Indirectly', |
| | | 49 | q{a couple expected vars are typed right}); |
| | | 50 | } |
| | | 51 | |
| | | 52 | sub test_checkline_mk_vartype_basic { |
| | | 53 | # this is what gets self-grepped: all that "elsif ($type eq" |
| | | 54 | # sub doesn't return anything, just warns or errors if need be |
| | | 55 | # |
| | | 56 | # TODO: |
| | | 57 | # |
| | | 58 | # test a shallow one and then a deeply nested one |
| | | 59 | # (type='Restricted', value='incorrect') |
| | | 60 | # (type='Restricted', value='RESTRICTED') |
| | | 61 | # (type='SedCommands', a few different values') |
| | | 62 | # once test coverage is persuasive, refactor to a dispatch table |
| | | 63 | # once refactored, get rid of the $main::program global |
39 | } | | 64 | } |
40 | | | 65 | |
41 | sub test_main { | | 66 | sub test_main { |
42 | my $unit = \&main::main; | | 67 | my $unit = \&main::main; |
43 | | | 68 | |
44 | @ARGV = ('-h'); | | 69 | @ARGV = ('-h'); |
45 | test_unit($unit, undef, 0, '^usage: pkglint ', '^$'); | | 70 | test_unit($unit, undef, 0, '^usage: pkglint ', '^$'); |
46 | | | 71 | |
47 | @ARGV = (); | | 72 | @ARGV = (); |
48 | test_unit($unit, undef, 1, '^ERROR:.+how to check', '^$'); | | 73 | test_unit($unit, undef, 1, '^ERROR:.+how to check', '^$'); |
49 | | | 74 | |
50 | @ARGV = ('.'); | | 75 | @ARGV = ('.'); |
51 | test_unit($unit, undef, 1, '^ERROR:.+how to check', '^$'); | | 76 | test_unit($unit, undef, 1, '^ERROR:.+how to check', '^$'); |
52 | | | 77 | |
53 | @ARGV = ('..'); | | 78 | @ARGV = ('..'); |
54 | test_unit($unit, undef, 1, '^ERROR:.+LICENSE', '^$'); | | 79 | test_unit($unit, undef, 1, '^ERROR:.+LICENSE', '^$'); |
| | | 80 | |
| | | 81 | @ARGV = ('/does/not/exist'); |
| | | 82 | test_unit($unit, undef, 1, '^ERROR:.+not exist', '^$'); |
| | | 83 | |
| | | 84 | @ARGV = ($ENV{HOME}); |
| | | 85 | test_unit($unit, undef, 1, '^ERROR:.+outside a pkgsrc', '^$'); |
55 | } | | 86 | } |
56 | | | 87 | |
57 | sub main { | | 88 | sub main { |
58 | test_get_vartypes_basictypes(); | | 89 | test_get_vartypes_basictypes(); |
| | | 90 | test_get_vartypes_map(); |
| | | 91 | test_checkline_mk_vartype_basic(); |
59 | test_main(); | | 92 | test_main(); |
60 | } | | 93 | } |
61 | | | 94 | |
62 | main(); | | 95 | main(); |