-
Notifications
You must be signed in to change notification settings - Fork 213
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
Warn on sqitch add file with double extension #724
Merged
Merged
Conversation
This file contains 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
`sqitch add` includes extensions for each engine. Warn if user specifies an extension resulting in a filename like `myobjects.sql.sql`
theory
requested changes
Mar 19, 2023
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.
Handy! aCould you add a test for it in t/add.t
?
Try this: --- a/lib/App/Sqitch/Command/add.pm
+++ b/lib/App/Sqitch/Command/add.pm
@@ -407,17 +407,17 @@ sub _add {
file => $file,
error => $!
);
-
+
# Warn if the file name has a double extension
if ($file =~ m/\.(\w+)\.\1+$/) {
my $ext = $1;
- $self->warning(__x(
- 'Warning: file {file} has a double extension of {ext}',
+ $self->warn(__x(
+ 'File {file} has a double extension of {ext}',
file => $file,
ext => $ext,
));
}
-
+
$self->info(__x 'Created {file}', file => $file);
}
diff --git a/t/add.t b/t/add.t
index cd3e29a3..ea952b3d 100644
--- a/t/add.t
+++ b/t/add.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
use utf8;
-use Test::More tests => 238;
+use Test::More tests => 240;
#use Test::More 'no_plan';
use App::Sqitch;
use App::Sqitch::Target;
@@ -414,14 +414,6 @@ EOF
'Info should show $out created';
unlink $out;
- # # Test with file name having a double extension
- $out = file 'test-add', 'duplicate_extension_test.sql.sql';
- warning_is {
- $add->_add('duplicate_extension_test.sql', $out, $tmpl, 'sqlite', 'add')
- } [qr/double extension of sql/], 'Should get warning for file name with double extension';
-
- unlink $out;
-
# Try with requires and conflicts.
ok $add = $CLASS->new(
sqitch => $sqitch,
@@ -448,6 +440,18 @@ BEGIN;
COMMIT;
EOF
unlink $out;
+
+ # # Test with file name having a double extension
+ $out = file 'test-add', 'duplicate_extension_test.sql.sql';
+ $add->_add('duplicate_extension_test.sql', $out, $tmpl, 'sqlite', 'add');
+ is_deeply +MockOutput->get_info, [[__x 'Created {file}', file => $out ]],
+ 'Info should show $out created';
+ is_deeply +MockOutput->get_warn, [[__x(
+ 'File {file} has a double extension of {ext}',
+ file => $out,
+ ext => 'sql',
+ )]], 'Should have warned about double extension';
+ unlink $out;
};
# First, test with Template::Tiny. |
blairjordan
force-pushed
the
patch-2
branch
2 times, most recently
from
April 3, 2023 14:30
5c6474b
to
e4e690e
Compare
@theory That's done the trick, thanks! |
theory
approved these changes
Apr 8, 2023
Thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
sqitch add
includes extensions for each engine. Warn if user specifies a filename likemyobjects.sql
resulting in themyobjects.sql.sql