Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
1 deletion.
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 |
---|---|---|
@@ -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 |
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,7 @@ | ||
#! /usr/bin/env perl6 | ||
use v6; | ||
use Test::Junkie; | ||
|
||
my $tracker = Test::Junkie::Tracker.new; | ||
$tracker.start; | ||
|
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,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 } | ||
} | ||
} | ||
} | ||
} | ||
} |
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,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; |