Permalink
Browse files

initial

  • Loading branch information...
1 parent c232134 commit 3953e38e8cb99f047402e655b30f1c804d7b2fbc @gam committed Apr 22, 2012
Showing with 124 additions and 1 deletion.
  1. +5 −1 README.md
  2. +7 −0 bin/autorun.pl
  3. +49 −0 lib/Test/Junkie.pm
  4. +63 −0 t/tracker.t
View
@@ -1,4 +1,8 @@
test-junkie
===========
-Continuous test runner for Perl 6
+Continuous test runner for Perl 6
+
+Initial version is based on masak's mini-tote Gist for all functionality.
+
+See: https://gist.github.com/834500
View
@@ -0,0 +1,7 @@
+#! /usr/bin/env perl6
+use v6;
+use Test::Junkie;
+
+my $tracker = Test::Junkie::Tracker.new;
+$tracker.start;
+
View
@@ -0,0 +1,49 @@
+module Test::Junkie;
+
+class Tracker {
+ has @.directories;
+ has $!timestamp;
+
+ multi method new() { self.bless(*, directories => <lib t>) }
+ multi method new(*@directories) { self.bless(*, :@directories) }
+
+ submethod BUILD(:@directories) {
+ @!directories = @directories;
+ }
+
+ method files() {
+ gather find_files @.directories;
+ }
+
+ method changed() {
+ $.files.grep({ .changed after $!timestamp });
+ }
+
+ method update_timer {
+ $!timestamp = time;
+ }
+
+ method start {
+ say "Starting Test::Junkie - don't say we didn't warn you!" ;
+ loop {
+ $.update_timer;
+ run_tests($.changed);
+ sleep .5 until $.changed;
+ }
+ }
+
+ sub run_tests(@tests) {
+ shell "PERL6LIB=lib prove -v -e perl6 @tests».path.sort()";
+ }
+
+ sub find_files(*@dirs) {
+ for @dirs -> $directory {
+ for dir($directory) -> $file {
+ given "$directory/$file".IO {
+ when .f { take $_ }
+ when .d { find_files .path }
+ }
+ }
+ }
+ }
+}
View
@@ -0,0 +1,63 @@
+use v6;
+use Test;
+use Test::Junkie;
+
+# tracker directory initialization
+{
+ my @directory_list = <directory1 directory2 directory3>;
+ my Test::Junkie::Tracker $directory_tracker = Test::Junkie::Tracker.new(@directory_list);
+ my Test::Junkie::Tracker $default_tracker = Test::Junkie::Tracker.new;
+
+ is $default_tracker.directories, <lib t>, "default directories should be are 'lib' and 't'";
+ is $directory_tracker.directories, @directory_list , "tracked directories should be configurable at instanciation";
+}
+
+# resolving tracked files
+{
+ my Test::Junkie::Tracker $tracker = Test::Junkie::Tracker.new();
+
+ my @actual = $tracker.files.map({.path});
+ my @expected = <lib/Test/Junkie.pm t/tracker.t>;
+
+ is @actual, @expected, "should track .pm and .t files in the configured directory trees";
+}
+
+# refreshing tracked files
+{
+ my Test::Junkie::Tracker $tracker = Test::Junkie::Tracker.new();
+ my $num_tracked_files = $tracker.files.elems;
+
+ my $tempfile = 't/temporary_file-' ~ $*PID ~ '.t';
+ create_temporary_file($tempfile);
+
+ is $tracker.files.elems, $num_tracked_files + 1, "should update tracked files if new file added";
+
+ remove_temporary_file($tempfile);
+}
+
+# checking for changed files
+{
+ my $tempfile = 't/temporary_file-' ~ $*PID ~ '.t';
+ my Test::Junkie::Tracker $tracker = Test::Junkie::Tracker.new();
+
+ $tracker.update_timer;
+ sleep 2;
+
+ create_temporary_file($tempfile);
+
+ is $tracker.changed.map({.path}), $tempfile, 'should return file(s) changed since last timer update';
+
+ remove_temporary_file($tempfile);
+}
+
+sub create_temporary_file(Str $file) {
+ my $fh = open $file, :w orelse die "Could not create $file";
+ $fh.close;
+}
+
+sub remove_temporary_file(Str $file) {
+ unlink $file;
+ ok($file.IO ~~ :!e, "cleanup: removed test file $file");
+}
+
+done;

0 comments on commit 3953e38

Please sign in to comment.