2 # vim:ts=4:sw=4:expandtab
4 use base 'Test::Builder::Module';
12 my $CLASS = __PACKAGE__;
16 i3test::Test - Additional test instructions for use in i3 testcases
22 my $ws = fresh_workspace;
23 is_num_children($ws, 0, 'no containers on this workspace yet');
25 is_num_children($ws, 1, 'one container after "open"');
31 This module provides convenience methods for i3 testcases. If you notice that a
32 certain pattern is present in 5 or more test cases, it should most likely be
33 moved into this module.
37 =head2 is_num_children($workspace, $expected, $test_name)
39 Gets the number of children on the given workspace and verifies that they match
40 the expected amount of children.
42 is_num_children('1', 0, 'no containers on workspace 1 at startup');
47 my ($workspace, $num_children, $name) = @_;
48 my $tb = $CLASS->builder;
50 my $con = i3test::get_ws($workspace);
51 $tb->ok(defined($con), "Workspace $workspace exists");
53 $tb->skip("Workspace does not exist, skipping is_num_children");
57 my $got_num_children = scalar @{$con->{nodes}};
59 $tb->is_num($got_num_children, $num_children, $name);
62 =head2 cmp_float($a, $b)
64 Compares floating point numbers C<$a> and C<$b> and returns true if they differ
67 $tmp = fresh_workspace;
69 open_window for (1..4);
71 cmd 'resize grow width 10 px or 25 ppt';
73 ($nodes, $focus) = get_ws_content($tmp);
74 ok(cmp_float($nodes->[0]->{percent}, 0.166666666666667), 'first window got 16%');
75 ok(cmp_float($nodes->[1]->{percent}, 0.166666666666667), 'second window got 16%');
76 ok(cmp_float($nodes->[2]->{percent}, 0.166666666666667), 'third window got 16%');
77 ok(cmp_float($nodes->[3]->{percent}, 0.50), 'fourth window got 50%');
81 my ($a, $b, $name) = @_;
82 my $tb = $CLASS->builder;
84 $tb->cmp_ok(abs($a - $b), '<', 1e-6, $name);
89 Returns true if the layout tree can still be received from i3.
91 # i3 used to crash on invalid commands in revision X
92 cmd 'invalid command';
97 my $tree = i3test::i3(i3test::get_socket_path())->get_tree->recv;
98 my @nodes = @{$tree->{nodes}};
99 my $tb = $CLASS->builder;
100 $tb->ok((@nodes > 0), 'i3 still lives');
105 Michael Stapelberg <michael@i3wm.org>