]> git.sur5r.net Git - i3/i3/blob - testcases/new-test
4efcde5d4acc3d8352f06127227db372e994d982
[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 $usage = <<'EOF';
19 Script to create a new testcase from a template.
20
21     # Create (and edit) a new test for moving floating windows
22     ./new-test floating move
23
24     # Create (and edit) a multi-monitor test for moving workspaces
25     ./new-test -m move workspaces
26 EOF
27
28 my $multi_monitor;
29
30 my $result = GetOptions(
31     'multi-monitor|mm' => \$multi_monitor
32 );
33
34 my $testname = join(' ', @ARGV);
35 $testname =~ s/ /-/g;
36
37 unless (length $testname) {
38     say $usage;
39     exit(0);
40 }
41
42 my $header = <<'EOF';
43 #!perl
44 # vim:ts=4:sw=4:expandtab
45 #
46 # Please read the following documents before working on tests:
47 # • http://build.i3wm.org/docs/testsuite.html
48 #   (or docs/testsuite)
49 #
50 # • http://build.i3wm.org/docs/lib-i3test.html
51 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
52 #
53 # • http://build.i3wm.org/docs/ipc.html
54 #   (or docs/ipc)
55 #
56 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
57 #   (unless you are already familiar with Perl)
58 #
59 # TODO: Description of this file.
60 # Ticket: #999
61 # Bug still in: #GITREV#
62 EOF
63
64 # Figure out the next test filename.
65 my @files;
66 if ($multi_monitor) {
67     @files = grep { basename($_) =~ /^5/ } <t/*.t>;
68 } else {
69     @files = grep { basename($_) !~ /^5/ } <t/*.t>;
70 }
71 my ($latest) = sort { $b cmp $a } @files;
72 my ($num) = (basename($latest) =~ /^([0-9]+)/);
73 my $filename = "t/" . ($num+1) . "-" . lc($testname) . ".t";
74
75 # Get the current git revision.
76 chomp(my $gitrev = qx(git describe --tags));
77 $header =~ s/#GITREV#/$gitrev/g;
78
79 # Create the file based on our template.
80 open(my $fh, '>', $filename);
81 print $fh $header;
82 if ($multi_monitor) {
83     print $fh <<'EOF';
84 use i3test i3_autostart => 0;
85
86 my $config = <<EOT;
87 # i3 config file (v4)
88 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
89
90 fake-outputs 1024x768+0+0,1024x768+1024+0
91 EOT
92
93 my $pid = launch_with_config($config);
94
95
96 exit_gracefully($pid);
97
98 done_testing;
99 EOF
100 } else {
101     print $fh <<'EOF';
102 use i3test;
103
104
105 done_testing;
106 EOF
107 }
108 close($fh);
109
110 my $editor = $ENV{EDITOR};
111 $editor ||= 'vi';
112 exec $editor, $filename;