make exists unnecessary
[scpubgit/DKit.git] / t / dot_ssh.t
index 1c752a7..9619022 100644 (file)
@@ -12,6 +12,8 @@ use Test::Exception;
 
   use Moo;
 
+  with 'DX::Role::Fact';
+
   has path => (is => 'ro', required => 1);
   has info => (is => 'ro', predicate => 1);
 
@@ -19,6 +21,8 @@ use Test::Exception;
 
   use Moo;
 
+  with 'DX::Role::Fact';
+
   has is_directory => (is => 'ro', default => 0);
   has is_file => (is => 'ro', default => 0);
   has mode => (is => 'ro', required => 1);
@@ -61,9 +65,8 @@ $solver->add_rule(@$_) for (
   [ path => [ qw(PS P) ],
     [ prop => 'PS', \'path', 'P' ] ],
   [ info_prop => [ qw(PS N V) ],
-    [ exists => [ qw(PSI) ],
-      [ prop => 'PS', \'info', 'PSI' ],
-      [ prop => 'PSI', 'N', 'V' ] ] ],
+    [ prop => 'PS', \'info', 'PSI' ],
+    [ prop => 'PSI', 'N', 'V' ] ],
   [ mode => [ qw(PS M) ],
     [ info_prop => 'PS', \'mode', 'M' ] ],
   [ exists_path => [ qw(PS) ],
@@ -231,11 +234,10 @@ $solver->add_rule(@$_) for (
     [ not => [ exists_path => 'PS' ] ],
     [ act => [ 'PS' ],
         sub {
-          my ($ps_var) = @_;
-          my ($id, $value) = ($ps_var->id, $ps_var->bound_value);
+          my ($value) = @_;
           DX::Action::FromCode->new(
             expect => sub {
-              ($id => My::PathStatus->new(
+              (path_status => My::PathStatus->new(
                 path => $value->path,
                 info => My::PathStatusInfo->new(
                   is_directory => 1, mode => ''
@@ -262,9 +264,7 @@ is(
   scalar(my ($action) = $res[0]->actions), 1
 );
 
-my ($type, $value) = $action->run;
-
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($action);
 
 ok(!$path_status{'.ssh'}, 'Empty retracted');
 
@@ -276,41 +276,27 @@ is($path_status{'.ssh'}, $protos{'.ssh'}, 'Created observed');
 
 ok(!$res[0]->actions, 'No action');
 
+$solver->add_predicate(
+  catfile => [ qw(DirPath FileName FilePath) ],
+    [ qw(+ + -) ] => sub {
+      +(FilePath => [ value => File::Spec->catfile($_{DirPath}, $_{FileName}) ])
+    },
+);
+
 $solver->add_rule(@$_) for (
-  [ catfile => [ qw(DirPath FileName FilePath) ],
-    DX::Op::FromCode->new(code => sub {
-      my ($self, $state) = @_;
-      my ($dir_path, $file_name, $file_path)
-        = map $state->scope_var($_), qw(DirPath FileName FilePath);
-      die "No." unless $dir_path->is_bound;
-      die "No." unless $file_name->is_bound;
-      die "No." if $file_path->is_bound;
-      my $cat_file = File::Spec->catfile(
-        map $_->bound_value, $dir_path, $file_name
-      );
-      $state->bind_value($file_path->id, $cat_file)
-            ->add_dependencies(
-                $file_path->id => $dir_path->id,
-                $file_path->id => $file_name->id,
-              )
-            ->then($self->next);
-    }) ],
   [ file_in => [ qw(DirStatus FileName FileStatus) ],
     [ is_directory => qw(DirStatus) ],
-    [ exists => [ qw(DirPath) ],
-      [ path => qw(DirStatus DirPath) ],
-      [ exists => [ qw(FilePath) ],
-        [ catfile => qw(DirPath FileName FilePath) ],
-        [ file_at => qw(FileStatus FilePath) ] ] ] ],
+    [ path => qw(DirStatus DirPath) ],
+    [ catfile => qw(DirPath FileName FilePath) ],
+    [ file_at => qw(FileStatus FilePath) ] ],
   [ is_file => [ qw(PS) ],
     [ not => [ exists_path => 'PS' ] ],
     [ act => [ 'PS' ],
         sub {
-          my ($ps_var) = @_;
-          my ($id, $value) = ($ps_var->id, $ps_var->bound_value);
+          my ($value) = @_;
           DX::Action::FromCode->new(
             expect => sub {
-              ($id => My::PathStatus->new(
+              (path_status => My::PathStatus->new(
                 path => $value->path,
                 info => My::PathStatusInfo->new(
                   is_file => 1, mode => ''
@@ -341,11 +327,11 @@ is(scalar @res, 1, 'One result');
 
 is(scalar(my @act = $res[0]->actions), 2, 'Two actions');
 
-is(scalar(my ($poss) = grep !@{$_->dependencies}, @act), 1, 'One possible');
+#::Dwarn(\@act);
 
-($type, $value) = $poss->run;
+is(scalar(my ($poss) = grep !@{$_->dependencies}, @act), 1, 'One possible');
 
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($poss);
 
 @res = keys_file()->results;
 
@@ -356,9 +342,7 @@ is(
   'One possible'
 );
 
-($type, $value) = $poss->run;
-
-$solver->facts->{$type}->remove_value($value);
+$solver->run_action($poss);
 
 @res = keys_file()->results;