aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-12-28 18:10:52 +0000
committerdakkar <dakkar@thenautilus.net>2016-12-28 18:12:50 +0000
commite36566e2918b5252bd0462ee9e88ffe9528975e7 (patch)
treed0d88d513952cd5eaa8513ac6558095a20548bfd
parenttest for mail_store coercion (diff)
downloadSietima-e36566e2918b5252bd0462ee9e88ffe9528975e7.tar.gz
Sietima-e36566e2918b5252bd0462ee9e88ffe9528975e7.tar.bz2
Sietima-e36566e2918b5252bd0462ee9e88ffe9528975e7.zip
test for CmdLine
-rw-r--r--lib/Sietima/CmdLine.pm23
-rw-r--r--t/tests/sietima/cmdline.t82
2 files changed, 99 insertions, 6 deletions
diff --git a/lib/Sietima/CmdLine.pm b/lib/Sietima/CmdLine.pm
index 3d78be2..20141df 100644
--- a/lib/Sietima/CmdLine.pm
+++ b/lib/Sietima/CmdLine.pm
@@ -29,20 +29,31 @@ sub BUILDARGS($class,@args) {
return $args;
}
-sub run($self) {
+has app_spec => (
+ is => 'lazy',
+ init_arg => undef,
+);
+
+sub _build_app_spec($self) {
my $spec_data = $self->sietima->command_line_spec();
- my $app_spec = App::Spec->read({
+ return App::Spec->read({
$spec_data->%*,
$self->extra_spec->%*,
});
+}
- my $runner = Sietima::Runner->new({
- spec => $app_spec,
+has runner => (
+ is => 'lazy',
+ init_arg => undef,
+ handles => [qw(run)],
+);
+
+sub _build_runner($self) {
+ return Sietima::Runner->new({
+ spec => $self->app_spec,
cmd => $self->sietima,
});
-
- $runner->run;
}
1;
diff --git a/t/tests/sietima/cmdline.t b/t/tests/sietima/cmdline.t
new file mode 100644
index 0000000..bd24c84
--- /dev/null
+++ b/t/tests/sietima/cmdline.t
@@ -0,0 +1,82 @@
+#!perl
+use lib 't/lib';
+use Test::Sietima;
+use Path::Tiny;
+use Sietima;
+use Sietima::CmdLine;
+
+subtest 'given instance' => sub {
+ my $s = Sietima->new({
+ return_path => 'list@example.com',
+ });
+ my $c = Sietima::CmdLine->new({
+ sietima => $s,
+ });
+ is(
+ $c,
+ object {
+ call app_spec => object {
+ call name => 'sietima';
+ call subcommands => hash {
+ field send => object {
+ call name => 'send';
+ };
+ etc;
+ };
+ };
+ call runner => object {
+ call cmd => $s;
+ };
+ },
+ 'spec & runner should be built',
+ );
+};
+
+subtest 'built via args' => sub {
+ my $c = Sietima::CmdLine->new({
+ args => {
+ return_path => 'list@example.com',
+ },
+ });
+ is(
+ $c,
+ object {
+ call sietima => object {
+ call return_path => 'list@example.com';
+ };
+ },
+ 'sietima should be built',
+ );
+};
+
+subtest 'built via args & traits' => sub {
+ my $c = Sietima::CmdLine->new({
+ traits => [ qw(ReplyTo) ],
+ args => {
+ return_path => 'list@example.com',
+ },
+ });
+ DOES_ok(
+ $c->sietima,
+ ['Sietima::Role::ReplyTo'],
+ 'sietima should be built with the given trait',
+ );
+};
+
+subtest 'extra spec' => sub {
+ my $c = Sietima::CmdLine->new({
+ extra_spec => { name => 'different' },
+ args => {
+ return_path => 'list@example.com',
+ },
+ });
+ is(
+ $c->app_spec,
+ object {
+ call name => 'different';
+ },
+ 'spec fields should be overridden',
+ );
+};
+
+done_testing;