From 84e70a19a82eeed387160a75f4ca28717cd5db7a Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 10 Oct 2016 21:14:59 +0200 Subject: [PATCH] testsuite: use relative paths, set PATH to absolute path This approach works better with autotools, which supports the build directory being complete outside the source tree. --- .../{complete-run.pl => complete-run.pl.in} | 71 ++++++++----------- testcases/lib/SocketActivation.pm | 10 +-- testcases/lib/TestWorker.pm | 2 +- testcases/lib/{i3test.pm => i3test.pm.in} | 2 +- testcases/t/171-config-migrate.t | 2 +- testcases/t/187-commands-parser.t | 2 +- testcases/t/196-randr-output-names.t | 2 +- testcases/t/201-config-parser.t | 2 +- testcases/t/207-shmlog.t | 8 +-- testcases/t/235-check-config-no-x.t | 2 +- 10 files changed, 41 insertions(+), 62 deletions(-) rename testcases/{complete-run.pl => complete-run.pl.in} (89%) rename testcases/lib/{i3test.pm => i3test.pm.in} (99%) diff --git a/testcases/complete-run.pl b/testcases/complete-run.pl.in similarity index 89% rename from testcases/complete-run.pl rename to testcases/complete-run.pl.in index 14c0a15d..d872bda1 100755 --- a/testcases/complete-run.pl +++ b/testcases/complete-run.pl.in @@ -17,19 +17,8 @@ use TAP::Parser::Aggregator; use Time::HiRes qw(time); use IO::Handle; -my $dirname; - -BEGIN { - use File::Basename; - use Cwd qw(abs_path); - - # fileparse()[1] contains the directory portion of the specified path. - # See File::Basename(3p) for more details. - $dirname = (fileparse(abs_path($0)))[1]; -} - # these are shipped with the testsuite -use lib $dirname . 'lib'; +use lib qw(@abs_top_builddir@/testcases/lib @abs_top_srcdir@/testcases/lib); use i3test::Util qw(slurp); use StartXServer; use StatusLine; @@ -82,17 +71,15 @@ my $result = GetOptions( pod2usage(-verbose => 2, -exitcode => 0) if $help; -chdir $dirname or die "Could not chdir into $dirname"; - # Check for missing executables my @binaries = qw( - ../i3 - ../i3bar/i3bar - ../i3-config-wizard/i3-config-wizard - ../i3-dump-log/i3-dump-log - ../i3-input/i3-input - ../i3-msg/i3-msg - ../i3-nagbar/i3-nagbar + @abs_top_builddir@/i3 + @abs_top_builddir@/i3bar/i3bar + @abs_top_builddir@/i3-config-wizard/i3-config-wizard + @abs_top_builddir@/i3-dump-log/i3-dump-log + @abs_top_builddir@/i3-input/i3-input + @abs_top_builddir@/i3-msg/i3-msg + @abs_top_builddir@/i3-nagbar/i3-nagbar ); foreach my $binary (@binaries) { @@ -100,15 +87,16 @@ foreach my $binary (@binaries) { die "$binary is not an executable" unless -x $binary; } -if ($options{coverage}) { - qx(command -v lcov &> /dev/null); - die "Cannot find lcov needed for coverage testing." if $?; - qx(command -v genhtml &> /dev/null); - die "Cannot find genhtml needed for coverage testing." if $?; - - # clean out the counters that may be left over from previous tests. - qx(lcov -d ../ --zerocounters &> /dev/null); -} +$ENV{PATH} = join(':', + '@abs_top_builddir@/i3-nagbar', + '@abs_top_builddir@/i3-msg', + '@abs_top_builddir@/i3-input', + '@abs_top_builddir@/i3-dump-log', + '@abs_top_builddir@/i3-config-wizard', + '@abs_top_builddir@/i3bar', + '@abs_top_builddir@', + '@abs_top_srcdir@', + $ENV{PATH}); qx(Xephyr -help 2>&1); die "Xephyr was not found in your path. Please install Xephyr (xserver-xephyr on Debian)." if $?; @@ -120,7 +108,17 @@ die "Xephyr was not found in your path. Please install Xephyr (xserver-xephyr on my @testfiles = @ARGV; # if no files were passed on command line, run all tests from t/ -@testfiles = if @testfiles == 0; +if (scalar @testfiles == 0) { + @testfiles = <@abs_top_srcdir@/testcases/t/*.t> if @testfiles == 0; +} else { + @testfiles = map { + # Fully qualify each specified file if necessary + if (! -e $_) { + $_ = "@abs_top_srcdir@/testcases/$_"; + } + $_ + } @testfiles; +} my $numtests = scalar @testfiles; @@ -251,17 +249,6 @@ if ($numtests == 1) { END { cleanup() } -if ($options{coverage}) { - print("\nGenerating test coverage report...\n"); - qx(lcov -d ../ -b ../ --capture -o latest/i3-coverage.info); - qx(genhtml -o latest/i3-coverage latest/i3-coverage.info); - if ($?) { - print("Could not generate test coverage html. Did you compile i3 with test coverage support?\n"); - } else { - print("Test coverage report generated in latest/i3-coverage\n"); - } -} - # Report logfiles that match “(Leak|Address)Sanitizer:”. my @logs_with_leaks; for my $log (<$outdir/i3-log-for-*>) { diff --git a/testcases/lib/SocketActivation.pm b/testcases/lib/SocketActivation.pm index b58707a4..53dbb3b6 100644 --- a/testcases/lib/SocketActivation.pm +++ b/testcases/lib/SocketActivation.pm @@ -62,14 +62,6 @@ sub activate_i3 { mkdir $ENV{XDG_RUNTIME_DIR}; } $ENV{DISPLAY} = $args{display}; - $ENV{PATH} = join(':', - '../i3-nagbar', - '../i3-msg', - '../i3-config-wizard', - '../i3bar', - '..', - $ENV{PATH} - ); # We are about to exec, but we did not modify $^F to include $socket # when creating the socket (because the file descriptor could have a @@ -96,7 +88,7 @@ sub activate_i3 { # the interactive signalhandler to make it crash immediately instead. # Also disable logging to SHM since we redirect the logs anyways. # Force Xinerama because we use Xdmx for multi-monitor tests. - my $i3cmd = abs_path("../i3") . q| --shmlog-size=0 --disable-signalhandler --force-xinerama|; + my $i3cmd = q|i3 --shmlog-size=0 --disable-signalhandler --force-xinerama|; if (!$args{validate_config}) { # We only set logging if i3 is actually started, but not if we only # validate the config file. This is to keep logging to a minimum as diff --git a/testcases/lib/TestWorker.pm b/testcases/lib/TestWorker.pm index 6371591f..aee994f7 100644 --- a/testcases/lib/TestWorker.pm +++ b/testcases/lib/TestWorker.pm @@ -125,7 +125,7 @@ sub worker_wait { package main; local $@; - do "./$file"; + do $file; $test->ok(undef, "$@") if $@; # XXX hack, we need to trigger the read watcher once more diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm.in similarity index 99% rename from testcases/lib/i3test.pm rename to testcases/lib/i3test.pm.in index 98486122..f9f6e821 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm.in @@ -836,7 +836,7 @@ sub launch_with_config { if ($config ne '-default') { say $fh $config; } else { - open(my $conf_fh, '<', './i3-test.config') + open(my $conf_fh, '<', '@abs_top_srcdir@/testcases/i3-test.config') or $tester->BAIL_OUT("could not open default config: $!"); local $/; say $fh scalar <$conf_fh>; diff --git a/testcases/t/171-config-migrate.t b/testcases/t/171-config-migrate.t index d098ae58..5bd21128 100644 --- a/testcases/t/171-config-migrate.t +++ b/testcases/t/171-config-migrate.t @@ -29,7 +29,7 @@ sub migrate_config { print $fh $config; close($fh); - my $cmd = "sh -c 'exec " . abs_path("../i3-migrate-config-to-v4") . " --v3 <$tmpfile'"; + my $cmd = "sh -c 'exec i3-migrate-config-to-v4 --v3 <$tmpfile'"; return [ split /\n/, qx($cmd) ]; } diff --git a/testcases/t/187-commands-parser.t b/testcases/t/187-commands-parser.t index 73c443f9..dc5b67ed 100644 --- a/testcases/t/187-commands-parser.t +++ b/testcases/t/187-commands-parser.t @@ -25,7 +25,7 @@ sub parser_calls { # TODO: use a timeout, so that we can error out if it doesn’t terminate # TODO: better way of passing arguments - my $stdout = qx(../test.commands_parser '$command' 2>&1 >&-); + my $stdout = qx(test.commands_parser '$command' 2>&1 >&-); # Filter out all debugging output. my @lines = split("\n", $stdout); diff --git a/testcases/t/196-randr-output-names.t b/testcases/t/196-randr-output-names.t index e5049eb8..7c53732b 100644 --- a/testcases/t/196-randr-output-names.t +++ b/testcases/t/196-randr-output-names.t @@ -28,7 +28,7 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 workspace 2 output DVI-I_1/digital EOT -my $output = qx(../i3 -C -c $filename); +my $output = qx(i3 -C -c $filename); unlike($output, qr/ERROR/, 'no errors in i3 -C'); close($fh); diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t index d92d3b20..6cd84b6f 100644 --- a/testcases/t/201-config-parser.t +++ b/testcases/t/201-config-parser.t @@ -25,7 +25,7 @@ sub parser_calls { my ($command) = @_; my $stdout; - run [ '../test.config_parser', $command ], + run [ 'test.config_parser', $command ], '>/dev/null', '2>', \$stdout; # TODO: use a timeout, so that we can error out if it doesn’t terminate diff --git a/testcases/t/207-shmlog.t b/testcases/t/207-shmlog.t index b63a7499..b6c6d776 100644 --- a/testcases/t/207-shmlog.t +++ b/testcases/t/207-shmlog.t @@ -33,7 +33,7 @@ my $pid = launch_with_config($config); my $stdout; my $stderr; -run [ '../i3-dump-log/i3-dump-log' ], +run [ 'i3-dump-log' ], '>', \$stdout, '2>', \$stderr; @@ -49,7 +49,7 @@ cmd 'shmlog on'; my $random_nop = mktemp('nop.XXXXXX'); cmd "nop $random_nop"; -run [ '../i3-dump-log/i3-dump-log' ], +run [ 'i3-dump-log' ], '>', \$stdout, '2>', \$stderr; @@ -62,7 +62,7 @@ like($stderr, qr#^$#, 'stderr empty'); cmd 'shmlog ' . (23 * 1024 * 1024); -run [ '../i3-dump-log/i3-dump-log' ], +run [ 'i3-dump-log' ], '>', \$stdout, '2>', \$stderr; @@ -75,7 +75,7 @@ like($stderr, qr#^$#, 'stderr empty'); cmd 'shmlog off'; -run [ '../i3-dump-log/i3-dump-log' ], +run [ 'i3-dump-log' ], '>', \$stdout, '2>', \$stderr; diff --git a/testcases/t/235-check-config-no-x.t b/testcases/t/235-check-config-no-x.t index ec17353e..5e87d992 100644 --- a/testcases/t/235-check-config-no-x.t +++ b/testcases/t/235-check-config-no-x.t @@ -26,7 +26,7 @@ sub check_config { my ($config) = @_; my ($fh, $tmpfile) = tempfile(UNLINK => 1); print $fh $config; - my $output = qx(DISPLAY= ../i3 -C -c $tmpfile 2>&1); + my $output = qx(DISPLAY= i3 -C -c $tmpfile 2>&1); my $retval = $?; $fh->flush; close($fh); -- 2.39.5