tests: Move perl tests to tests/, make them callable from top-level Makefile

Use "make test" or "make test-verbose" to run.
Note that "make test" seems to be more common than "make tests", hence the
change.

Also, use a new clean directory directory as a working area for each run
Created using mkdtemp and deleted in cleanup()
This commit is contained in:
Jakob Unterwurzacher 2014-10-20 19:59:08 +02:00
parent 38970c75bd
commit 0e8e1dd20c
3 changed files with 33 additions and 28 deletions

View File

@ -14,3 +14,11 @@ MAINTAINERCLEANFILES = aclocal.m4
ACLOCAL_AMFLAGS = -I m4
.PHONY: test
test:
perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' tests/*.pl
.PHONY: test-verbose
test-verbose:
perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' tests/*.pl

View File

@ -141,9 +141,3 @@ encfs-man.html: encfs.pod
@POD2HTML@ encfs.pod > $@
endif
tests:
perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' *.t
tests-verbose:
perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' *.t

View File

@ -3,26 +3,25 @@
use Test::More qw( no_plan );
use File::Path;
use File::Copy;
use File::Temp;
use IO::Handle;
use Digest::MD5 qw(md5_hex);
my $tempDir = $ENV{'TMPDIR'} || "/tmp";
my $raw = "$tempDir/crypt-raw-$$";
my $crypt = "$tempDir/crypt-$$";
# test filesystem in standard config mode
&runTests('standard');
# test in paranoia mode
&runTests('paranoia');
# Wrapper function - runs all tests in the specified mode
sub runTests
{
my $mode = shift;
&newWorkingDir;
my $hardlinks = 1;
if($mode eq 'standard')
{
@ -48,6 +47,17 @@ sub runTests
&cleanup;
}
# Helper function
# Create a new empty working directory
sub newWorkingDir
{
our $workingDir = mkdtemp("$tempDir/encfs-tests-XXXX")
|| BAIL_OUT("Could not create temporary directory");
our $raw = "$workingDir/raw";
our $crypt = "$workingDir/crypt";
}
# Test Corruption
# Modify the encrypted file and verify that the MAC check detects it
sub corruption
@ -71,7 +81,7 @@ sub corruption
# (like a database would do)
sub internalModification
{
$ofile = "$tempDir/crypt-internal-$$";
$ofile = "$workingDir/crypt-internal-$$";
qx(dd if=/dev/urandom of=$ofile bs=2k count=2 2> /dev/null);
ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file");
@ -196,7 +206,7 @@ sub fileCreation
sub grow
{
open(my $fh_a, "+>$crypt/grow");
open(my $fh_b, "+>$tempDir/grow");
open(my $fh_b, "+>$workingDir/grow");
my $d = "1234567"; # Length 7 so we are not aligned to the block size
my $len = 7;
@ -248,7 +258,7 @@ sub checkContents
sub encName
{
my $plain = shift;
my $enc = qx(./encfsctl encode --extpass="echo test" $raw $plain);
my $enc = qx(./encfs/encfsctl encode --extpass="echo test" $raw $plain);
chomp($enc);
return $enc;
}
@ -297,15 +307,11 @@ sub mount
{
my $args = shift;
ok( ! -d $raw, "no existing dir");
ok( ! -d $crypt, "no existing dir");
# When these fail, the rest of the tests makes no sense
mkdir($raw) || BAIL_OUT("Could not create $raw: $!");
mkdir($crypt) || BAIL_OUT("Could not create $crypt: $!");
mkdir $raw;
ok( -d $raw, "created dir" );
mkdir $crypt;
ok( -d $crypt, "created dir" );
qx(./encfs --extpass="echo test" $args $raw $crypt);
qx(./encfs/encfs --extpass="echo test" $args $raw $crypt);
ok( -f "$raw/.encfs6.xml", "created control file");
}
@ -327,10 +333,7 @@ sub cleanup
rmdir $crypt;
ok( ! -d $crypt, "unmount ok, mount point removed");
if(-d $raw)
{
rmtree($raw);
}
ok( ! -d $raw, "encrypted directory removed");
rmtree($workingDir);
ok( ! -d $workingDir, "working dir removed");
}