| 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 |
# • https://build.i3wm.org/docs/testsuite.html |
| 48 |
# (or docs/testsuite) |
| 49 |
# |
| 50 |
# • https://build.i3wm.org/docs/lib-i3test.html |
| 51 |
# (alternatively: perldoc ./testcases/lib/i3test.pm) |
| 52 |
# |
| 53 |
# • https://build.i3wm.org/docs/ipc.html |
| 54 |
# (or docs/ipc) |
| 55 |
# |
| 56 |
# • https://i3wm.org/downloads/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 |
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
| 88 |
|
| 89 |
fake-outputs 1024x768+0+0,1024x768+1024+0 |
| 90 |
EOT |
| 91 |
|
| 92 |
my $pid = launch_with_config($config); |
| 93 |
|
| 94 |
|
| 95 |
exit_gracefully($pid); |
| 96 |
|
| 97 |
done_testing; |
| 98 |
EOF |
| 99 |
} else { |
| 100 |
print $fh <<'EOF'; |
| 101 |
use i3test; |
| 102 |
|
| 103 |
|
| 104 |
done_testing; |
| 105 |
EOF |
| 106 |
} |
| 107 |
close($fh); |
| 108 |
|
| 109 |
my $editor = $ENV{EDITOR}; |
| 110 |
$editor ||= 'vi'; |
| 111 |
exec $editor, $filename; |