]> git.sur5r.net Git - i3/i3/blob - testcases/new-test
Merge branch 'master' into next
[i3/i3] / testcases / new-test
1 #!/usr/bin/env perl
2 # vim:ts=4:sw=4:expandtab
3 # © 2012 Michael Stapelberg and contributors
4 # Script to create a new testcase from a template.
5 #
6 #     # Create (and edit) a new test for moving floating windows
7 #     ./new-test floating move
8 #
9 #     # Create (and edit) a multi-monitor test for moving workspaces
10 #     ./new-test -m move workspaces
11
12 use strict;
13 use warnings;
14 use File::Basename qw(basename);
15 use Getopt::Long;
16 use v5.10;
17
18 my $multi_monitor;
19
20 my $result = GetOptions(
21     'multi-monitor|mm' => \$multi_monitor
22 );
23
24 my $testname = join(' ', @ARGV);
25 $testname =~ s/ /-/g;
26
27 my $header = <<'EOF';
28 #!perl
29 # vim:ts=4:sw=4:expandtab
30 #
31 # Please read the following documents before working on tests:
32 # • http://build.i3wm.org/docs/testsuite.html
33 #   (or docs/testsuite)
34 #
35 # • http://build.i3wm.org/docs/lib-i3test.html
36 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
37 #
38 # • http://build.i3wm.org/docs/ipc.html
39 #   (or docs/ipc)
40 #
41 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
42 #   (unless you are already familiar with Perl)
43 #
44 # TODO: Description of this file.
45 # Ticket: #999
46 # Bug still in: #GITREV#
47 EOF
48
49 # Figure out the next test filename.
50 my @files;
51 if ($multi_monitor) {
52     @files = grep { basename($_) =~ /^5/ } <t/*.t>;
53 } else {
54     @files = grep { basename($_) !~ /^5/ } <t/*.t>;
55 }
56 my ($latest) = sort { $b cmp $a } @files;
57 my ($num) = (basename($latest) =~ /^([0-9]+)/);
58 my $filename = "t/" . ($num+1) . "-" . lc($testname) . ".t";
59
60 # Get the current git revision.
61 chomp(my $gitrev = qx(git describe --tags));
62 $header =~ s/#GITREV#/$gitrev/g;
63
64 # Create the file based on our template.
65 open(my $fh, '>', $filename);
66 print $fh $header;
67 if ($multi_monitor) {
68     print $fh <<'EOF';
69 use i3test i3_autostart => 0;
70
71 # Ensure the pointer is at (0, 0) so that we really start on the first
72 # (the left) workspace.
73 $x->root->warp_pointer(0, 0);
74
75 my $config = <<EOT;
76 # i3 config file (v4)
77 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
78
79 fake-outputs 1024x768+0+0,1024x768+1024+0
80 EOT
81
82
83
84 exit_gracefully($pid);
85
86 done_testing;
87 EOF
88 } else {
89     print $fh <<'EOF';
90 use i3test;
91
92
93 done_testing;
94 EOF
95 }
96 close($fh);
97
98 my $editor = $ENV{EDITOR};
99 $editor ||= 'vi';
100 exec $editor, $filename;