expunge [ value => $value ] style in favour of scalarrefs
[scpubgit/DKit.git] / t / dot_ssh.t
index 2e37b31..d55b5d5 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) ],
@@ -80,7 +83,7 @@ $solver->add_rule(@$_) for (
 
 sub paths_for_simple {
   join ' ', map $_->value_for('PS')->path, $solver->query(
-    [ qw(PS) ], [ path_status => 'PS' ], @_
+    [ path_status => 'PS' ], @_
   )->results;
 }
 
@@ -90,7 +93,7 @@ is(paths_for_simple([ is_directory => 'PS' ]), '.ssh');
 
 is(paths_for_simple([ is_file => 'PS' ]), '.ssh/authorized_keys');
 
-is(paths_for_simple([ mode => 'PS', [ value => '0755' ] ]), '.ssh');
+is(paths_for_simple([ mode => 'PS', \'0755' ]), '.ssh');
 
 $solver->add_rule(
   path_status_at => [ 'PS', 'P' ],
@@ -104,8 +107,7 @@ $solver->add_rule(
 
 throws_ok {
   $solver->query(
-    [ qw(PS) ],
-      [ path_status_at => 'PS', [ value => '.ssh' ] ]
+    [ path_status_at => 'PS', \'.ssh' ]
   )->results
 } qr/ARGH/;
 
@@ -126,8 +128,7 @@ my @res;
 
 lives_ok {
   @res = $solver->query(
-    [ qw(PS) ],
-      [ path_status_at => 'PS', [ value => '.ssh' ] ]
+    [ path_status_at => 'PS', \'.ssh' ]
   )->results
 };
 
@@ -163,22 +164,22 @@ $solver->add_rule(
 $ob_res{'.ssh'} = $protos{'.ssh'};
 
 sub paths_for {
-  join ' ', map $_->value_for('PS')->path, $solver->query([ 'PS' ], @_)->results;
+  join ' ', map $_->value_for('PS')->path, $solver->query(@_)->results;
 }
 
 is(
-  paths_for([ path_status => 'PS' ], [ path => 'PS', [ value => '.ssh' ] ]),
+  paths_for([ path_status => 'PS' ], [ path => 'PS', \'.ssh' ]),
   '',
   'no .ssh entry'
 );
 
-throws_ok { paths_for([ path_status_at => 'PS', [ value => '.ssh' ] ]) }
+throws_ok { paths_for([ path_status_at => 'PS', \'.ssh' ]) }
   qr/refused/;
 
 $solver->{observation_policy} = sub { 1 };
 
 is(
-  paths_for([ path_status_at => 'PS', [ value => '.ssh' ] ]),
+  paths_for([ path_status_at => 'PS', \'.ssh' ]),
   '.ssh',
   'observation'
 );
@@ -187,7 +188,7 @@ is($path_status{'.ssh'}, $ob_res{'.ssh'});
 
 delete $solver->{observation_policy};
 
-lives_ok { paths_for([ path_status_at => 'PS', [ value => '.ssh' ] ]) }
+lives_ok { paths_for([ path_status_at => 'PS', \'.ssh' ]) }
   'No observation required anymore';
 
 $path_status{'.ssh/authorized_keys'} = $protos{'.ssh/authorized_keys'};
@@ -216,7 +217,7 @@ $ob_res{'.ssh'} = $empty{'.ssh'};
 $solver->{observation_policy} = sub { 1 };
 
 sub dot_ssh_query {
-  $solver->query([ 'PS' ], [ directory_at => 'PS' => [ value => '.ssh' ] ]);
+  $solver->query([ directory_at => 'PS' => \'.ssh' ]);
 }
 
 is_deeply(
@@ -224,18 +225,17 @@ is_deeply(
   []
 );
 
-#::Dwarn(paths_for([ directory_at => 'PS', [ value => '.ssh' ] ]));
+#::Dwarn(paths_for([ directory_at => 'PS', \'.ssh' ]));
 
 $solver->add_rule(@$_) for (
   [ is_directory => [ 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_directory => 1, mode => ''
@@ -274,41 +274,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 => ''
@@ -327,7 +313,7 @@ $solver->add_rule(@$_) for (
 %ob_res = %empty;
 
 sub keys_file {
-  $solver->query([ qw(D F) ],
+  $solver->query(
      [ directory_at => 'D' => \'.ssh' ],
      [ file_in => 'D' => \'authorized_keys' => 'F' ],
    );
@@ -339,6 +325,8 @@ is(scalar @res, 1, 'One result');
 
 is(scalar(my @act = $res[0]->actions), 2, 'Two actions');
 
+#::Dwarn(\@act);
+
 is(scalar(my ($poss) = grep !@{$_->dependencies}, @act), 1, 'One possible');
 
 $solver->run_action($poss);