-
-
Notifications
You must be signed in to change notification settings - Fork 30
Bug 2054397: Test Perl code for vendor-specific SQL #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justdave
wants to merge
6
commits into
main
Choose a base branch
from
bug-2054397-harmony
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
add0457
Bug 2054397: Test Perl code for vendor-specific SQL
justdave b95c828
Fix the test failures
justdave 96168c1
Revert accidental spacing change
justdave 3effc4e
Test the contents of the scripts directory as well.
justdave 6eda1c3
Add $dbh->sql_date_to_epoch abstraction and suggest it in test
justdave 8ecd408
Fix new test failures
justdave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| use 5.14.0; | ||
| use strict; | ||
| use warnings; | ||
|
|
||
| use lib qw(. lib local/lib/perl5 t); | ||
|
|
||
| use Support::Files; | ||
| use File::Find; | ||
|
|
||
| use Test::More; | ||
|
|
||
| my %seen_file; | ||
| my @files = grep { $_ ne 't/013db_portability.t' && !$seen_file{$_}++ } | ||
| (@Support::Files::testitems, @Support::Files::test_files); | ||
|
|
||
| my @script_files; | ||
| find( | ||
| sub { | ||
| return if -d; | ||
| return unless /\.pl$/; | ||
| push @script_files, $File::Find::name; | ||
| }, | ||
| 'scripts' | ||
| ); | ||
|
|
||
| push @files, grep { !$seen_file{$_}++ } @script_files; | ||
|
|
||
| my @rules = ( | ||
| { | ||
| token => qr/\bUNIX_TIMESTAMP\s*\(/, | ||
| helper => 'sql_date_to_epoch', | ||
| message => 'use $dbh->sql_date_to_epoch(...) instead of UNIX_TIMESTAMP()', | ||
| }, | ||
| { | ||
| token => qr/\bDATE_FORMAT\s*\(/, | ||
| helper => 'sql_date_format', | ||
| message => 'use $dbh->sql_date_format(...) instead of DATE_FORMAT()', | ||
| }, | ||
| { | ||
| token => qr/\bCONCAT\s*\(/, | ||
| helper => 'sql_string_concat', | ||
| message => 'use $dbh->sql_string_concat(...) instead of CONCAT()', | ||
| }, | ||
| { | ||
| token => qr/\b(?:POSITION|INSTR|LOCATE)\s*\(/, | ||
| helper => 'sql_position/sql_iposition', | ||
| message => 'use $dbh->sql_position(...) or $dbh->sql_iposition(...) instead', | ||
| }, | ||
| { | ||
| token => qr/\bGROUP_CONCAT\s*\(/, | ||
| helper => 'sql_group_concat', | ||
| message => 'use $dbh->sql_group_concat(...) instead of GROUP_CONCAT()', | ||
| }, | ||
| ); | ||
|
|
||
| my @violations; | ||
|
|
||
| foreach my $file (@files) { | ||
| next if $file =~ m{^Bugzilla/DB(?:/|\.pm$)}; | ||
|
|
||
| open(my $fh, '<', $file) or do { | ||
| push @violations, { file => $file, line => 0, text => 'could not open file' }; | ||
| next; | ||
| }; | ||
|
|
||
| my $line_number = 0; | ||
| while (my $line = <$fh>) { | ||
| $line_number++; | ||
| next if $line =~ /^\s*#/; | ||
| next if $line =~ /^\s*=/; | ||
|
|
||
| foreach my $rule (@rules) { | ||
| next unless $line =~ $rule->{token}; | ||
| push @violations, { | ||
| file => $file, | ||
| line => $line_number, | ||
| text => $line, | ||
| helper => $rule->{helper}, | ||
| message => $rule->{message}, | ||
| }; | ||
| } | ||
| } | ||
| close($fh); | ||
| } | ||
|
|
||
| is(scalar(@violations), 0, 'no raw vendor-specific SQL where a Bugzilla DB helper exists'); | ||
|
|
||
| if (@violations) { | ||
| diag(join("\n", map { | ||
| sprintf('%s:%d: %s (%s)', $_->{file}, $_->{line}, $_->{message}, $_->{text}) | ||
| } @violations)); | ||
| } | ||
|
|
||
| done_testing(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure what this code is intending by using concat() on a single entity, but this fixes the compatibility issue.