App-GitHooks-Plugin-RubyCompile

 view release on metacpan or  search on metacpan

lib/App/GitHooks/Plugin/RubyCompile.pm  view on Meta::CPAN

    my $app = delete( $args{'app'} );
    my $staged_changes = $app->get_staged_changes();
    my $repository = $app->get_repository();

    # Ignore deleted files.
    return $PLUGIN_RETURN_SKIPPED
        if $git_action eq 'D';

    # Execute ruby -c.
    my $path = $repository->work_tree() . '/' . $file;
    my ( $pid, $stdin, $stdout, $stderr ) = System::Command->spawn( 'ruby', '-W0', '-c', $path );

    # Retrieve the output.
    chomp( my $message_out = do { local $/ = undef; <$stdout> } );

    # Raise an exception if we didn't get "syntax OK".
    if ( $message_out !~ /^Syntax\ OK$/x ) {
            my @warnings = <$stderr>;
            foreach my $warning ( @warnings ) {
                    chomp( $warning );
                    $warning =~ s/^\Q$path\E:/Line /;
            }
            die join( "\n", @warnings ) . "\n";
    }

    return $PLUGIN_RETURN_PASSED;
}

t/10-run.t  view on Meta::CPAN

                plugins                 => [ 'App::GitHooks::Plugin::RubyCompile' ],
            );

            # Set up test files.
            ok_add_files(
                files      => $test->{'files'},
                repository => $repository,
            );

            # Try to commit.
            my $stderr;
            lives_ok(
                sub
                {
                    $stderr = Capture::Tiny::capture_stderr(
                        sub
                        {
                            $repository->run( 'commit', '-m', 'Test message.' );
                        }
                    );
                    note( $stderr );
                },
                'Commit the changes.',
            );

            like(
                $stderr,
                $test->{'expected'},
                "The output matches expected results.",
            );
        }
    );
}



( run in 0.237 second using v1.01-cache-2.11-cpan-26ccb49234f )