Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
* Add the beginnings of a testsuite. Modify existing code slightly to…
Browse files Browse the repository at this point in the history
… make this possible.

* Only rakudolog (and by extension, githubparser) are tested, and coverage is pretty low even for those.  But this is a starting point.
* Add a Makefile (this shouldn't conflict with botnix when sharing the checkout directory) to allow "make test" and "make testcover".
  • Loading branch information
Infinoid committed May 1, 2009
1 parent a75ea45 commit 27825ff
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
prove t

testcover:
@rm -rf cover_db
@HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,t/" prove t
@cover -summary -report html -outputdir cover_db
12 changes: 9 additions & 3 deletions modules/local/githubparser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ my $feed_number = 1;

my %objects_by_package;

sub get_self {
my $pkg = shift;
return $objects_by_package{$pkg};
}

sub init {
my $self = shift;
my $package_name = $$self{modulename};
Expand All @@ -35,16 +40,16 @@ sub fetch_feed {
my $self = $objects_by_package{$pkg};
my $atom = XML::Atom::Client->new();
my $feed = $atom->getFeed($$self{url});
$self->process_feed($feed);
$pkg->process_feed($feed);
}

sub process_feed {
my ($self, $feed) = @_;
my ($pkg, $feed) = @_;
my $self = $objects_by_package{$pkg};
my @items = $feed->entries;
@items = sort { $a->updated cmp $b->updated } @items; # ascending order
my $newest = $items[-1];
my $latest = $newest->updated;
$latest = $items[0]->updated if exists $ENV{TEST_RSS_PARSER};

# skip the first run, to prevent new installs from flooding the channel
if(defined($$self{lastrev})) {
Expand Down Expand Up @@ -103,6 +108,7 @@ sub output_item {
$log = join("\n", @lines);

$prefix = longest_common_prefix(@files);
$prefix //= '/';
$prefix =~ s|^/||; # cut off the leading slash
if(scalar @files > 1) {
$prefix .= " (" . scalar(@files) . " files)";
Expand Down
6 changes: 0 additions & 6 deletions modules/local/todo

This file was deleted.

82 changes: 82 additions & 0 deletions t/rakudolog.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!perl
use strict;
use warnings;

use Test::More;
use Cwd;
use lib getcwd();
use t::util;
load_plugin("rakudolog");

my $tests;
BEGIN { $tests = 0; };

plan tests => $tests;

my $xml_header = << '__XML__';
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:github.com,2008:/feeds/rakudo/commits/rakudo/master</id>
<link type="text/html" rel="alternate" href="http://github.com/rakudo/rakudo/commits/master/"/>
<link type="application/atom+xml" rel="self" href="http://github.com/feeds/rakudo/commits/rakudo/master"/>
<title>Recent Commits to rakudo:master</title>
__XML__

my $xml_footer = << '__XML__';
<entry>
<id>tag:github.com,2008:Grit::Commit/c7d2d7784f80b2c9f05b68d4aa5a6e21a2f2a257</id>
<link type="text/html" rel="alternate" href="http://github.com/rakudo/rakudo/commit/c7d2d7784f80b2c9f05b68d4aa5a6e21a2f2a257"/>
<title>Merge branch 'master' of git@github.com:rakudo/rakudo</title>
<updated>2009-05-01T09:32:55-07:00</updated>
<content type="html">&lt;pre&gt;
Merge branch 'master' of git@github.com:rakudo/rakudo&lt;/pre&gt;</content>
<author>
<name>pmichaud</name>
</author>
</entry>
</feed>
__XML__

# initial sync
my $xml = $xml_header . '<updated>2009-05-01T09:32:55-07:00</updated>' . $xml_footer;
my $feed = XML::Atom::Feed->new(\$xml);
my $rl = modules::local::rakudolog->get_self();
ok(!exists($$rl{lastrev}), "no lastrev by default");
call_func('process_feed', $feed);
my $output = [output()];
is(scalar @$output, 0, "nothing output the first time around");
is($$rl{lastrev}, "2009-05-01T09:32:55-07:00", "lastrev was set");
BEGIN { $tests += 3 };

# update
$xml_footer = << '__XML__' . $xml_footer;
<entry>
<id>tag:github.com,2008:Grit::Commit/7f5af50c19baf360dacc5779b9c013fb14db34d3</id>
<link type="text/html" rel="alternate" href="http://github.com/rakudo/rakudo/commit/7f5af50c19baf360dacc5779b9c013fb14db34d3"/>
<title>Big refactor of Rakudo's enums, making them more compliant with S12, and building them with much less generated code. Track an enum related grammar change from STD.pm too. Also gets rid of various bits of cruft that only hung around because of the previous enums implementation needing them. Bool is no longer sort-of-enum-ish (before we had some curious interactions there). Also an infinite loop in infix:&lt;but&gt; is fixed.</title>
<updated>2009-05-01T09:58:40-07:00</updated>
<content type="html">&lt;pre&gt;m src/builtins/enums.pir
m src/builtins/guts.pir
m src/builtins/op.pir
m src/classes/Abstraction.pir
m src/classes/Bool.pir
m src/parser/actions.pm
m src/parser/grammar.pg
Big refactor of Rakudo's enums, making them more compliant with S12, and building them with much less generated code. Track an enum related grammar change from STD.pm too. Also gets rid of various bits of cruft that only hung around because of the previous enums implementation needing them. Bool is no longer sort-of-enum-ish (before we had some curious interactions there). Also an infinite loop in infix:&amp;lt;but&amp;gt; is fixed.&lt;/pre&gt;</content>
<author>
<name>jnthn</name>
</author>
</entry>
__XML__
$xml = $xml_header . '<updated>2009-05-01T09:58:40-07:00</updated>' . $xml_footer;
$feed = XML::Atom::Feed->new(\$xml);
call_func('process_feed', $feed);
$output = [output()];
is(scalar @$output, 6, "6 lines of output");
is($$output[0]{net} , 'magnet' , "line to magnet/#parrot");
is($$output[0]{chan}, '#parrot' , "line to magnet/#parrot");
is($$output[1]{net} , 'freenode', "line to freenode/#perl6");
is($$output[1]{chan}, '#perl6' , "line to freenode/#perl6");
is($$rl{lastrev}, "2009-05-01T09:58:40-07:00", "lastrev was updated");
BEGIN { $tests += 6 };
47 changes: 47 additions & 0 deletions t/util.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package t::util;
use strict;
use warnings;
use Perl6::Export::Attrs;

my $module;
my $inst;
sub load_plugin :Export(:DEFAULT) {
$module = shift;
do "modules/local/$module.pm";
$module = "modules::local::$module";
$inst = $module;
call_func('init');
}

sub call_func :Export(:DEFAULT) {
my $func = shift;
return $inst->$func(@_);
}

my @output;

sub output :Export(:DEFAULT) {
my $line = shift;
return @output unless defined $line;
return undef unless exists $output[$line];
return $output[$line];
}

sub reset_output :Export(:DEFAULT) {
@output = ();
}


package main;

# stubs
sub create_timer { my ($timername, $self, $functionname, $timeout) = @_; }
sub lprint { my $line = shift; }

# gather output for test
sub send_privmsg {
my ($net, $chan, $text) = @_;
push(@output, { net => $net, chan => $chan, text => $text });
}

1;

0 comments on commit 27825ff

Please sign in to comment.