Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #329 -- Uninitialized value warnings in S::R::Commands #332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ on 'test' => sub {
requires "Test::Fatal" => "0";
requires "Test::LWP::UserAgent" => "0";
requires "Test::More" => "0";
requires "Test::NoWarnings" => "0";
requires "Test::Time" => "0";
requires "Test::Warn" => "0";
requires "lib" => "0";
Expand Down
2 changes: 2 additions & 0 deletions lib/Selenium/Remote/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ sub get_params {
my $command = $args->{'command'};
my $url = $self->get_url($command);

# Issue 329 -- Suppress unint value warns
$args = { map { $_ => $args->{$_} ? $args->{$_} : "" } qw{session_id id name property_name other window_handle} };
# Do the var substitutions.
$url =~ s/:sessionId/$args->{'session_id'}/;
$url =~ s/:id/$args->{'id'}/;
Expand Down
68 changes: 44 additions & 24 deletions t/04-commands-implemented.t
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
use strict;
use warnings;

# TODO: find another way to do this checking, this is so fragile
use Selenium::Remote::Commands;
use Test::More;
use Test::More tests => 3 + 1;
use Test::NoWarnings;

unless($ENV{RELEASE_TESTING}) {
plan(skip_all=>"Author tests not required for installation.");
# Assume we're not using dzil test unless we're doing that
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to do this, just use FindBin.

if( !grep { index( $_, ".build" ) != -1 } @INC ) {
require Cwd;
require File::Basename;
push( @INC, File::Basename::dirname(Cwd::abs_path(__FILE__)) . "/../lib" );
}

my $comm = Selenium::Remote::Commands->new->get_cmds;
for my $command (keys %{$comm}) {
my $found_command = 0;
for my $file (
qw{lib/Selenium/Remote/Driver.pm
lib/Selenium/Remote/WebElement.pm
lib/Selenium/Firefox.pm}
) {
open(my $fh, '<', $file) or die "Couldn't open file $file";
for (<$fh>) {
if (/'?command'?\s*=>\s*'$command'/
or /{'?commands'?}->\{'?$command'?}/) {
pass("find $command");
$found_command = 1;
require_ok( "Selenium::Remote::Commands" ) || die;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer a message with the die


subtest "All implemented commands are found" => sub {
plan skip_all => "Author tests not required for installation." unless $ENV{'RELEASE_TESTING'};
my $comm = Selenium::Remote::Commands->new->get_cmds;
for my $command (keys %{$comm}) {
my $found_command = 0;
for my $file (
qw{lib/Selenium/Remote/Driver.pm
lib/Selenium/Remote/WebElement.pm
lib/Selenium/Firefox.pm}
) {
open(my $fh, '<', $file) or die "Couldn't open file $file";
for (<$fh>) {
if ( /'?command'?\s*=>\s*'$command'/ or /{'?commands'?}->\{'?$command'?}/) {
pass("find $command");
$found_command = 1;
}
}
}
if (!$found_command && $command !~ /Gecko/) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems profoundly silly to use pass/fail when one could simply fall through and do ok($found_command,"found $command") unless $command =~ /Gecko/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall writing that bit... maybe I moved it?

fail("find $command");
}
}
if (!$found_command && $command !~ /Gecko/) {
fail("find $command");
}
}
};

done_testing;
subtest "get_params() works as intended" => sub {
no warnings qw{redefine once};
# I know this is somewhat whimsical as an URL, but hey, it is a test.
local *Selenium::Remote::Commands::get_url = sub { return "http://foo.bar.baz:4444/session/:sessionId:id:name:propertyName:other:windowHandle" };
local *Selenium::Remote::Commands::get_method = sub { return 'methodMan'; };
local *Selenium::Remote::Commands::get_no_content_success = sub { return 'zippy' };
my $model_return = {
'method' => 'methodMan',
'no_content_success' => 'zippy',
'url' => 'http://foo.bar.baz:4444/session/12345'
};
my $bogus_obj = bless( {}, "Selenium::Remote::Commands" );
is( Selenium::Remote::Commands::get_params( $bogus_obj ), undef, "We return early when session_id not passed in" );
is_deeply( Selenium::Remote::Commands::get_params( $bogus_obj, { 'session_id' => "12345" } ), $model_return, "Expected data returned when minimal information input" );
};

1;