[Bps-public-commit] Prophet branch, master, updated. a999708effcd6fa858d69a68cceb8ba9906fa242
spang at bestpractical.com
spang at bestpractical.com
Mon Aug 10 14:13:14 EDT 2009
The branch, master has been updated
via a999708effcd6fa858d69a68cceb8ba9906fa242 (commit)
from 374af585c21494ad5f4f0d2d12f2855c6eabb702 (commit)
Summary of changes:
lib/Prophet/CLI.pm | 44 -------------------------------
lib/Prophet/Test.pm | 21 +++++++++++++-
t/Settings/lib/App/Settings/Test.pm | 20 +------------
t/Settings/t/database-settings-editor.t | 16 +++++-----
t/Settings/t/sync-database-settings.t | 24 ++++++++--------
5 files changed, 41 insertions(+), 84 deletions(-)
- Log -----------------------------------------------------------------
commit a999708effcd6fa858d69a68cceb8ba9906fa242
Author: Christine Spang <spang at bestpractical.com>
Date: Mon Aug 10 19:12:05 2009 +0100
Kill Prophet::CLI->invoke, make Prophet::Test::run_command use clean output redirection
diff --git a/lib/Prophet/CLI.pm b/lib/Prophet/CLI.pm
index ffcea01..8e814a4 100644
--- a/lib/Prophet/CLI.pm
+++ b/lib/Prophet/CLI.pm
@@ -143,50 +143,6 @@ sub tokenize {
return @tokens;
}
-
-=head2 invoke outhandle, error_variable_ref, ARGV_COMPATIBLE_ARRAY
-
-Run the given command. If outhandle is true, select that as the file handle
-for the duration of the command. If error_variable_ref is true, STDERR
-will be redirected to that scalar for the duration of the command.
-
-=cut
-
-sub invoke {
- my ($self, $output, $error, @args) = @_;
-
- # save old STDOUT for later restoration and select $output as the
- # new default filehandle
- my $original_stdout;
- $original_stdout = select $output if $output;
-
- my $original_stderr;
- # save STDERR away for later restoration
- if ( ref $error ) {
- open $original_stderr, '>&', \*STDERR;
- close STDERR;
- open STDERR, ">", $error or die "Couldn't open STDERR for redirection: $!";
- }
-
- my $ret = eval {
- local $SIG{__DIE__} = 'DEFAULT';
- $self->run_one_command(@args);
- };
- warn $@ if $@;
-
- if ( ref $error ) {
- # restore STDERR
- close STDERR;
- open STDERR, ">", $original_stderr;
- }
-
- # restore STDOUT
- select $original_stdout if $original_stdout;
-
- return $ret;
-}
-
-
sub is_interactive {
return -t STDIN && -t STDOUT;
}
diff --git a/lib/Prophet/Test.pm b/lib/Prophet/Test.pm
index dbceb8b..2d797c8 100644
--- a/lib/Prophet/Test.pm
+++ b/lib/Prophet/Test.pm
@@ -317,12 +317,29 @@ Examples:
=cut
+our $CLI_CLASS = 'Prophet::CLI';
+
sub run_command {
my $output = '';
my $error = '';
- open my $out_handle, '>', \$output;
- Prophet::CLI->new->invoke($out_handle, \$error, @_);
+ my $original_stdout = *STDOUT;
+ my $original_stderr = *STDERR;
+ open( my $out_handle, '>', \$output );
+ open( my $err_handle, '>', \$error );
+ *STDOUT = $out_handle;
+ *STDERR = $err_handle;
+ $|++; # autoflush
+
+ my $ret = eval {
+ local $SIG{__DIE__} = 'DEFAULT';
+ $CLI_CLASS->new->run_one_command(@_);
+ };
+ warn $@ if $@;
+
+ # restore to originals
+ *STDOUT = $original_stdout;
+ *STDERR = $original_stderr;
return wantarray ? ($output, $error) : $output;
}
diff --git a/t/Settings/lib/App/Settings/Test.pm b/t/Settings/lib/App/Settings/Test.pm
index 2fc423e..3194dce 100644
--- a/t/Settings/lib/App/Settings/Test.pm
+++ b/t/Settings/lib/App/Settings/Test.pm
@@ -7,28 +7,12 @@ use base qw(Prophet::Test Exporter);
use lib 't/Settings/lib';
use App::Settings::CLI;
-our @EXPORT = qw/as_alice as_bob diag run_settings_command like ok
+our @EXPORT = qw/as_alice as_bob diag run_command like ok
repo_uri_for/;
Prophet::Test->import;
-# don't use Prophet::Test::run_command since we want our app to be
-# App::Settings rather than Prophet::App
-sub run_settings_command {
- my $output = '';
- my $error = '';
- open my $out_handle, '>', \$output;
-
- # feed a persistent handle in to keep the prop cache between
- # commands (clear the handle's cache if something not using
- # this handle object changes props on disk; for example a
- # subprocess using run_output_matches and friends)
- App::Settings::CLI->new->invoke(
- $out_handle, \$error, @_,
- );
-
- return wantarray ? ($output, $error) : $output;
-}
+$Prophet::Test::CLI_CLASS = 'App::Settings::CLI';
1;
diff --git a/t/Settings/t/database-settings-editor.t b/t/Settings/t/database-settings-editor.t
index 02440f5..d0cd7af 100644
--- a/t/Settings/t/database-settings-editor.t
+++ b/t/Settings/t/database-settings-editor.t
@@ -17,11 +17,11 @@ BEGIN {
diag $ENV{'PROPHET_REPO'};
}
-my $out = run_settings_command( 'init' );
+my $out = run_command( 'init' );
is( $out, "Initialized your new Prophet database.\n", 'replica init' );
# test noninteractive set
-$out = run_settings_command(
+$out = run_command(
'settings', 'set', '--', 'statuses', '["new","open","stalled"]',
);
my $expected = <<'END_OUTPUT';
@@ -33,7 +33,7 @@ is( $out, $expected, "settings set went ok" );
# check with settings show
my $valid_settings_output = Prophet::Util->slurp('t/data/settings-first.tmpl');
-$out = run_settings_command( qw/settings/ );
+$out = run_command( qw/settings/ );
is( $out, $valid_settings_output, "changed settings output matches" );
# test settings (interactive editing)
@@ -45,7 +45,7 @@ diag ("interactive template status will be found in $filename");
Prophet::Test->set_editor_script("settings-editor.pl --first $filename");
# then edit the settings
-# (can't use run_settings_command with editor scripts because they don't play nicely
+# (can't use run_command with editor scripts because they don't play nicely
# with output redirection)
run_output_matches( 'settings', [ 'settings', 'edit' ],
[
@@ -63,10 +63,10 @@ $valid_settings_output = Prophet::Util->slurp('t/data/settings-second.tmpl');
# look up db uuid and clear the prop cache, since we've modified the
# on-disk props via another process
-my ($db_uuid) = (run_settings_command( 'info' ) =~ /DB UUID: (.*)\n/);
+my ($db_uuid) = (run_command( 'info' ) =~ /DB UUID: (.*)\n/);
Prophet::Replica::sqlite::clear_prop_cache( $db_uuid );
-($out, my $error) = run_settings_command( qw/settings show/ );
+($out, my $error) = run_command( qw/settings show/ );
is( $out, $valid_settings_output, "changed settings output matches" );
warn "going to print error of settings show";
diag $error;
@@ -92,6 +92,6 @@ is($template_ok, 'ok!', "interactive template was correct");
# check the settings with settings show
$valid_settings_output = Prophet::Util->slurp('t/data/settings-third.tmpl');
-# run_settings_command( 'settings' );
-$out = run_settings_command( qw/settings show/ );
+# run_command( 'settings' );
+$out = run_command( qw/settings show/ );
is( $out, $valid_settings_output, 'changed settings output matches' );
diff --git a/t/Settings/t/sync-database-settings.t b/t/Settings/t/sync-database-settings.t
index 9e80e27..c915a41 100644
--- a/t/Settings/t/sync-database-settings.t
+++ b/t/Settings/t/sync-database-settings.t
@@ -6,41 +6,41 @@ use lib 't/Settings/lib';
use App::Settings::Test tests => 12;
as_alice {
- ok( run_settings_command( qw(init) ), 'replica init' );
- ok( run_settings_command( qw(create --type Bug -- --status new --from alice ) ),
+ ok( run_command( qw(init) ), 'replica init' );
+ ok( run_command( qw(create --type Bug -- --status new --from alice ) ),
'Created a record as alice' );
- my $output = run_settings_command( qw(search --type Bug --regex .) );
+ my $output = run_command( qw(search --type Bug --regex .) );
like( $output, qr/new/, 'Found our record' );
- $output = run_settings_command( qw(settings show) );
+ $output = run_command( qw(settings show) );
like( $output, qr/default_status: \["new"\]/,
'the original milestone list is there');
- ok( run_settings_command( qw(settings set -- default_status ["open"]) ),
+ ok( run_command( qw(settings set -- default_status ["open"]) ),
'set default_status to ["open"]' );
- $output = run_settings_command( qw(settings --show) );
+ $output = run_command( qw(settings --show) );
like( $output, qr/default_status: \["open"\]/,
'the original milestone list is there' );
};
as_bob {
- ok( run_settings_command( 'clone', '--from', repo_uri_for('alice') ),
+ ok( run_command( 'clone', '--from', repo_uri_for('alice') ),
'Sync ran ok!' );
- my $stdout = run_settings_command( qw(settings show) );
+ my $stdout = run_command( qw(settings show) );
like( $stdout, qr/default_status: \["open"\]/,
'the original milestone list is there' );
- ok( run_settings_command( qw(settings set -- default_status ["stalled"]) ),
+ ok( run_command( qw(settings set -- default_status ["stalled"]) ),
'set default_status to ["stalled"]' );
- $stdout = run_settings_command( qw(settings show) );
+ $stdout = run_command( qw(settings show) );
like( $stdout, qr/default_status: \["stalled"\]/,
'the original milestone list is there');
};
as_alice {
- ok( run_settings_command( 'pull', '--from', repo_uri_for('bob') ), 'Sync ran ok!' );
- my $stdout = run_settings_command( qw(settings show) );
+ ok( run_command( 'pull', '--from', repo_uri_for('bob') ), 'Sync ran ok!' );
+ my $stdout = run_command( qw(settings show) );
like( $stdout, qr/default_status: \["stalled"\]/,
'the original milestone list is there' );
};
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list