From 4e4aca4a5f135314252502ddd7bfd73b2093a89d Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Sat, 16 Feb 2008 08:15:18 +0000 Subject: [PATCH] Continuous Testing app for Perl. Design for running CPAN distribution tests. git-svn-id: http://code.handlino.com/svn/people/gugod/perl5/Test-Continuously@216 b19cb30a-9f2e-4084-8847-5e1a13269302 --- .cvsignore | 10 ++ Changes | 5 + MANIFEST | 10 ++ Makefile.PL | 11 ++ README | 38 +++++++ lib/Test/Continuously.pm | 162 +++++++++++++++++++++++++++++ lib/Test/Continuously/Formatter.pm | 38 +++++++ t/00.load.t | 7 ++ t/perlcritic.t | 11 ++ t/pod-coverage.t | 6 ++ t/pod.t | 6 ++ 11 files changed, 304 insertions(+) create mode 100644 .cvsignore create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Test/Continuously.pm create mode 100644 lib/Test/Continuously/Formatter.pm create mode 100644 t/00.load.t create mode 100644 t/perlcritic.t create mode 100644 t/pod-coverage.t create mode 100644 t/pod.t diff --git a/.cvsignore b/.cvsignore new file mode 100644 index 0000000..92bc53b --- /dev/null +++ b/.cvsignore @@ -0,0 +1,10 @@ +blib* +Makefile +Makefile.old +Build +_build* +pm_to_blib* +*.tar.gz +.lwpcookies +Test-Continuously-* +cover_db diff --git a/Changes b/Changes new file mode 100644 index 0000000..6b14a27 --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ +Revision history for Test-Continuously + +0.0.1 Sat Feb 16 14:09:02 2008 + Initial release. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..1c3ef1b --- /dev/null +++ b/MANIFEST @@ -0,0 +1,10 @@ +Changes +MANIFEST +META.yml # Will be created by "make dist" +Makefile.PL +README +lib/Test/Continuously.pm +t/00.load.t +t/perlcritic.t +t/pod-coverage.t +t/pod.t diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..b7bf576 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,11 @@ +use strict; +use warnings; +use inc::Module::Install; + +all_from 'lib/Test/Continuously.pm'; + +build_requires 'Test::More' => '0.42'; + +WriteAll; + + diff --git a/README b/README new file mode 100644 index 0000000..b2f76a0 --- /dev/null +++ b/README @@ -0,0 +1,38 @@ +Test-Continuously version 0.0.1 + +This module is inspired by "Continuous Testing" + + http://groups.csail.mit.edu/pag/continuoustesting/ + +Perl module developers can use this module to keep testing their work +at the same moment they are coding. It keeps polling if any code is +changed, and run tests if so. + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + +USAGE + +To use this, run this at your module directory (where a t/ lives): + + perl -MTest::Continuously -e runtests + +Then just switch to your editor and start coding. You shall be +notified when a round of test is finished. + +DEPENDENCIES + +Mac::Growl + +COPYRIGHT AND LICENCE + +Copyright (C) 2008, Kang-min Liu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. diff --git a/lib/Test/Continuously.pm b/lib/Test/Continuously.pm new file mode 100644 index 0000000..ff00fb3 --- /dev/null +++ b/lib/Test/Continuously.pm @@ -0,0 +1,162 @@ +use warnings; +use strict; +package Test::Continuously; + +use 5.008; + +our $VERSION = '0.0.1'; + +use Exporter::Lite; +use App::Prove; +use File::Find; +use Cwd; + +our @EXPORT = qw(&runtests); +{ + no warnings; + *{App::Prove::_exit} = sub {}; +} + +sub run_once { + my $prove = App::Prove->new; + $prove->process_args( + "--formatter" => "Test::Continuously::Formatter", + "--norc", "--nocolor", "-Q", "-l", "t" + ); + $prove->run; +} + +my %files; +sub _changed { + my $modified = 0; + find sub { + my $filename = $File::Find::name; + return if $filename =~ /~$/; + return if ! -f $filename; + + my $mtime = (stat($filename))[9]; + if (exists $files{$filename}) { + if ( $files{$filename} < $mtime) { + $modified = 1; + print STDERR "[MSG] $filename is updated\n"; + } + } + else { + $modified = 1; + } + $files{$filename} = $mtime; + }, getcwd; + return $modified; +} + +sub runtests { + while (1) { + run_once if _changed; + sleep 5; + } +} + +1; + +__END__ + +=head1 NAME + +Test::Continuously - [One line description of module's purpose here] + + +=head1 VERSION + +This document describes Test::Continuously version 0.0.1 + + +=head1 SYNOPSIS + + use Test::Continuously; + + +=head1 DESCRIPTION + + +=head1 INTERFACE + + +=over + +=item new() + +=back + +=head1 DIAGNOSTICS + +=over + +=item C<< Error message here, perhaps with %s placeholders >> + +[Description of error here] + +=item C<< Another error message here >> + +[Description of error here] + +[Et cetera, et cetera] + +=back + + +=head1 CONFIGURATION AND ENVIRONMENT + +Test::Continuously requires no configuration files or environment variables. + +=head1 DEPENDENCIES + +None. + +=head1 INCOMPATIBILITIES + +None reported. + +=head1 BUGS AND LIMITATIONS + +No bugs have been reported. + +Please report any bugs or feature requests to +C, or through the web interface at +L. + + +=head1 AUTHOR + +Kang-min Liu C<< >> + + +=head1 LICENCE AND COPYRIGHT + +Copyright (c) 2008, Kang-min Liu C<< >>. All rights reserved. + +This module is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. See L. + + +=head1 DISCLAIMER OF WARRANTY + +BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE +ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH +YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR, OR CORRECTION. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE +LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, +OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE +THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. diff --git a/lib/Test/Continuously/Formatter.pm b/lib/Test/Continuously/Formatter.pm new file mode 100644 index 0000000..69ae691 --- /dev/null +++ b/lib/Test/Continuously/Formatter.pm @@ -0,0 +1,38 @@ +package Test::Continuously::Formatter; +use base 'TAP::Formatter::Console'; + +use Mac::Growl ':all'; +use IO::String; + +sub summary { + my ( $self, $aggregate ) = @_; + + my $str; + my $io = IO::String->new($str); + $self->stdout($io); + + $self->SUPER::summary($aggregate); + + RegisterNotifications( + "Test::Continuously", + ["TestResult"], + ["TestResult"] + ); + + $str =~ s/^\s*//s; + $str =~ s/\s*$//s; + my @lines = split(/\n/, $str); + shift @lines; shift @lines; + + for (split(/\n(?! )/, join("\n", @lines) )) { + s/ +/ /gs; + PostNotification( + "Test::Continuously", + "TestResult", + "Test Summary Report", + $_, + ); + } +} + +1; diff --git a/t/00.load.t b/t/00.load.t new file mode 100644 index 0000000..0f076c0 --- /dev/null +++ b/t/00.load.t @@ -0,0 +1,7 @@ +use Test::More tests => 1; + +BEGIN { +use_ok( 'Test::Continuously' ); +} + +diag( "Testing Test::Continuously $Test::Continuously::VERSION" ); diff --git a/t/perlcritic.t b/t/perlcritic.t new file mode 100644 index 0000000..f516f58 --- /dev/null +++ b/t/perlcritic.t @@ -0,0 +1,11 @@ +#!perl + +eval { require Test::Perl::Critic }; +if ($@) { + require Test::More; + Test::More::plan( + skip_all => "Test::Perl::Critic required for testing PBP compliance" + ); +} + +Test::Perl::Critic::all_critic_ok(); diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 0000000..703f91d --- /dev/null +++ b/t/pod-coverage.t @@ -0,0 +1,6 @@ +#!perl -T + +use Test::More; +eval "use Test::Pod::Coverage 1.04"; +plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; +all_pod_coverage_ok(); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 0000000..976d7cd --- /dev/null +++ b/t/pod.t @@ -0,0 +1,6 @@ +#!perl -T + +use Test::More; +eval "use Test::Pod 1.14"; +plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; +all_pod_files_ok();