2012-10-03 02:13:30 +04:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
# © 2012 Michael Stapelberg and contributors
|
|
|
|
# Script to create a new testcase from a template.
|
|
|
|
#
|
|
|
|
# # Create (and edit) a new test for moving floating windows
|
|
|
|
# ./new-test floating move
|
|
|
|
#
|
|
|
|
# # Create (and edit) a multi-monitor test for moving workspaces
|
|
|
|
# ./new-test -m move workspaces
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Basename qw(basename);
|
|
|
|
use Getopt::Long;
|
|
|
|
use v5.10;
|
|
|
|
|
2013-10-17 15:20:35 +04:00
|
|
|
my $usage = <<'EOF';
|
|
|
|
Script to create a new testcase from a template.
|
|
|
|
|
|
|
|
# Create (and edit) a new test for moving floating windows
|
|
|
|
./new-test floating move
|
|
|
|
|
|
|
|
# Create (and edit) a multi-monitor test for moving workspaces
|
|
|
|
./new-test -m move workspaces
|
|
|
|
EOF
|
|
|
|
|
2012-10-03 02:13:30 +04:00
|
|
|
my $multi_monitor;
|
|
|
|
|
|
|
|
my $result = GetOptions(
|
|
|
|
'multi-monitor|mm' => \$multi_monitor
|
|
|
|
);
|
|
|
|
|
|
|
|
my $testname = join(' ', @ARGV);
|
|
|
|
$testname =~ s/ /-/g;
|
|
|
|
|
2013-10-17 15:20:35 +04:00
|
|
|
unless (length $testname) {
|
|
|
|
say $usage;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2012-10-03 02:13:30 +04:00
|
|
|
my $header = <<'EOF';
|
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
|
|
|
# Please read the following documents before working on tests:
|
2017-09-24 11:19:07 +03:00
|
|
|
# • https://build.i3wm.org/docs/testsuite.html
|
2012-10-03 02:13:30 +04:00
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
2017-09-24 11:19:07 +03:00
|
|
|
# • https://build.i3wm.org/docs/lib-i3test.html
|
2012-10-03 02:13:30 +04:00
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
2017-09-24 11:19:07 +03:00
|
|
|
# • https://build.i3wm.org/docs/ipc.html
|
2012-10-03 02:13:30 +04:00
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
2023-08-31 21:01:56 +03:00
|
|
|
# • https://i3wm.org/downloads/modern_perl_a4.pdf
|
2012-10-03 02:13:30 +04:00
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
#
|
|
|
|
# TODO: Description of this file.
|
|
|
|
# Ticket: #999
|
|
|
|
# Bug still in: #GITREV#
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Figure out the next test filename.
|
|
|
|
my @files;
|
|
|
|
if ($multi_monitor) {
|
|
|
|
@files = grep { basename($_) =~ /^5/ } <t/*.t>;
|
|
|
|
} else {
|
|
|
|
@files = grep { basename($_) !~ /^5/ } <t/*.t>;
|
|
|
|
}
|
|
|
|
my ($latest) = sort { $b cmp $a } @files;
|
|
|
|
my ($num) = (basename($latest) =~ /^([0-9]+)/);
|
|
|
|
my $filename = "t/" . ($num+1) . "-" . lc($testname) . ".t";
|
|
|
|
|
|
|
|
# Get the current git revision.
|
|
|
|
chomp(my $gitrev = qx(git describe --tags));
|
|
|
|
$header =~ s/#GITREV#/$gitrev/g;
|
|
|
|
|
|
|
|
# Create the file based on our template.
|
|
|
|
open(my $fh, '>', $filename);
|
|
|
|
print $fh $header;
|
|
|
|
if ($multi_monitor) {
|
|
|
|
print $fh <<'EOF';
|
|
|
|
use i3test i3_autostart => 0;
|
|
|
|
|
|
|
|
my $config = <<EOT;
|
|
|
|
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
|
|
|
|
|
|
|
fake-outputs 1024x768+0+0,1024x768+1024+0
|
|
|
|
EOT
|
|
|
|
|
2012-12-22 17:08:25 +04:00
|
|
|
my $pid = launch_with_config($config);
|
2012-10-03 02:13:30 +04:00
|
|
|
|
|
|
|
|
|
|
|
exit_gracefully($pid);
|
|
|
|
|
|
|
|
done_testing;
|
|
|
|
EOF
|
|
|
|
} else {
|
|
|
|
print $fh <<'EOF';
|
|
|
|
use i3test;
|
|
|
|
|
|
|
|
|
|
|
|
done_testing;
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
close($fh);
|
|
|
|
|
|
|
|
my $editor = $ENV{EDITOR};
|
|
|
|
$editor ||= 'vi';
|
|
|
|
exec $editor, $filename;
|