stop using return_stack directly in tests
Matt S Trout [Mon, 3 Feb 2014 04:47:58 +0000 (04:47 +0000)]
t/basic.t
t/ssh_key.t

index 936a847..be3e32d 100644 (file)
--- a/t/basic.t
+++ b/t/basic.t
@@ -120,18 +120,13 @@ my $inner_op = make_op($pop_stack);
 my $call_op = FromCode->new(
   code => sub {
     my ($self, $state) = @_;
-    my @rst = @{$state->return_stack};
     my $save_scope = $state->scope;
     my %scope = (S => $save_scope->{S});
     my $ret_op = FromCode->new(
       code => sub { $_[1]->but(scope => $save_scope, next_op => $_[0]->next) },
       next => $self->next,
     );
-    $state->but(
-      scope => \%scope,
-      return_stack => [ @rst, $ret_op ],
-      next_op => $inner_op
-    );
+    $state->but(scope => \%scope)->push_return_then($ret_op, $inner_op);
   },
   next => FromCode->new(
     code => bind_array(P => \@shells),
@@ -173,10 +168,8 @@ my $or_code = sub {
   my $inner_or = FromCode->new(
     code => sub { $_[1]->then($var->bound_value) }
   );
-  $state->but(
-    return_stack => [ @{$state->return_stack}, $self->next ],
-    next_op => $inner_or
-  )->mark_choice($var);
+  $state->push_return_then($self->next, $inner_or)
+        ->mark_choice($var);
 };
 
 my $top_or = FromCode->new(
index 8d8d5c9..b7ed6ed 100644 (file)
@@ -64,11 +64,9 @@ sub make_exists {
       code => sub { $_[1]->but(scope => $scope, next_op => $_[0]->next) },
       next => $self->next,
     );
-    $state->but(
-      scope => { %$scope },
-      return_stack => [ @{$state->return_stack}, $ret_op ],
-      next_op => $inner_op
-    )->assign_vars(%vars);
+    $state->but(scope => { %$scope })
+          ->push_return_then($ret_op, $inner_op)
+          ->assign_vars(%vars);
   };
 }
 
@@ -93,14 +91,12 @@ sub make_call {
         die "WTH";
       }
     } @arg_spec;
-    $state->but(
-      scope => {},
-      return_stack => [ @{$state->return_stack}, $ret_op ],
-      next_op => FromCode->new(
-        code => sub { $option->(@_, @args) },
-        next => $pop_ret,
-      ),
+    my $next_op = FromCode->new(
+      code => sub { $option->(@_, @args) },
+      next => $pop_ret,
     );
+    $state->but(scope => {})
+          ->push_return_then($ret_op, $next_op);
   };
 }