Permalink
Browse files

add Stylish::Project and Stylish::Project::REPL

  • Loading branch information...
1 parent 0f57112 commit 59d5382eb8415b934e5b00f4c42a24b59b86c45e @jrockway committed Apr 25, 2010
Showing with 117 additions and 0 deletions.
  1. +1 −0 .eproject
  2. +6 −0 Makefile.PL
  3. +38 −0 t/project/basic.t
  4. +72 −0 t/project/repl.t
View
@@ -1 +1,2 @@
:mxdeclare-project-p t
+
View
@@ -4,4 +4,10 @@ use strict;
name 'Stylish';
all_from 'lib/Stylish.pm';
+requires 'AnyEvent';
+requires 'AnyEvent::Inotify::Simple';
+requires 'AnyEvent::REPL';
+requires 'AnyEvent::Term';
+requires 'Coro';
+
WriteAll;
View
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Stylish::Project;
+use Directory::Scratch;
+
+my $tmp = Directory::Scratch->new;
+$tmp->mkdir('t');
+$tmp->mkdir('lib/Test/Project');
+$tmp->touch('lib/Test/Project.pm', "class Test::Project {","}");
+$tmp->touch('lib/Test/Project/Module.pm', "class Test::Project::Module {","}");
+
+my $changes = 0;
+my $project = Stylish::Project->new(
+ root => "$tmp",
+ on_change => [sub { $changes++ }],
+);
+
+is_deeply [sort $project->get_libraries],
+ ['lib/Test/Project.pm', 'lib/Test/Project/Module.pm'],
+ 'got library files';
+
+is_deeply [sort $project->get_modules],
+ ['Test::Project', 'Test::Project::Module'],
+ 'got modules';
+
+$tmp->delete('lib/Test/Project.pm');
+
+$project->_inotify->poll;
+
+is $changes, 1, 'got delete';
+
+is_deeply [$project->get_libraries],
+ ['lib/Test/Project/Module.pm'],
+ 'got library files';
+
+done_testing;
View
@@ -0,0 +1,72 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Stylish::Project;
+use Stylish::REPL::Project;
+use Directory::Scratch;
+
+use Coro;
+
+my $rchange = AnyEvent->condvar;
+
+my $tmp = Directory::Scratch->new;
+$tmp->mkdir('lib');
+
+my $project = Stylish::Project->new(
+ root => "$tmp",
+ on_change => [],
+);
+
+my $repl = Stylish::REPL::Project->new(
+ project => $project,
+ on_repl_change => sub { $rchange->send(@_) },
+ on_output => sub { diag(join '', @_) },
+);
+
+async {
+ is $repl->push_eval("2 + 2"), '4', 'repl works';
+ is $repl->push_eval("`pwd`"), "$tmp", 'pwd is correct';
+}->join;
+
+$tmp->touch(
+ 'lib/Test.pm',
+ 'use MooseX::Declare;',
+ 'class Test {',
+ ' has \'foo\' => ( is => \'ro\', required => 1 );',
+ ' method bar { "OH HAI: ". $self->foo }',
+ '}',
+ '1;',
+);
+
+is $rchange->recv, '1', 'got next generation REPL';
+
+async {
+ like $repl->push_eval('my $test = Test->new( foo => 42 )'),
+ qr/Test=HASH/,
+ 'got Test object';
+ is $repl->push_eval('$test->bar'), 'OH HAI: 42', 'the object works!';
+}->join;
+
+$rchange = AnyEvent->condvar;
+
+$tmp->touch(
+ 'lib/Test.pm',
+ 'use MooseX::Declare;',
+ 'class Test {',
+ ' has \'foo\' => ( is => \'ro\', required => 1 );',
+ ' method bar { "Oh, hello: ". $self->foo }',
+ '}',
+ '1;',
+);
+
+is $rchange->recv, '2', 'got next generation REPL';
+
+async {
+ like $repl->push_eval('my $test = Test->new( foo => 42 )'),
+ qr/Test=HASH/,
+ 'got Test object';
+ is $repl->push_eval('$test->bar'), 'Oh, hello: 42', 'the new code took effect!';
+}->join;
+
+done_testing;

0 comments on commit 59d5382

Please sign in to comment.