Skip to content

Commit ac76a36

Browse files
committed
Use of Feature::Compat::Try in the test libraries
To be consinstence with the rest of the project, module in the test library have to use also try/catch block. This commit should complete the "migration" to Feature::Compat::Try wherever was applicable. https://progress.opensuse.org/issues/176862
1 parent a5ee6da commit ac76a36

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

t/lib/OpenQA/SeleniumTest.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use OpenQA::WebAPI;
2424
use OpenQA::Log 'log_info';
2525
use OpenQA::Utils;
2626
use OpenQA::Test::Utils qw(wait_for);
27+
use Feature::Compat::Try;
28+
2729
use POSIX '_exit';
2830

2931
our $_driver;
@@ -49,7 +51,7 @@ sub disable_timeout () {
4951

5052
sub start_driver ($mojoport) {
5153
# Connect to it
52-
eval {
54+
try {
5355
# enforce the JSON Wire protocol (instead of using W3C WebDriver protocol)
5456
# note: This is required with Selenium::Remote::Driver 1.36 which would now use W3C mode leading
5557
# to errors like "unknown command: unknown command: Cannot call non W3C standard command while
@@ -97,8 +99,8 @@ sub start_driver ($mojoport) {
9799
$_driver->set_window_size(600, 800);
98100
$_driver->get("http://localhost:$mojoport/");
99101

100-
};
101-
die $@ if ($@);
102+
}
103+
catch ($e) { die $e }
102104

103105
return $_driver;
104106
}

t/lib/OpenQA/Test/Utils.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use Mojo::IOLoop::ReadWriteProcess 'process';
3232
use Mojo::Server::Daemon;
3333
use Mojo::IOLoop::Server;
3434
use Test::MockModule;
35+
use Feature::Compat::Try;
3536
use Time::HiRes 'sleep';
3637

3738
BEGIN {
@@ -595,9 +596,11 @@ sub mock_io_loop (%args) {
595596
my $io_loop_mock = Test::MockModule->new('Mojo::IOLoop');
596597
$io_loop_mock->redefine( # avoid forking to prevent coverage analysis from slowing down the test significantly
597598
subprocess => sub ($io_loop, $function, $callback) {
598-
my @result = eval { $function->() };
599-
my $error = $@;
600-
$io_loop->next_tick(sub { $callback->(undef, $error, @result) });
599+
my @result;
600+
try { @result = $function->() }
601+
catch ($e) {
602+
$io_loop->next_tick(sub { $callback->(undef, $e, @result) })
603+
}
601604
}) if $args{subprocess};
602605
return $io_loop_mock;
603606
}

0 commit comments

Comments
 (0)