[libcode-tidyall-perl] 237/374: handle errors correctly in JSBeautify, JSHint

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:27 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcode-tidyall-perl.

commit c0fcdef1bdb0024fa832e3040feead01f2004af2
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Fri Sep 14 12:20:03 2012 -0400

    handle errors correctly in JSBeautify, JSHint
---
 lib/Code/TidyAll/Plugin/JSBeautify.pm   |    8 +++++++-
 lib/Code/TidyAll/Plugin/JSHint.pm       |    2 ++
 lib/Code/TidyAll/t/Plugin/JSBeautify.pm |    5 +++++
 lib/Code/TidyAll/t/Plugin/JSHint.pm     |    6 ++++++
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/Code/TidyAll/Plugin/JSBeautify.pm b/lib/Code/TidyAll/Plugin/JSBeautify.pm
index 1d91925..94f8b26 100644
--- a/lib/Code/TidyAll/Plugin/JSBeautify.pm
+++ b/lib/Code/TidyAll/Plugin/JSBeautify.pm
@@ -1,6 +1,7 @@
 package Code::TidyAll::Plugin::JSBeautify;
 use IPC::System::Simple qw(run);
 use Moo;
+use Try::Tiny;
 extends 'Code::TidyAll::Plugin';
 
 sub _build_cmd { 'js-beautify' }
@@ -8,7 +9,12 @@ sub _build_cmd { 'js-beautify' }
 sub transform_file {
     my ( $self, $file ) = @_;
 
-    run( sprintf( "%s --replace %s %s", $self->cmd, $self->argv, $file ) );
+    try {
+        run( sprintf( "%s --replace %s %s", $self->cmd, $self->argv, $file ) );
+    }
+    catch {
+        die sprintf( "%s exited with error - possibly bad arg list '%s'", $self->cmd, $self->argv );
+    };
 }
 
 1;
diff --git a/lib/Code/TidyAll/Plugin/JSHint.pm b/lib/Code/TidyAll/Plugin/JSHint.pm
index 1a3913f..a73a66a 100644
--- a/lib/Code/TidyAll/Plugin/JSHint.pm
+++ b/lib/Code/TidyAll/Plugin/JSHint.pm
@@ -25,6 +25,8 @@ sub validate_file {
 
     my $cmd = sprintf( "%s %s %s", $self->cmd, $self->argv, $file );
     my $output = capture_merged { system($cmd) };
+    use d;
+    dp $output;
     die "$output\n" if $output =~ /\S/;
 }
 
diff --git a/lib/Code/TidyAll/t/Plugin/JSBeautify.pm b/lib/Code/TidyAll/t/Plugin/JSBeautify.pm
index b179999..96794d3 100644
--- a/lib/Code/TidyAll/t/Plugin/JSBeautify.pm
+++ b/lib/Code/TidyAll/t/Plugin/JSBeautify.pm
@@ -14,6 +14,11 @@ sub test_main : Tests {
         conf        => { argv => '--indent-size 2 --brace-style expand' },
         expect_tidy => 'sp.toggleResult = function(id)\n{\n  foo(id)\n}\n',
     );
+    $self->tidyall(
+        source       => $source,
+        conf         => { argv => '--badoption' },
+        expect_error => qr/exited with error/
+    );
 }
 
 1;
diff --git a/lib/Code/TidyAll/t/Plugin/JSHint.pm b/lib/Code/TidyAll/t/Plugin/JSHint.pm
index 7e8819b..5b7c538 100644
--- a/lib/Code/TidyAll/t/Plugin/JSHint.pm
+++ b/lib/Code/TidyAll/t/Plugin/JSHint.pm
@@ -49,6 +49,12 @@ sub test_main : Tests {
         expect_error => qr/not in camel case/,
         desc         => 'error - camelcase - conf file',
     );
+    $self->tidyall(
+        source       => 'var my_object = {};',
+        conf         => { argv => "--badoption" },
+        expect_error => qr/Unknown option/,
+        desc         => 'error - bad option'
+    );
 }
 
 1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git



More information about the Pkg-perl-cvs-commits mailing list