]> git.sur5r.net Git - i3/i3/blobdiff - testcases/lib/i3test.pm
testcases: correctly enable lexical pragmata
[i3/i3] / testcases / lib / i3test.pm
index cf29d7b9eb797ef86e8f02182a7d9f03b8a9e357..ad598b846ccbf87a0ff3eadbd6bfc49d2aa42a6c 100644 (file)
@@ -1,5 +1,6 @@
 package i3test;
 # vim:ts=4:sw=4:expandtab
+use strict; use warnings;
 
 use File::Temp qw(tmpnam tempfile tempdir);
 use Test::Builder;
@@ -9,11 +10,8 @@ use X11::XCB qw(:all);
 use AnyEvent::I3;
 use EV;
 use List::Util qw(first);
-use List::MoreUtils qw(lastval);
 use Time::HiRes qw(sleep);
-use Try::Tiny;
 use Cwd qw(abs_path);
-use Proc::Background;
 use SocketActivation;
 
 use v5.10;
@@ -58,16 +56,22 @@ BEGIN {
 sub import {
     my $class = shift;
     my $pkg = caller;
-    eval "package $pkg;
-use Test::Most" . (@_ > 0 ? " qw(@_)" : "") . ";
+
+    my $test_most_args = @_ ? "qw(@_)" : "";
+    local $@;
+    eval << "__";
+package $pkg;
+use Test::Most $test_most_args;
 use Data::Dumper;
 use AnyEvent::I3;
 use Time::HiRes qw(sleep);
 use Test::Deep qw(eq_deeply cmp_deeply cmp_set cmp_bag cmp_methods useclass noclass set bag subbagof superbagof subsetof supersetof superhashof subhashof bool str arraylength Isa ignore methods regexprefonly regexpmatches num regexponly scalref reftype hashkeysonly blessed array re hash regexpref hash_each shallow array_each code arrayelementsonly arraylengthonly scalarrefonly listmethods any hashkeys isa);
-use v5.10;
-use strict;
-use warnings;
-";
+__
+    $tester->bail_out("$@") if $@;
+    feature->import(":5.10");
+    strict->import;
+    warnings->import;
+
     @_ = ($class);
     goto \&Exporter::import;
 }
@@ -246,7 +250,7 @@ sub get_focused {
         $lf = $focused[0];
         last unless defined($con->{focus});
         @focused = @{$con->{focus}};
-        @cons = grep { $_->{id} == $lf } (@{$con->{nodes}}, @{$con->{'floating_nodes'}});
+        my @cons = grep { $_->{id} == $lf } (@{$con->{nodes}}, @{$con->{'floating_nodes'}});
         $con = $cons[0];
     }
 
@@ -269,7 +273,8 @@ sub get_dock_clients {
             my $first = first { $_->{type} == 5 } @{$output->{nodes}};
             @docked = (@docked, @{$first->{nodes}});
         } elsif ($which eq 'bottom') {
-            my $last = lastval { $_->{type} == 5 } @{$output->{nodes}};
+            my @matching = grep { $_->{type} == 5 } @{$output->{nodes}};
+            my $last = $matching[-1];
             @docked = (@docked, @{$last->{nodes}});
         }
     }
@@ -375,7 +380,7 @@ sub exit_gracefully {
     $socketpath ||= get_socket_path();
 
     my $exited = 0;
-    try {
+    eval {
         say "Exiting i3 cleanly...";
         i3($socketpath)->command('exit')->recv;
         $exited = 1;
@@ -424,7 +429,7 @@ sub launch_with_config {
         $tmp_socket_path = File::Temp::tempnam('/tmp', 'i3-test-socket-');
     }
 
-    my ($fh, $tmpfile) = tempfile('i3-test-config-XXXXX', UNLINK => 1);
+    my ($fh, $tmpfile) = tempfile('/tmp/i3-test-config-XXXXX', UNLINK => 1);
     say $fh $config;
     say $fh "ipc-socket $tmp_socket_path" unless $dont_add_socket_path;
     close($fh);
@@ -434,7 +439,10 @@ sub launch_with_config {
         unix_socket_path => "$tmp_socket_path-activation",
         display => $ENV{DISPLAY},
         configfile => $tmpfile,
-        logpath => $ENV{LOGPATH},
+        outdir => $ENV{OUTDIR},
+        testname => $ENV{TESTNAME},
+        valgrind => $ENV{VALGRIND},
+        strace => $ENV{STRACE},
         cv => $cv,
     );
 
@@ -447,4 +455,14 @@ sub launch_with_config {
     return $pid;
 }
 
+package i3test::X11;
+use parent 'X11::XCB::Connection';
+
+sub input_focus {
+    my $self = shift;
+    i3test::sync_with_i3($self);
+
+    return $self->SUPER::input_focus(@_);
+}
+
 1