@@ -4,39 +4,30 @@ use warnings;
4
4
use Test::More tests => 3 + 1;
5
5
use Test::NoWarnings;
6
6
7
- # Assume we're not using dzil test unless we're doing that
8
- if ( !grep { index ( $_ , " .build" ) != -1 } @INC ) {
9
- require Cwd;
10
- require File::Basename;
11
- push ( @INC , File::Basename::dirname(Cwd::abs_path(__FILE__ )) . " /../lib" );
12
- }
13
-
14
- require_ok( " Selenium::Remote::Commands" ) || die ;
7
+ require_ok( " Selenium::Remote::Commands" ) || die " Module couldn't be loaded, can't continue with testing!" ;
15
8
16
9
subtest " All implemented commands are found" => sub {
17
10
plan skip_all => " Author tests not required for installation." unless $ENV {' RELEASE_TESTING' };
18
- my $comm = Selenium::Remote::Commands-> new-> get_cmds;
19
- for my $command (keys %{$comm }) {
20
- my $found_command = 0;
21
- for my $file (
22
- qw{ lib/Selenium/Remote/Driver.pm
23
- lib/Selenium/Remote/WebElement.pm
24
- lib/Selenium/Firefox.pm}
25
- ) {
26
- open (my $fh , ' <' , $file ) or die " Couldn't open file $file " ;
27
- for (<$fh >) {
28
- if ( / '?command'?\s *=>\s *'$command '/ or /{' ?commands' ?}-> \{' ?$command' ?}/) {
29
- pass(" find $command " );
30
- $found_command = 1;
31
- }
32
- }
33
- }
34
- if (!$found_command && $command !~ / Gecko/ ) {
35
- fail(" find $command " );
36
- }
11
+ my @cmds2see = keys ( %{ Selenium::Remote::Commands-> new-> get_cmds } );
12
+ # You won't find the Gecko command in Selenium::Rmeote::Commands. This is intentional, so remove it from consideration.
13
+ @cmds2see = grep { $_ !~ / Gecko/ } @cmds2see ;
14
+ plan ' tests' => scalar ( @cmds2see );
15
+ my @files = map { _get_file_contents($_ ) } qw{ lib/Selenium/Remote/Driver.pm lib/Selenium/Remote/WebElement.pm lib/Selenium/Firefox.pm} ;
16
+ for my $command (@cmds2see ) {
17
+ my $detector = q/ ['"]?command['"]?\s*[=-]{1}>\s*\{?['"]/ . $command . q/ ['"]\}?/ ;
18
+ my $found = grep { my $contents = $_ ; grep { $_ =~ qr /$detector / } @$contents } @files ;
19
+ ok( $found , " Found $command " );
37
20
}
38
21
};
39
22
23
+ sub _get_file_contents {
24
+ my $file = shift ;
25
+ my @contents ;
26
+ open (my $fh , ' <' , $file ) or die " Couldn't open file $file " ;
27
+ for (<$fh >) { push ( @contents , $_ ) }
28
+ return \@contents ;
29
+ }
30
+
40
31
subtest " get_params() works as intended" => sub {
41
32
no warnings qw{ redefine once} ;
42
33
# I know this is somewhat whimsical as an URL, but hey, it is a test.
0 commit comments