commit 00e344ce75c7362e394c7a097c9c1066dd3c117a
parent 70528e2b21c539ecbfca91cfe98d989afffcd961
Author: Kyle Milz <kyle@0x30.net>
Date: Wed, 15 Jun 2016 22:08:11 -0600
tt: factor out some common code from vim.t
Diffstat:
A | Test/Package.pm | | | 67 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | tt/vim.t | | | 32 | +++++++++++++------------------- |
2 files changed, 80 insertions(+), 19 deletions(-)
diff --git a/Test/Package.pm b/Test/Package.pm
@@ -0,0 +1,67 @@
+package Test::Package;
+use strict;
+
+use IPC::Open2;
+use File::Temp qw( tempdir );
+
+sub new {
+ my ($class, $dist_name, $dist_root, $extract_cmd) = @_;
+
+ my $self = {};
+ bless($self, $class);
+
+ # Create temporary directory for the contents of this package.
+ my $dir = tempdir( CLEANUP => 1 );
+ $self->{dir} = $dir;
+
+ my $dist_url = "$dist_root$dist_name";
+ system("cd $dir && curl -O $dist_url") == 0 or die "download failed";
+ system("cd $dir && $extract_cmd $dist_name") == 0 or die "extract failed";
+
+ return $self;
+}
+
+sub dir {
+ my ($self) = @_;
+ return $self->{dir};
+}
+
+sub dependencies {
+ my ($self, @deps) = @_;
+
+ my @installed_pkgs;
+ @installed_pkgs = get_installed_obsd() if ($^O eq "openbsd");
+
+ my @missing_deps;
+ for my $dep (@deps) {
+ my $found = 0;
+
+ for (@installed_pkgs) {
+ if (/^$dep.*$/) {
+ $found = 1;
+ last;
+ }
+ }
+ if ($found == 0) {
+ push @missing_deps, $dep;
+ }
+ }
+
+ my $missing_deps = join(' ', @missing_deps);
+ if (@missing_deps) {
+ die "Missing dependencies, install with: 'pkg_add $missing_deps'\n";
+ }
+}
+
+sub get_installed_obsd {
+ my $pid = open2(\*CHLD_OUT, undef, 'pkg_info');
+ waitpid( $pid, 0 );
+ my $pkg_info_exit_code = $? >> 8;
+
+ my @installed_pkgs;
+ push @installed_pkgs, ($_) while (readline \*CHLD_OUT);
+
+ return @installed_pkgs;
+}
+
+1;
diff --git a/tt/vim.t b/tt/vim.t
@@ -9,40 +9,34 @@ use List::MoreUtils qw ( each_array );
use Test::More tests => 238;
use Time::HiRes qw( time );
+use Test::Package;
use Test::Viewer;
-# Build and test Vim with citrun.
-#
-# Download source, extract, configure and compile
-#
-my $tmpdir = tempdir( CLEANUP => 1 );
+# Verify that Vim under citrun tests successfully and then cross check that the
+# data structures instrumented inside Vim are consistent with known good values.
-my $vim_src = "vim-7.4.tar.bz2";
-my $vim_url = "ftp://ftp.vim.org/pub/vim/unix/$vim_src";
+# Download: Vim 7.4 from vim.org.
+my $vim_url = "ftp://ftp.vim.org/pub/vim/unix/";
+my $package = Test::Package->new("vim-7.4.tar.bz2", $vim_url, "tar xjf");
-system("cd $tmpdir && curl -O $vim_url") == 0 or die "download failed";
-system("cd $tmpdir && tar xjf $vim_src") == 0 or die "extract failed";
+# Dependencies: gtk and curl are needed for consistent builds.
+$package->dependencies("citrun", "gtk", "curl");
-my $srcdir = "$tmpdir/vim74/src";
+# Configure.
+my $srcdir = $package->dir() . "/vim74/src";
system("citrun-wrap make -C $srcdir config") == 0 or die "citrun-wrap make config failed";
-
-# Remove last instrumented node from configure run
system("rm $srcdir/INSTRUMENTED");
+# Compile.
system("citrun-wrap make -C $srcdir -j8 myself") == 0 or die "citrun-wrap make failed";
-# Check that the native test suite can pass, validating that the instrumentation
-# hasn't broken the intent of the program.
-#
+# Test: need to use expect because Vim needs a tty to test correctly.
my $exp = Expect->spawn("make", "-C", "$srcdir/testdir");
$exp->expect(undef, ("ALL DONE"));
-
-# Unfuck the terminal after the testsuite is done
system("resize");
-# Make sure the instrumentation for vim and xxd is working correctly
-#
+# Verify: instrumented data structures are consistent.
my $viewer = Test::Viewer->new();
$ENV{CITRUN_SOCKET} = getcwd . "/citrun-test.socket";