]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/517-regress-move-direction-ipc.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 517-regress-move-direction-ipc.t
index 1a325ae764b45695686bb5ffbb0fd41033757906..2f7f2b27f897b5168a4fa839071f9d7614bf2430 100644 (file)
@@ -2,13 +2,13 @@
 # vim:ts=4:sw=4:expandtab
 #
 # Please read the following documents before working on tests:
-# • http://build.i3wm.org/docs/testsuite.html
+# • https://build.i3wm.org/docs/testsuite.html
 #   (or docs/testsuite)
 #
-# • http://build.i3wm.org/docs/lib-i3test.html
+# • https://build.i3wm.org/docs/lib-i3test.html
 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
 #
-# • http://build.i3wm.org/docs/ipc.html
+# • https://build.i3wm.org/docs/ipc.html
 #   (or docs/ipc)
 #
 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
@@ -27,51 +27,29 @@ workspace ws-left output fake-0
 workspace ws-right output fake-1
 EOT
 
-my $i3 = i3(get_socket_path());
-$i3->connect()->recv;
-
-# subscribe to the 'focus' ipc event
-my $focus = AnyEvent->condvar;
-$i3->subscribe({
-    workspace => sub {
-        my ($event) = @_;
-        if ($event->{change} eq 'focus') {
-            $focus->send($event);
-        }
-    }
-})->recv;
-
-# give up after 0.5 seconds
-my $timer = AnyEvent->timer(
-    after => 0.5,
-    cb => sub {
-        $focus->send(0);
-    }
-);
-
 # open two windows on the left output
 cmd 'workspace ws-left';
 open_window;
 open_window;
 
-# move a window over to the right output
-cmd 'move right';
-my $event = $focus->recv;
+sub focus_subtest {
+    my ($cmd, $want) = @_;
 
-ok($event, 'moving from workspace with two windows triggered focus ipc event');
-is($event->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
-is(@{$event->{current}->{nodes}}, 1, 'focus event gave the right number of windows on the workspace');
+    my @events = events_for(
+       sub { cmd $cmd },
+       'workspace');
 
-# reset and try again
-$focus = AnyEvent->condvar;
-cmd 'workspace ws-left';
-$focus->recv;
+    my @focus = grep { $_->{change} eq 'focus' } @events;
+    is(scalar @focus, 1, 'Received 1 workspace::focus event');
+    is($focus[0]->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
+    is(@{$focus[0]->{current}->{nodes}}, $want, 'focus event gave the right number of windows on the workspace');
+}
+
+# move a window over to the right output
+subtest 'move right (1)', \&focus_subtest, 'move right', 1;
 
-$focus = AnyEvent->condvar;
-cmd 'move right';
-$event = $focus->recv;
-ok($event, 'moving from workspace with one window triggered focus ipc event');
-is($event->{current}->{name}, 'ws-right', 'focus event gave the right workspace');
-is(@{$event->{current}->{nodes}}, 2, 'focus event gave the right number of windows on the workspace');
+# move another window
+cmd 'workspace ws-left';
+subtest 'move right (2)', \&focus_subtest, 'move right', 2;
 
 done_testing;