[Bps-public-commit] r11274 - in SVN-PropDB: . t

jesse at bestpractical.com jesse at bestpractical.com
Sun Mar 30 16:48:43 EDT 2008


Author: jesse
Date: Sun Mar 30 16:48:43 2008
New Revision: 11274

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/lib/Prophet/Record.pm
   SVN-PropDB/lib/Prophet/Test.pm
   SVN-PropDB/t/cli.t

Log:
 r28797 at 68-247-16-135:  jesse | 2008-03-30 10:48:18 -1000
 * dealt with annoying "base64 encoded uuids sometimes contain /" bug.
 * check cli search output
 * alice and bob can now have separate replicas


Modified: SVN-PropDB/lib/Prophet/Record.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Record.pm	(original)
+++ SVN-PropDB/lib/Prophet/Record.pm	Sun Mar 30 16:48:43 2008
@@ -54,8 +54,7 @@
 sub create {
     my $self = shift;
     my %args = validate(@_, {  props => 1});
-        my $uuid = $UUIDGEN->create_b64;
-        $uuid =~ s/==$//g;
+        my $uuid = $UUIDGEN->create_str;
 
     $self->uuid($uuid);
 

Modified: SVN-PropDB/lib/Prophet/Test.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test.pm	(original)
+++ SVN-PropDB/lib/Prophet/Test.pm	Sun Mar 30 16:48:43 2008
@@ -1,18 +1,21 @@
 package Prophet::Test;
-
+use strict;
 use base qw/Test::More Exporter/;
-our @EXPORT = qw/as_alice as_bob as_charlie as_david/;
+our @EXPORT = qw/as_alice as_bob as_charlie as_david run_ok run_output_matches/;
 
 use File::Temp qw/tempdir/;
 use Path::Class 'dir';
+use Test::Exception;
+
 
 our $REPO_BASE = File::Temp::tempdir();
+Test::More->import;
+diag($REPO_BASE);
 
 sub import_extra {
     my $class = shift;
     my $args  = shift;
 
-    $class->setup($args);
     Test::More->export_to_level(2);
 
     # Now, clobber Test::Builder::plan (if we got given a plan) so we
@@ -23,6 +26,98 @@
     }
 }
 
+=head2 run_script SCRIPT_NAME [@ARGS]
+
+Runs the script SCRIPT_NAME as a perl script, setting the @INC to the same as our caller
+
+=cut
+
+
+sub run_script {
+    my $script = shift;
+    system($^X, (map { "-I$_" } @INC), 'bin/'.$script, @_);
+    Carp::croak $! if $?;
+    return;
+}
+
+=head2 run_ok SCRIPT_NAME [@ARGS] (<- optional hashref), optional message
+
+Runs the script, checking that it didn't error out.
+
+=cut
+
+sub run_ok {
+   my $script = shift;
+   my $args = shift if (ref $_[0] eq 'ARRAY');
+   my $msg = shift if (@_);
+   
+   lives_and {
+   
+      @_ = (run_script($script, @$args), $msg);
+      goto &Test::More::ok;
+};
+}
+
+sub _mk_cmp_closure {
+    my ($exp, $err, $negate) = @_;
+    my $line = 0;
+    sub {
+	my $output = shift;
+	chomp $output;
+	++$line;
+	unless (@$exp) {
+	    push @$err, "$line: got $output";
+	    return;
+	}
+	my $item = shift @$exp;
+	push @$err, "$line: got ($output), expect ($item)\n"
+	    unless ref($item) ? ($output =~ m/$item/)
+                       	      : ($output eq $item);
+    }
+}
+
+use IPC::Run3 'run3';
+
+=head2 is_script_output SCRIPTNAME \@ARGS, \@STDOUT_MATCH, \@STDERR_MATCH, $MSG
+
+Runs the script, checking to see that its output matches
+
+
+
+=cut
+
+sub is_script_output {
+    my ($script, $arg, $exp_stdout, $exp_stderr, $msg) = @_;
+    my $stdout_err = [];
+    $exp_stderr ||= [];
+    my @cmd = ($^X, (map { "-I$_" } @INC), 'bin/'.$script);
+
+    my $ret = run3 [@cmd, @$arg], undef,
+	_mk_cmp_closure($exp_stdout, $stdout_err,0), # stdout
+	_mk_cmp_closure($exp_stderr, $stdout_err,0); # stderr
+	
+    if (@$stdout_err) {
+    	@_ = (0, join(' ', "$msg:", $script, @$arg));
+	   diag("Different in line: ".join(',', @$stdout_err));
+    	goto \&ok;
+    }
+    else {
+    	@_ = (1, join(' ', "$msg:", $script, @$arg));
+    	goto \&ok;
+    }
+
+};
+
+sub run_output_matches {
+    my ($script, $args, $expected, $msg) = @_;
+    lives_and {
+        @_ = ($script, $args, $expected, [], $msg);
+        goto \&is_script_output;
+    };
+    
+
+}
+
 =head2 repo_path_for $USERNAME
 
 Returns a path on disk for where $USERNAME's replica is stored
@@ -75,10 +170,10 @@
 
 =cut
 
-as_alice (&) { as_user( alice => shift) }
-as_bob (&){ as_user( bob => shift) }
-as_charlie(&) { as_user( charlie => shift) }
-as_david(&) { as_user( david => shift) }
+sub as_alice (&) { as_user( alice => shift) }
+sub as_bob (&){ as_user( bob => shift) }
+sub as_charlie(&) { as_user( charlie => shift) }
+sub as_david(&) { as_user( david => shift) }
 
 
 

Modified: SVN-PropDB/t/cli.t
==============================================================================
--- SVN-PropDB/t/cli.t	(original)
+++ SVN-PropDB/t/cli.t	Sun Mar 30 16:48:43 2008
@@ -3,11 +3,18 @@
 use warnings;
 use strict;
 
-use Prophet::Test tests => 3;
-
+use Prophet::Test tests => 4;
 as_alice {
-    ok(`bin/prophet-node-create --type Bug --status new` );
-}
+    run_ok('prophet-node-create', [qw(--type Bug --status new)], "Created a record as alice"); 
+    run_output_matches('prophet-node-search', [qw(--type Bug --regex .)], [qr/new/], " Found our record");
+};
+
+
+as_bob {
+    run_ok('prophet-node-create', [qw(--type Bug --status open)], "Created a record as bob" );
+    run_output_matches('prophet-node-search', [qw(--type Bug --regex .)], [qr/open/], " Found our record");
+
+};
 
 # create 1 node
 # update the node



More information about the Bps-public-commit mailing list