@@ -166,6 +166,8 @@ sub standaloneJob {
166166 Arg[2] : String $url. The location of the database to be created
167167 Arg[3] : (optional) Arrayref $args. Extra parameters of the pipeline (as on the command-line)
168168 Arg[4] : (optional) Arrayref $tweaks. Tweaks to be applied to the database (as with the -tweak command-line option)
169+ Arg[5] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
170+ key that is understood is "expect_failure" to reverse the expectation of the test.
169171 Example : init_pipeline(
170172 'Bio::EnsEMBL::Hive::Examples::LongMult::PipeConfig::LongMultServer_conf',
171173 $server_url,
@@ -183,7 +185,7 @@ sub standaloneJob {
183185=cut
184186
185187sub init_pipeline {
186- my ($file_or_module , $url , $options , $tweaks ) = @_ ;
188+ my ($file_or_module , $url , $options , $tweaks , $flags ) = @_ ;
187189
188190 $options ||= [];
189191
@@ -203,7 +205,7 @@ sub init_pipeline {
203205 push @args , @$options ;
204206 push @args , map {-tweak => $_ } @$tweaks if $tweaks ;
205207
206- return _test_ehive_script(' init_pipeline' , undef , \@args );
208+ return _test_ehive_script(' init_pipeline' , undef , \@args , undef , $flags );
207209}
208210
209211
@@ -214,6 +216,8 @@ sub init_pipeline {
214216 Arg[2] : String $url. The location of the database
215217 Arg[3] : Arrayref $args. Extra arguments given to the script
216218 Arg[4] : String $test_name (optional). The name of the test
219+ Arg[5] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
220+ key that is understood is "expect_failure" to reverse the expectation of the test.
217221 Description : Generic method that can run any eHive script and check its return status
218222 Returntype : None
219223 Exceptions : TAP-style
@@ -223,12 +227,19 @@ sub init_pipeline {
223227=cut
224228
225229sub _test_ehive_script {
226- my ($script_name , $url , $args , $test_name ) = @_ ;
230+ my ($script_name , $url , $args , $test_name , $flags ) = @_ ;
227231 $args ||= [];
232+ $flags ||= {};
228233 my @ext_args = ( defined ($url ) ? (-url => $url ) : (), @$args );
229- $test_name ||= ' Can run ' .$script_name .(@ext_args ? ' with the following cmdline options: ' .join (' ' , @ext_args ) : ' ' );
230234
231- ok(!system ($ENV {' EHIVE_ROOT_DIR' }.' /scripts/' .$script_name .' .pl' , @ext_args ), $test_name );
235+ my $rc = system ($ENV {' EHIVE_ROOT_DIR' }.' /scripts/' .$script_name .' .pl' , @ext_args );
236+ if ($flags -> {expect_failure }) {
237+ $test_name ||= $script_name .' fails' .(@ext_args ? ' with the command-line options: ' .join (' ' , @ext_args ) : ' ' );
238+ ok($rc , $test_name );
239+ } else {
240+ $test_name ||= ' Can run ' .$script_name .(@ext_args ? ' with the command-line options: ' .join (' ' , @ext_args ) : ' ' );
241+ is($rc , 0, $test_name );
242+ }
232243}
233244
234245
@@ -237,6 +248,8 @@ sub _test_ehive_script {
237248 Arg[1] : String $url. The location of the database
238249 Arg[2] : Arrayref $args. Extra arguments given to runWorker
239250 Arg[3] : String $test_name (optional). The name of the test
251+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
252+ key that is understood is "expect_failure" to reverse the expectation of the test.
240253 Example : runWorker($url, [ -can_respecialize => 1 ]);
241254 Description : Run a worker on the given pipeline in the current process.
242255 The worker options have been divided in three groups: the ones affecting its specialization,
@@ -269,6 +282,8 @@ sub runWorker {
269282 Arg[1] : String $url. The location of the database
270283 Arg[2] : Arrayref $args. Extra arguments given to seed_pipeline
271284 Arg[3] : String $test_name (optional). The name of the test
285+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
286+ key that is understood is "expect_failure" to reverse the expectation of the test.
272287 Example : $seed_pipeline($url, [$arg1, $arg2], 'Run seed_pipeline with two arguments');
273288 Description : Very generic function to run seed_pipeline on the given database with the given arguments
274289 Returntype : None
@@ -289,6 +304,8 @@ sub seed_pipeline {
289304 Arg[1] : String $url. The location of the database
290305 Arg[2] : Arrayref $args. Extra arguments given to beekeeper.pl
291306 Arg[3] : String $test_name (optional). The name of the test
307+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
308+ key that is understood is "expect_failure" to reverse the expectation of the test.
292309 Example : beekeeper($url, [$arg1, $arg2], 'Run beekeeper with two arguments');
293310 Description : Very generic function to run beekeeper on the given database with the given arguments
294311 Returntype : None
@@ -307,6 +324,8 @@ sub beekeeper {
307324 Arg[1] : String $url. The location of the database
308325 Arg[2] : Arrayref $args. Extra arguments given to beekeeper.pl
309326 Arg[3] : String $test_name (optional). The name of the test
327+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
328+ key that is understood is "expect_failure" to reverse the expectation of the test.
310329 Example : tweak_pipeline($url, [$arg1, $arg2], 'Run tweak_pipeline with two arguments');
311330 Description : Very generic function to run tweak_pipeline on the given database with the given arguments
312331 Returntype : None
@@ -326,6 +345,8 @@ sub tweak_pipeline {
326345 Arg[1] : String $url or undef. The location of the database
327346 Arg[2] : Arrayref $args. Extra arguments given to generate_graph.pl
328347 Arg[3] : String $test_name (optional). The name of the test
348+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
349+ key that is understood is "expect_failure" to reverse the expectation of the test.
329350 Example : generate_graph($url, [-output => 'lm_analyses.png'], 'Generate a PNG A-diagram');
330351 Description : Very generic function to run generate_graph.pl on the given database with the given arguments
331352 Returntype : None
@@ -345,6 +366,8 @@ sub generate_graph {
345366 Arg[1] : String $url. The location of the database
346367 Arg[2] : Arrayref $args. Extra arguments given to visualize_jobs.pl
347368 Arg[3] : String $test_name (optional). The name of the test
369+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
370+ key that is understood is "expect_failure" to reverse the expectation of the test.
348371 Example : visualize_jobs($url, [-output => 'lm_jobs.png', -accu_values], 'Generate a PNG J-diagram with accu values');
349372 Description : Very generic function to run visualize_jobs.pl on the given database with the given arguments
350373 Returntype : None
@@ -363,6 +386,8 @@ sub visualize_jobs {
363386 Arg[1] : String $url. The location of the database
364387 Arg[2] : Arrayref $args. Extra arguments given to peekJob.pl
365388 Arg[3] : String $test_name (optional). The name of the test
389+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
390+ key that is understood is "expect_failure" to reverse the expectation of the test.
366391 Example : peekJob($url, [-job_id => 1], 'Check params for job 1');
367392 Description : Very generic function to run peekJob.pl on the given database with the given arguments
368393 Returntype : None
@@ -382,6 +407,8 @@ sub peekJob {
382407 Arg[1] : String $url. The location of the database
383408 Arg[2] : Arrayref $args. Extra arguments given to db_cmd.pl
384409 Arg[3] : String $test_name (optional). The name of the test
410+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
411+ key that is understood is "expect_failure" to reverse the expectation of the test.
385412 Example : db_cmd($url, [-sql => 'DROP DATABASE'], 'Drop the database');
386413 Description : Very generic function to run db_cmd.pl on the given database with the given arguments
387414 Returntype : None
@@ -401,6 +428,8 @@ sub db_cmd {
401428 Arg[1] : String $url. The location of the database
402429 Arg[2] : String $sql. The SQL to run on the database
403430 Arg[3] : String $test_name (optional). The name of the test
431+ Arg[4] : (optional) Hashref $flags. Flags given to the text framework. Currently the only
432+ key that is understood is "expect_failure" to reverse the expectation of the test.
404433 Example : run_sql_on_db($url, 'INSERT INTO sweets (name, quantity) VALUES (3, 'Snickers')');
405434 Description : Execute an SQL command on the given database and test its execution. This expects the
406435 command-line client to return a non-zero code in case of a failure.
@@ -412,8 +441,10 @@ sub db_cmd {
412441=cut
413442
414443sub run_sql_on_db {
415- my ($url , $sql , $test_name ) = @_ ;
416- return _test_ehive_script(' db_cmd' , $url , [-sql => $sql ], $test_name // ' Can run ' .$sql );
444+ my ($url , $sql , $test_name , $flags ) = @_ ;
445+ $flags ||= {};
446+ $test_name //= $flags -> {expect_failure } ? $sql .' fails' : ' Can run ' .$sql ;
447+ return _test_ehive_script(' db_cmd' , $url , [-sql => $sql ], $test_name , $flags );
417448}
418449
419450
0 commit comments