]> git.sur5r.net Git - i3/i3/blob - testcases/t/17-workspace.t
1c0c7e285beef134a488690cbc8dd6f57f75da31
[i3/i3] / testcases / t / 17-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests whether we can switch to a non-existant workspace
5 # (necessary for further tests)
6 #
7 use Test::More tests => 2;
8 use List::MoreUtils qw(all none);
9 use Data::Dumper;
10 use AnyEvent::I3;
11 use File::Temp qw(tmpnam);
12 use v5.10;
13
14 my $i3 = i3("/tmp/nestedcons");
15
16 sub get_workspace_names {
17     my $tree = $i3->get_workspaces->recv;
18     my @workspaces = map { @{$_->{nodes}} } @{$tree->{nodes}};
19     [ map { $_->{name} } @workspaces ]
20 }
21
22 sub workspace_exists {
23     my ($name) = @_;
24     ($name ~~ @{get_workspace_names()})
25 }
26
27 sub get_unused_workspace {
28     my @names = get_workspace_names();
29     my $tmp;
30     do { $tmp = tmpnam() } while ($tmp ~~ @names);
31     $tmp
32 }
33
34 my $tmp = get_unused_workspace();
35 diag("Temporary workspace name: $tmp\n");
36
37 $i3->command("workspace $tmp")->recv;
38 ok(workspace_exists($tmp), 'workspace created');
39
40 my $otmp = get_unused_workspace();
41 diag("Other temporary workspace name: $otmp\n");
42
43 # As the old workspace was empty, it should get
44 # cleaned up as we switch away from it
45 $i3->command("workspace $otmp")->recv;
46 ok(!workspace_exists($tmp), 'old workspace cleaned up');
47
48 diag( "Testing i3, Perl $], $^X" );