]> git.sur5r.net Git - i3/i3/blob - testcases/lib/i3test/Test.pm
Merge branch 'master' into next
[i3/i3] / testcases / lib / i3test / Test.pm
1 package i3test::Test;
2
3 use base 'Test::Builder::Module';
4
5 our @EXPORT = qw(is_num_children);
6
7 my $CLASS = __PACKAGE__;
8
9 =head1 NAME
10
11 i3test::Test - Additional test instructions for use in i3 testcases
12
13 =head1 SYNOPSIS
14
15   use i3test;
16
17   my $ws = fresh_workspace;
18   is_num_children($ws, 0, 'no containers on this workspace yet');
19   cmd 'open';
20   is_num_children($ws, 1, 'one container after "open"');
21
22   done_testing;
23
24 =head1 DESCRIPTION
25
26 This module provides convenience methods for i3 testcases. If you notice that a
27 certain pattern is present in 5 or more test cases, it should most likely be
28 moved into this module.
29
30 =head1 EXPORT
31
32 =head2 is_num_children($workspace, $expected, $test_name)
33
34 Gets the number of children on the given workspace and verifies that they match
35 the expected amount of children.
36
37   is_num_children('1', 0, 'no containers on workspace 1 at startup');
38
39 =cut
40
41 sub is_num_children {
42     my ($workspace, $num_children, $name) = @_;
43     my $tb = $CLASS->builder;
44
45     my $con = i3test::get_ws($workspace);
46     $tb->ok(defined($con), "Workspace $workspace exists");
47     if (!defined($con)) {
48         $tb->skip("Workspace does not exist, skipping is_num_children");
49         return;
50     }
51
52     my $got_num_children = scalar @{$con->{nodes}};
53
54     $tb->is_num($got_num_children, $num_children, $name);
55 }
56
57 =head1 AUTHOR
58
59 Michael Stapelberg <michael@i3wm.org>
60
61 =cut
62
63 1