From: Peter Rabbitson Date: Wed, 18 Dec 2013 13:50:36 +0000 (+0100) Subject: Port whitespace cleanup from master 428975b0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2a0d52b0905ead92f31996b24e1428464c8f674;p=dbsrgits%2FSQL-Abstract.git Port whitespace cleanup from master 428975b0 Reducing diffnoise in the upcoming merge --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index c8f470b..46a9e39 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -267,11 +267,9 @@ sub _quote { sub _assert_pass_injection_guard { if ($_[1] =~ $_[0]->{injection_guard}) { my $class = ref $_[0]; - die "Possible SQL injection attempt '$_[1]'. If this is indeed a part of the - " - . "desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply your own -" - . "{injection_guard} attribute to ${class}->new()" + die "Possible SQL injection attempt '$_[1]'. If this is indeed a part of " + . "the desired SQL use literal SQL ( \'...' or \[ '...' ] ) or supply " + . "your own {injection_guard} attribute to ${class}->new()" } } diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index f54a478..1bae6c3 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -638,13 +638,13 @@ sub _order_by_to_dq { $dq->{by} = $$arg; } elsif (ref($arg) eq 'SCALAR') { - # < mst> right, but if it doesn't match that, it goes "ok, right, not sure, + # < mst> right, but if it doesn't match that, it goes "ok, right, not sure, # totally leaving this untouched as a literal" # < mst> so I -think- it's relatively robust # < ribasushi> right, it's relatively safe then # < ribasushi> is this regex centralized? # < mst> it only exists in _order_by_to_dq in SQL::Abstract::Converter - # < mst> it only exists because you were kind enough to support new + # < mst> it only exists because you were kind enough to support new # dbihacks crack combined with old literal order_by crack # < ribasushi> heh :) diff --git a/t/00new.t b/t/00new.t index 29646e0..bbba692 100644 --- a/t/00new.t +++ b/t/00new.t @@ -15,7 +15,7 @@ my @handle_tests = ( # stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' # LDNOTE: modified the line above (changing the test suite!!!) because # the test was not consistent with the doc: hashrefs should not be -# influenced by the current logic, they always mean 'AND'. So +# influenced by the current logic, they always mean 'AND'. So # { a => 4, b => 0} should ALWAYS mean ( a = ? AND b = ? ). # # acked by RIBASUSHI @@ -92,11 +92,11 @@ my @handle_tests = ( { args => {convert => "upper"}, stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )', - where => [ { ticket => [11, 12, 13], + where => [ { ticket => [11, 12, 13], hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, { tack => { between => [qw/tick tock/] } }, - { a => [qw/b c d/], - e => { '!=', [qw(f g)] }, + { a => [qw/b c d/], + e => { '!=', [qw(f g)] }, q => { 'not in', [14..20] } } ], }, ); diff --git a/t/02where.t b/t/02where.t index 920534d..9ea045b 100644 --- a/t/02where.t +++ b/t/02where.t @@ -106,7 +106,7 @@ my @handle_tests = ( }, { - where => { + where => { priority => [ {'>', 3}, {'<', 1} ], requestor => \'is not null', }, @@ -116,7 +116,7 @@ my @handle_tests = ( }, { - where => { + where => { requestor => { '!=', ['-and', undef, ''] }, }, stmt => " WHERE ( requestor IS NOT NULL AND requestor != ? )", @@ -124,9 +124,9 @@ my @handle_tests = ( }, { - where => { + where => { priority => [ {'>', 3}, {'<', 1} ], - requestor => { '!=', undef }, + requestor => { '!=', undef }, }, order => [qw/a b c d e f g/], stmt => " WHERE ( ( ( priority > ? ) OR ( priority < ? ) ) AND requestor IS NOT NULL )" @@ -135,9 +135,9 @@ my @handle_tests = ( }, { - where => { + where => { priority => { 'between', [1, 3] }, - requestor => { 'like', undef }, + requestor => { 'like', undef }, }, order => \'requestor, ticket', #LDNOTE: modified parentheses @@ -149,12 +149,12 @@ my @handle_tests = ( { - where => { - id => 1, - num => { - '<=' => 20, - '>' => 10, - }, + where => { + id => 1, + num => { + '<=' => 20, + '>' => 10, + }, }, # LDNOTE : modified test below, just parentheses differ # @@ -406,7 +406,7 @@ for my $case (@handle_tests) { local $Data::Dumper::Terse = 1; my $sql = SQL::Abstract->new; my($stmt, @bind); - ok(!(my $e = exception { + ok(!(my $e = exception { ($stmt, @bind) = $sql->where($case->{where}, $case->{order}); is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind}) || diag "Search term:\n" . Dumper $case->{where}; diff --git a/t/03values.t b/t/03values.t index b3ab252..7ebb7fc 100644 --- a/t/03values.t +++ b/t/03values.t @@ -91,7 +91,7 @@ for my $record (@data) { { my $sql = SQL::Abstract->new; - my $data = { + my $data = { event => 'rapture', stuff => 'fluff', time => \ 'now()', diff --git a/t/04modifiers.t b/t/04modifiers.t index efa95a4..7cb4d2c 100644 --- a/t/04modifiers.t +++ b/t/04modifiers.t @@ -26,7 +26,7 @@ Test -and -or and -nest modifiers, assuming the following: limitation of one modifier type per hahsref) * When in condition context i.e. where => { -or { a = 1 } }, each modifier affects only the immediate element following it. - * When in column multi-condition context i.e. + * When in column multi-condition context i.e. where => { x => { '!=', [-and, [qw/1 2 3/]] } }, a modifier affects the OUTER ARRAYREF if and only if it is the first element of said ARRAYREF @@ -77,7 +77,7 @@ my @and_or_tests = ( %{$and_or_args->{or}}, }, - # test modifiers within hashrefs + # test modifiers within hashrefs { where => { -or => [ [ foo => 1, bar => 2 ], @@ -93,7 +93,7 @@ my @and_or_tests = ( %{$and_or_args->{or_and}}, }, - # test modifiers within arrayrefs + # test modifiers within arrayrefs { where => [ -or => [ [ foo => 1, bar => 2 ], @@ -171,8 +171,8 @@ my @and_or_tests = ( # the -and should affect the OUTER arrayref, while the internal structures remain intact { - where => { x => [ - -and => [ 1, 2 ], { -like => 'x%' } + where => { x => [ + -and => [ 1, 2 ], { -like => 'x%' } ]}, stmt => 'WHERE (x = ? OR x = ?) AND x LIKE ?', bind => [qw/1 2 x%/], @@ -218,7 +218,7 @@ my @and_or_tests = ( bind => [1 .. 13], }, - # 1st -and is in column mode, thus flips the entire array, whereas the + # 1st -and is in column mode, thus flips the entire array, whereas the # 2nd one is just a condition modifier { where => [ @@ -399,7 +399,7 @@ for my $case (@and_or_tests) { my $where_copy = $dclone->($case->{where}) if $dclone;; - lives_ok (sub { + lives_ok (sub { my ($stmt, @bind) = $sql->where($case->{where}); is_same_sql_bind( $stmt, diff --git a/t/05in_between.t b/t/05in_between.t index ffaf6cc..51d3842 100644 --- a/t/05in_between.t +++ b/t/05in_between.t @@ -176,7 +176,7 @@ my @in_between_tests = ( where => { x => { -in => [ 1, undef ] } }, stmt => " WHERE ( x IN ( ? ) OR x IS NULL )", bind => [ 1 ], - test => '-in with undef as an element', + test => '-in with undef as an element', }, { where => { x => { -in => [ 1, undef, 2, 3, undef ] } }, diff --git a/t/07subqueries.t b/t/07subqueries.t index 28bac85..2ea48e8 100644 --- a/t/07subqueries.t +++ b/t/07subqueries.t @@ -36,7 +36,7 @@ push @tests, { #2 ($sub_stmt, @sub_bind) - = $sql->select("t1", "c1", {c2 => {"<" => 100}, + = $sql->select("t1", "c1", {c2 => {"<" => 100}, c3 => {-like => "foo%"}}); $where = { foo => 1234, @@ -49,7 +49,7 @@ push @tests, { }; #3 -($sub_stmt, @sub_bind) +($sub_stmt, @sub_bind) = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"}); $where = { foo => 1234, @@ -73,7 +73,7 @@ push @tests, { #5 -($sub_stmt, @sub_bind) +($sub_stmt, @sub_bind) = $sql->where({age => [{"<" => 10}, {">" => 20}]}); $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause $where = { diff --git a/t/08special_ops.t b/t/08special_ops.t index 7632be4..dc6a618 100644 --- a/t/08special_ops.t +++ b/t/08special_ops.t @@ -11,7 +11,7 @@ use SQL::Abstract; my $sqlmaker = SQL::Abstract->new(special_ops => [ # special op for MySql MATCH (field) AGAINST(word1, word2, ...) - {regex => qr/^match$/i, + {regex => qr/^match$/i, handler => sub { my ($self, $field, $op, $arg) = @_; $arg = [$arg] if not ref $arg; @@ -26,7 +26,7 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [ }, # special op for Basis+ NATIVE - {regex => qr/^native$/i, + {regex => qr/^native$/i, handler => sub { my ($self, $field, $op, $arg) = @_; $arg =~ s/'/''/g; @@ -39,7 +39,7 @@ my $sqlmaker = SQL::Abstract->new(special_ops => [ my @tests = ( - #1 + #1 { where => {foo => {-match => 'foo'}, bar => {-match => [qw/foo bar/]}}, stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )", diff --git a/t/12format_keyword.t b/t/12format_keyword.t index a1cd8d8..be31a6a 100644 --- a/t/12format_keyword.t +++ b/t/12format_keyword.t @@ -5,20 +5,20 @@ use Test::More; use SQL::Abstract::Tree; my $sqlat = SQL::Abstract::Tree->new({ - colormap => { - select => ['s(', ')s'], - where => ['w(', ')w'], - from => ['f(', ')f'], - join => ['j(', ')f'], - on => ['o(', ')o'], - 'group by' => ['gb(',')gb'], - 'order by' => ['ob(',')ob'], - }, + colormap => { + select => ['s(', ')s'], + where => ['w(', ')w'], + from => ['f(', ')f'], + join => ['j(', ')f'], + on => ['o(', ')o'], + 'group by' => ['gb(',')gb'], + 'order by' => ['ob(',')ob'], + }, }); for ( keys %{$sqlat->colormap}) { - my ($l, $r) = @{$sqlat->colormap->{$_}}; - is($sqlat->format_keyword($_), "$l$_$r", "$_ 'colored' correctly"); + my ($l, $r) = @{$sqlat->colormap->{$_}}; + is($sqlat->format_keyword($_), "$l$_$r", "$_ 'colored' correctly"); } diff --git a/t/90pod.t b/xt/90pod.t similarity index 80% rename from t/90pod.t rename to xt/90pod.t index ddc2905..57b8782 100644 --- a/t/90pod.t +++ b/xt/90pod.t @@ -1,3 +1,6 @@ +use warnings; +use strict; + use Test::More; eval "use Test::Pod 1.14"; diff --git a/t/91podcoverage.t b/xt/91podcoverage.t similarity index 98% rename from t/91podcoverage.t rename to xt/91podcoverage.t index 5335eef..9e74ea1 100644 --- a/t/91podcoverage.t +++ b/xt/91podcoverage.t @@ -1,3 +1,6 @@ +use warnings; +use strict; + use Test::More; # TEMPORARY diff --git a/xt/92whitespace.t b/xt/92whitespace.t new file mode 100644 index 0000000..ebc0148 --- /dev/null +++ b/xt/92whitespace.t @@ -0,0 +1,54 @@ +use warnings; +use strict; + +use Test::More; +use File::Glob 'bsd_glob'; +use lib 't/lib'; + +eval "use Test::EOL 1.0 ()"; +plan skip_all => 'Test::EOL 1.0 required' if $@; +eval "use Test::NoTabs 0.9 ()"; +plan skip_all => 'Test::NoTabs 0.9 required' if $@; + +# FIXME - temporary workaround for RT#82032, RT#82033 +# also add all scripts (no extension) and some extra extensions +# we want to check +{ + no warnings 'redefine'; + my $is_pm = sub { + $_[0] !~ /\./ || $_[0] =~ /\.(?:pm|pod|skip|bash|sql|json|proto)$/i || $_[0] =~ /::/; + }; + + *Test::EOL::_is_perl_module = $is_pm; + *Test::NoTabs::_is_perl_module = $is_pm; +} + +my @pl_targets = qw/t lib script examples/; +Test::EOL::all_perl_files_ok({ trailing_whitespace => 1 }, @pl_targets); +Test::NoTabs::all_perl_files_ok(@pl_targets); + +# check some non-"perl files" in the root separately +# use .gitignore as a guide of what to skip +# (or do not test at all if no .gitignore is found) +if (open(my $gi, '<', '.gitignore')) { + my $skipnames; + while (my $ln = <$gi>) { + next if $ln =~ /^\s*$/; + chomp $ln; + $skipnames->{$_}++ for bsd_glob($ln); + } + + # that we want to check anyway + delete $skipnames->{'META.yml'}; + + for my $fn (bsd_glob('*')) { + next if $skipnames->{$fn}; + next unless -f $fn; + Test::EOL::eol_unix_ok($fn, { trailing_whitespace => 1 }); + Test::NoTabs::notabs_ok($fn); + } +} + +# FIXME - Test::NoTabs and Test::EOL declare 'no_plan' which conflicts with done_testing +# https://github.com/schwern/test-more/issues/14 +#done_testing;