[Bps-public-commit] Prophet branch, config-gitlike, updated. 00486b0b4111839cb2deb88f7ca4fda9cf1e1275
spang at bestpractical.com
spang at bestpractical.com
Fri Jun 26 05:42:55 EDT 2009
The branch, config-gitlike has been updated
via 00486b0b4111839cb2deb88f7ca4fda9cf1e1275 (commit)
via 206525ef612f9e395c641cdc2f07d9a29e170a13 (commit)
from a1316914f448020702470436298912aebc683132 (commit)
Summary of changes:
lib/Prophet/Test.pm | 19 ++++++-
lib/Prophet/Test/Editor.pm | 97 +++++++++++++++++++++++++++++++
t/Settings/t/database-settings-editor.t | 97 +++++++++++++++++++++++++++++++
t/Settings/t/sync-database-settings.t | 3 -
t/data/settings-first.tmpl | 19 ++++++
t/data/settings-second.tmpl | 19 ++++++
t/data/settings-third.tmpl | 19 ++++++
t/scripts/settings-editor.pl | 53 +++++++++++++++++
8 files changed, 322 insertions(+), 4 deletions(-)
create mode 100644 lib/Prophet/Test/Editor.pm
create mode 100644 t/Settings/t/database-settings-editor.t
create mode 100644 t/data/settings-first.tmpl
create mode 100644 t/data/settings-second.tmpl
create mode 100644 t/data/settings-third.tmpl
create mode 100755 t/scripts/settings-editor.pl
- Log -----------------------------------------------------------------
commit 206525ef612f9e395c641cdc2f07d9a29e170a13
Author: Christine Spang <spang at mit.edu>
Date: Fri Jun 26 12:40:37 2009 +0300
Move set_editor_script over from SD
diff --git a/lib/Prophet/Test.pm b/lib/Prophet/Test.pm
index 6e7dbca..37df797 100644
--- a/lib/Prophet/Test.pm
+++ b/lib/Prophet/Test.pm
@@ -6,10 +6,11 @@ use base qw/Test::More Exporter/;
use Test::Script::Run ':all';
our @EXPORT = qw/as_alice as_bob as_charlie as_david as_user run_ok repo_uri_for run_script run_output_matches run_output_matches_unordered replica_last_rev replica_uuid_for ok_added_revisions replica_uuid database_uuid database_uuid_for
serialize_conflict serialize_changeset in_gladiator diag is_script_output
- run_command set_editor load_record last_script_stdout last_script_stderr
+ run_command set_editor set_editor_script load_record last_script_stdout last_script_stderr
last_script_exit_code
/;
+use Cwd qw/getcwd/;
use File::Path 'rmtree';
use File::Spec;
use File::Temp qw/tempdir tempfile/;
@@ -55,6 +56,22 @@ sub set_editor {
$EDIT_TEXT = shift;
}
+=head2 set_editor_script SCRIPT
+
+Sets the editor that Proc::InvokeEditor uses.
+
+This should be a non-interactive script found in F<t/scripts>.
+
+=cut
+
+sub set_editor_script {
+ my ($self, $script) = @_;
+
+ delete $ENV{'VISUAL'}; # Proc::InvokeEditor checks this first
+ $ENV{'EDITOR'} = "$^X " . File::Spec->catfile(getcwd(), 't', 'scripts', $script);
+ Test::More::diag "export EDITOR=" . $ENV{'EDITOR'} . "\n";
+}
+
=head2 import_extra($class, $args)
=cut
commit 00486b0b4111839cb2deb88f7ca4fda9cf1e1275
Author: Christine Spang <spang at mit.edu>
Date: Fri Jun 26 12:42:22 2009 +0300
Move settings command tests from SD to Prophet
diff --git a/lib/Prophet/Test/Editor.pm b/lib/Prophet/Test/Editor.pm
new file mode 100644
index 0000000..bb5fe2b
--- /dev/null
+++ b/lib/Prophet/Test/Editor.pm
@@ -0,0 +1,97 @@
+package Prophet::Test::Editor;
+use strict;
+use warnings;
+
+use Prophet::Util;
+use Params::Validate;
+use File::Spec;
+
+=head2 edit( tmpl_files => $tmpl_files, edit_callback => sub {}, verify_callback => sub {} )
+
+Expects @ARGV to contain at least an option and a file to be edited. It
+can also contain a replica uuid, a ticket uuid, and a status file. The last
+item must always be the file to be edited. The others, if they appear, must
+be in that order after the option. The status file must contain the
+string 'status' in its filename.
+
+edit_callback is called on each line of the file being edited. It should make
+any edits to the lines it receives and then print what it wants to be saved to
+the file.
+
+verify_callback is called after editing is done. If you need to write
+whether the template was correct to a status file, for example, this
+should be done here.
+
+=cut
+
+sub edit {
+ my %args = @_;
+ validate( @_, { edit_callback => 1,
+ verify_callback => 1,
+ tmpl_files => 1,
+ }
+ );
+
+ my $option = shift @ARGV;
+ my $tmpl_file = $args{tmpl_files}->{$option};
+
+ my @valid_template = Prophet::Util->slurp("t/data/$tmpl_file");
+ chomp @valid_template;
+
+ my $status_file = $ARGV[-2] =~ /status/ ? delete $ARGV[-2] : undef;
+ # a bit of a hack to dermine whether the last arg is a filename
+ my $replica_uuid = File::Spec->file_name_is_absolute($ARGV[0]) ? undef : shift @ARGV;
+ my $ticket_uuid = File::Spec->file_name_is_absolute($ARGV[0]) ? undef : shift @ARGV;
+
+ my @template = ();
+ while (<>) {
+ chomp( my $line = $_ );
+ push @template, $line;
+
+ $args{edit_callback}(
+ option => $option, template => \@template,
+ valid_template => \@valid_template,
+ replica_uuid => $replica_uuid,
+ ticket_uuid => $ticket_uuid,
+ );
+ }
+
+ $args{verify_callback}( template => \@template,
+ valid_template => \@valid_template, status_file => $status_file );
+}
+
+=head2 check_template_by_line($template, $valid_template, $errors)
+
+$template is a reference to an array containing the template to check,
+split into lines. $valid_template is the same for the template to
+check against. Lines in these arrays should not have trailing newlines.
+$errors is a reference to an array where error messages will be stored.
+
+Lines in $valid_template should consist of either plain strings, or strings
+beginning with 'qr/' (to delimit a regexp object).
+
+Returns true if the templates match and false otherwise.
+
+=cut
+
+sub check_template_by_line {
+ my @template = @{ shift @_ };
+ my @valid_template = @{ shift @_ };
+ my $replica_uuid = shift;
+ my $ticket_uuid = shift;
+ my $errors = shift;
+
+ for my $valid_line (@valid_template) {
+ my $line = shift @template;
+
+ push @$errors, "got nothing, expected [$valid_line]" if !defined($line);
+
+ push @$errors, "[$line] doesn't match [$valid_line]"
+ if ($valid_line =~ /^qr\//) ? $line !~ eval($valid_line)
+ : $line eq $valid_line;
+ }
+
+ return !(@$errors == 0);
+}
+
+1;
diff --git a/t/Settings/t/database-settings-editor.t b/t/Settings/t/database-settings-editor.t
new file mode 100644
index 0000000..d0098df
--- /dev/null
+++ b/t/Settings/t/database-settings-editor.t
@@ -0,0 +1,97 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Prophet::Test tests => 9;
+use Prophet::Util;
+use File::Temp qw(tempdir);
+use File::Spec;
+no warnings 'once';
+
+$ENV{'PERL5LIB'} .= ':t/Settings/lib';
+
+# test the CLI and interactive UIs for showing and updating settings
+
+BEGIN {
+ require File::Temp;
+ $ENV{'PROPHET_REPO'} = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
+ diag $ENV{'PROPHET_REPO'};
+}
+
+run_ok( 'settings', [ 'init' ] );
+
+my $replica_uuid = replica_uuid;
+
+# test noninteractive set
+run_output_matches( 'settings', [ 'settings', '--set', '--', 'statuses',
+ '["new","open","stalled"]' ],
+ [
+ 'Trying to change statuses from ["new","open","stalled","closed"] to ["new","open","stalled"].',
+ ' -> Changed.',
+ ], [], "settings --set went ok",
+);
+
+# check with settings --show
+my @valid_settings_output = Prophet::Util->slurp('t/data/settings-first.tmpl');
+chomp (@valid_settings_output);
+
+run_output_matches(
+ 'settings',
+ [ qw/settings --show/ ],
+ [ @valid_settings_output ], [], "changed settings output matches"
+);
+
+# test settings (interactive editing)
+
+my $filename = File::Temp->new(
+ TEMPLATE => File::Spec->catfile(File::Spec->tmpdir(), '/statusXXXXX') )->filename;
+diag ("interactive template status will be found in $filename");
+# first set the editor to an editor script
+Prophet::Test->set_editor_script("settings-editor.pl --first $filename");
+
+# then edit the settings
+run_output_matches( 'settings', [ 'settings' ],
+ [
+ 'Changed default_status from ["new"] to ["open"].',
+ 'Setting with uuid "6FBD84A1-4568-48E7-B90C-F1A5B7BD8ECD" does not exist.',
+ ], [], "interactive settings set went ok",);
+
+# check the tempfile to see if the template presented to the editor was correct
+chomp(my $template_ok = Prophet::Util->slurp($filename));
+is($template_ok, 'ok!', "interactive template was correct");
+
+# check the settings with settings --show
+ at valid_settings_output = Prophet::Util->slurp('t/data/settings-second.tmpl');
+chomp (@valid_settings_output);
+
+run_output_matches(
+ 'settings',
+ [ qw/settings --show/ ],
+ [ @valid_settings_output ], [], "changed settings output matches"
+);
+
+# test setting to invalid json
+my $second_filename = File::Temp->new(
+ TEMPLATE => File::Spec->catfile(File::Spec->tmpdir(), '/statusXXXXX') )->filename;
+diag ("interactive template status will be found in $second_filename");
+Prophet::Test->set_editor_script("settings-editor.pl --second $second_filename");
+run_output_matches( 'settings', [ 'settings' ],
+ [
+ qr/^An error occured setting default_milestone to \["alpha":/,
+ 'Changed default_component from ["core"] to ["ui"].',
+ ], [], "interactive settings set with JSON error went ok",
+);
+
+# check the tempfile to see if the template presented to the editor was correct
+chomp($template_ok = Prophet::Util->slurp($filename));
+is($template_ok, 'ok!', "interactive template was correct");
+
+# check the settings with settings --show
+ at valid_settings_output = Prophet::Util->slurp('t/data/settings-third.tmpl');
+chomp (@valid_settings_output);
+
+run_output_matches(
+ 'settings',
+ [ qw/settings --show/ ],
+ [ @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 bed418f..5c1fbd1 100644
--- a/t/Settings/t/sync-database-settings.t
+++ b/t/Settings/t/sync-database-settings.t
@@ -37,6 +37,3 @@ as_alice {
like($stdout, qr/default_status: \["stalled"\]/, "the original milestone list is there");
};
-exit;
-
-
diff --git a/t/data/settings-first.tmpl b/t/data/settings-first.tmpl
new file mode 100644
index 0000000..57cc516
--- /dev/null
+++ b/t/data/settings-first.tmpl
@@ -0,0 +1,19 @@
+# uuid: BAB613BD-9E25-4612-8DE3-21E4572859EA
+default_milestone: ["alpha"]
+
+# uuid: 1AF5CF74-A6D4-417E-A738-CCE64A0A7F71
+milestones: ["alpha","beta","1.0"]
+
+# uuid: 0AEC922F-57B1-44BE-9588-816E5841BB18
+default_component: ["core"]
+
+# uuid: 6CBD84A1-4568-48E7-B90C-F1A5B7BD8ECD
+components: ["core","ui","docs","tests"]
+
+# uuid: 2F9E6509-4468-438A-A733-246B3061003E
+default_status: ["new"]
+
+# uuid: 24183C4D-EFD0-4B16-A207-ED7598E875E6
+statuses: ["new","open","stalled"]
+
+
diff --git a/t/data/settings-second.tmpl b/t/data/settings-second.tmpl
new file mode 100644
index 0000000..1cc5abc
--- /dev/null
+++ b/t/data/settings-second.tmpl
@@ -0,0 +1,19 @@
+# uuid: BAB613BD-9E25-4612-8DE3-21E4572859EA
+default_milestone: ["alpha"]
+
+# uuid: 1AF5CF74-A6D4-417E-A738-CCE64A0A7F71
+milestones: ["alpha","beta","1.0"]
+
+# uuid: 0AEC922F-57B1-44BE-9588-816E5841BB18
+default_component: ["core"]
+
+# uuid: 6CBD84A1-4568-48E7-B90C-F1A5B7BD8ECD
+components: ["core","ui","docs","tests"]
+
+# uuid: 2F9E6509-4468-438A-A733-246B3061003E
+default_status: ["open"]
+
+# uuid: 24183C4D-EFD0-4B16-A207-ED7598E875E6
+statuses: ["new","open","stalled"]
+
+
diff --git a/t/data/settings-third.tmpl b/t/data/settings-third.tmpl
new file mode 100644
index 0000000..74dd857
--- /dev/null
+++ b/t/data/settings-third.tmpl
@@ -0,0 +1,19 @@
+# uuid: BAB613BD-9E25-4612-8DE3-21E4572859EA
+default_milestone: ["alpha"]
+
+# uuid: 1AF5CF74-A6D4-417E-A738-CCE64A0A7F71
+milestones: ["alpha","beta","1.0"]
+
+# uuid: 0AEC922F-57B1-44BE-9588-816E5841BB18
+default_component: ["ui"]
+
+# uuid: 6CBD84A1-4568-48E7-B90C-F1A5B7BD8ECD
+components: ["core","ui","docs","tests"]
+
+# uuid: 2F9E6509-4468-438A-A733-246B3061003E
+default_status: ["open"]
+
+# uuid: 24183C4D-EFD0-4B16-A207-ED7598E875E6
+statuses: ["new","open","stalled"]
+
+
diff --git a/t/scripts/settings-editor.pl b/t/scripts/settings-editor.pl
new file mode 100755
index 0000000..6a6ad8a
--- /dev/null
+++ b/t/scripts/settings-editor.pl
@@ -0,0 +1,53 @@
+#!perl -i
+use strict;
+use warnings;
+use Prophet::Test::Editor;
+
+# perl script to trick Proc::InvokeEditor with for the settings command
+
+my %tmpl_files = ( '--first' => 'settings-first.tmpl',
+ '--second' => 'settings-second.tmpl',
+);
+
+Prophet::Test::Editor::edit(
+ tmpl_files => { '--first' => 'settings-first.tmpl',
+ '--second' => 'settings-second.tmpl',
+ },
+ edit_callback => sub {
+ my %args = @_;
+ my $option = $args{option};
+
+ if ($option eq '--first') {
+ s/(?<=^default_status: \[")new(?="\])/open/; # valid json change
+ s/^default_milestone(?=: \["alpha"\])$/invalid_setting/; # changes setting name
+ s/(?<=uuid: 6)C(?=BD84A1)/F/; # changes a UUID to an invalid one
+ s/^project_name//; # deletes setting
+ } elsif ($option eq '--second') {
+ s/(?<=^default_component: \[")core(?="\])/ui/; # valid json change
+ s/(?<=^default_milestone: \["alpha")]$//; # invalid json
+ }
+ print;
+ },
+ verify_callback => sub {
+ my %args = @_;
+
+ my $ok = 1;
+
+ my %seen; # lookup table
+ my @vonly; # answer
+
+ # build lookup table
+ @seen{@{$args{template}}} = ( );
+
+ for my $line (@{$args{valid_template}}) {
+ push(@vonly, $line) unless exists $seen{$line};
+ }
+
+ # if anything is only in the valid template, we don't match
+ $ok = 0 if scalar @vonly;
+
+ open STATUSFILE, '>', $args{status_file};
+ $ok ? print STATUSFILE "ok!" : print STATUSFILE "not ok!";
+ close STATUSFILE;
+ }
+);
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list