forked from masak/proto
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added DbBuilder::Log and its docs/tests
- Loading branch information
1 parent
ebfcfd7
commit d87f592
Showing
4 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package DbBuilder::Log; | ||
|
|
||
| use Exporter::Easy EXPORT => [ 'log' ]; | ||
| use Mojo::Log; | ||
|
|
||
| my $LOG = Mojo::Log->new; | ||
| use 5.020; | ||
| sub log($$) { | ||
| my ( $level, $message ) = @_; | ||
| $LOG->$level( $message ); | ||
| $level eq 'fatal' and die "*died through fatal level log message*\n"; | ||
|
|
||
| return $message; | ||
| } | ||
|
|
||
| 1; | ||
|
|
||
| __END__ | ||
|
|
||
| =encoding utf8 | ||
| =head1 NAME | ||
| DbBuilder::Log - convenient logging | ||
| =head1 SYNOPSIS | ||
| use DbBuilder::Log; | ||
| log info => 'Starting stuff'; | ||
| log fatal => 'Oh noes!'; # dies after logging | ||
| OUTPUT: | ||
| [Sat Nov 21 12:12:30 2015] [info] Starting stuff | ||
| [Sat Nov 21 12:12:30 2015] [fatal] Oh noes! | ||
| *died through fatal level log message* | ||
| =head1 DESCRIPTION | ||
| This module is used to access and manipulate the database of Perl 6 | ||
| distributions that is built by the build script. | ||
| =head1 EXPORTED SUBROUTINES | ||
| =head2 C<log> | ||
| log info => 'Starting stuff'; | ||
| log fatal => 'Oh noes!'; # dies after logging | ||
| B<Takes> log level and the log message and prints those along | ||
| with a time stamp. Valid log levels are C<debug>, C<info>, C<warn>, | ||
| C<error>, and c<fatal>. If C<fatal> log level is used, the subroutine will | ||
| C<die> after printing the error message. | ||
| =head1 CONTACT INFORMATION | ||
| Original version of this module was written by Zoffix Znet | ||
| (L<https://github.com/zoffixznet/>, C<Zoffix> on irc.freenode.net). | ||
| =head1 LICENSE | ||
| You can use and distribute this module under the same terms as Perl itself. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!perl | ||
|
|
||
| use strict; | ||
| use warnings FATAL => 'all'; | ||
|
|
||
| use Test::Most; | ||
| use Test::Output qw/combined_from/; | ||
|
|
||
| BEGIN { use_ok 'DbBuilder::Log' }; | ||
|
|
||
| my ( $out, $ret ); | ||
| my $time_stamp_re = qr/\[\w{3} \w{3} \d\d? \d{2}:\d{2}:\d{2} \d{4}\]/; | ||
|
|
||
| for ( qw/debug info warn error/ ) { | ||
| $out = combined_from sub { $ret = log $_ => "This is $_ log"; }; | ||
| like $out => qr/^$time_stamp_re \[$_\] This is $_ log$/, "$_ log works"; | ||
| is $ret, "This is $_ log", 'return value of log() is the message'; | ||
| } | ||
|
|
||
| subtest 'fatal level log' => sub { | ||
| $out = combined_from sub { eval { log fatal => 'This is fatal log' } }; | ||
| like $out => qr/^$time_stamp_re \[fatal\] This is fatal log$/, | ||
| 'fatal log has correct message'; | ||
|
|
||
| throws_ok { combined_from sub {log fatal => 'dies';} } | ||
| qr/^\*died through fatal level log message\*$/, 'fatal log dies'; | ||
| }; | ||
|
|
||
| dies_ok { log foobar => 'dies'; } 'dies on non-existent log level'; | ||
| throws_ok { eval "log info => 'foo', 'bar'"; $@ and die; } | ||
| qr/Too many arguments/, 'prototype catches screw ups'; | ||
|
|
||
| done_testing; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!perl | ||
|
|
||
| use strict; | ||
| use warnings FATAL => 'all'; | ||
| use Test::Most; | ||
| use Mojo::URL; | ||
| use Test::Mojo::WithRoles qw/SubmitForm ElementCounter Debug/; | ||
| use t::Helper; | ||
|
|
||
| my $db_file = t::Helper::setup_db_file; | ||
| END { unlink $db_file } | ||
|
|
||
| my $t = Test::Mojo::WithRoles->new('ModulesPerl6'); | ||
| my ( $dist1, $dist2 ) = t::Helper::dist_out_data; | ||
|
|
||
| $_->{travis_url} = Mojo::URL->new($_->{url})->host('travis-ci.org') | ||
| for $dist1, $dist2; | ||
|
|
||
| { | ||
| diag 'Have dists table with right data'; | ||
| $t->dive_reset->get_ok('/')->status_is(200) | ||
| ->element_count_is('#dists tbody tr' => 2, 'we have just two dists') | ||
| ->dive_in('#dists tbody tr:first-child ') | ||
| ->dived_text_is('.name a[href^="/"]' => 'Dist1' ) | ||
| ->dived_text_is('.desc' => 'Test Dist1') | ||
| ->dived_text_is('.kwalitee a' => '100%' ) | ||
| ->dived_text_is('.travis a' => 'passing' ) | ||
| ->dived_text_is('.stars a' => '42' ) | ||
| ->dived_text_is('.issues a' => '12' ) | ||
| ->dived_text_is('.updated' => '2015-11-08') | ||
| # ->dived_text_is('.added' => '2015-11-04') | ||
| ->element_count_is(".name a[href='$dist1->{url}']" => 1) | ||
| ->element_count_is('.name a[href="/dist/Dist1"]' => 1) | ||
| ->element_count_is('.name a i.dist-logos.s-dist1' => 1) | ||
| ->element_count_is(".travis a[href='$dist1->{travis_url}']" => 1) | ||
| ->element_count_is(".stars a[href='$dist1->{url}stargazers']" => 1) | ||
| ->element_count_is(".issues a[href='$dist1->{url}issues']" => 1) | ||
| ; | ||
|
|
||
| $t->dive_reset | ||
| ->dive_in('#dists tbody tr:first-child + tr ') | ||
| ->dived_text_is('.name a[href^="/"]' => 'Dist2' ) | ||
| ->dived_text_is('.desc' => 'Test Dist2') | ||
| # ->dived_text_is('.kwalitee a' => '0%' ) | ||
| ->dived_text_is('.travis a' => 'failing' ) | ||
| ->dived_text_is('.stars a' => '14' ) | ||
| ->dived_text_is('.issues a' => '6' ) | ||
| ->dived_text_is('.updated' => '2015-11-02') | ||
| # ->dived_text_is('.added' => '2015-10-26') | ||
| ->element_count_is(".name a[href='$dist2->{url}']" => 1) | ||
| ->element_count_is('.name a[href="/dist/Dist2"]' => 1) | ||
| ->element_count_is('.name a i.dist-logos.s-dist2' => 1) | ||
| ->element_count_is('.kwalitee a[href="/kwalitee/Dist2"]' => 1) | ||
| ->element_count_is(".travis a[href='$dist2->{travis_url}']" => 1) | ||
| ->element_count_is(".stars a[href='$dist2->{url}stargazers']" => 1) | ||
| ->element_count_is(".issues a[href='$dist2->{url}issues']" => 1) | ||
| ; | ||
| } | ||
|
|
||
| { | ||
| diag 'Misc elements'; | ||
| $t->dive_reset->get_ok('/')->status_is(200) | ||
| ->text_is('.total_dist_count' => 2, 'total distro count is displayed') | ||
| ->text_like('.build_last_updated' | ||
| => qr/\w{3}\s \w{3}\s \d\d?\s \d{2}:\d{2}:\d{2}\s \d{4}/x, | ||
| 'db build date is displayed (e.g. Wed Dec 31 19:00:00 1969)') | ||
| ; | ||
|
|
||
| $t->dive_reset->get_ok('/repo/Dist1') | ||
| ->status_is(302) | ||
| ->header_is(Location => 'https://github.com/perl6/modules.perl6.org/') | ||
| ; | ||
|
|
||
| # This should eventually be a proper page with info and not a redirect | ||
| $t->dive_reset->get_ok('/dist/Dist1') | ||
| ->status_is(302) | ||
| ->header_is(Location => 'https://github.com/perl6/modules.perl6.org/') | ||
| ; | ||
|
|
||
| $t->dive_reset->get_ok('/')->status_is(200) | ||
| ->text_like('#site_tip' => qr/^Tip \d\z/, 'Site tip has correct text'); | ||
| ; | ||
| } | ||
|
|
||
| done_testing; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!perl | ||
|
|
||
| use strict; | ||
| use warnings FATAL => 'all'; | ||
| use Test::Most; | ||
| use Mojo::URL; | ||
| use Test::Mojo::WithRoles qw/SubmitForm ElementCounter/; | ||
| use t::Helper; | ||
|
|
||
| my $db_file = t::Helper::setup_db_file; | ||
| END { unlink $db_file } | ||
|
|
||
| my $t = Test::Mojo::WithRoles->new('ModulesPerl6'); | ||
|
|
||
| { | ||
| $t->dive_reset->get_ok('/')->status_is(200) | ||
| ->element_exists('#search[action="/"]', 'search form' ) | ||
| ->element_exists('#search [name="q"]', 'search box is there') | ||
| ->element_exists('#search [type="submit"]', 'with submit button' ); | ||
|
|
||
| $t->click_ok('#search' => {q => 'Test'})->status_is(200) | ||
| ->element_exists('#search [name="q"][value="Test"]') | ||
| ->element_count_is('#dists tbody tr:not(.hidden)' => 2, | ||
| 'we have two results') | ||
| ->text_is( '#dists tbody tr:first-child td:first-child a + a' | ||
| => 'Dist1') | ||
| ->text_is( '#dists tbody tr:first-child + tr td:first-child a + a' | ||
| => 'Dist2'); | ||
|
|
||
| $t->click_ok('#search' => {q => 'Dist2'})->status_is(200) | ||
| ->element_count_is('#dists tbody tr:not(.hidden)' => 1, | ||
| 'we have one result') | ||
| ->element_exists('#dists tbody tr:first-child.hidden') | ||
| ->text_is('#dists tbody tr:first-child + tr td:first-child a + a' | ||
| => 'Dist2'); | ||
|
|
||
| $t->click_ok('#search' => {q => 'Dist42'})->status_is(200) | ||
| ->element_count_is('#dists tbody tr' => 3, | ||
| 'dists table has three rows (2 dists, hidden, ' | ||
| . 'and 1 message saying there are no results') | ||
| ->element_count_is('#dists tbody tr:not(.hidden)' => 1, | ||
| 'we have no results and showing the error message') | ||
| ->text_is('#dists tbody tr:not(.hidden) .error' => | ||
| 'No results were found') | ||
| ; | ||
| } | ||
|
|
||
| done_testing; |