avoid cpan indexing of test::helper
[perl-fuse.git] / test / helper.pm
1 #!/usr/bin/perl
2 package # avoid cpan indexing
3         test::helper;
4 use strict;
5 use Exporter;
6 use Config;
7 use POSIX qw(WEXITSTATUS);
8 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
9 @ISA = "Exporter";
10 @EXPORT_OK = qw($_loop $_opts $_point $_pidfile $_real);
11 my $tmp = -d '/private' ? '/private/tmp' : '/tmp';
12 our($_loop, $_point, $_pidfile, $_real, $_opts) = ('examples/loopback.pl',"$tmp/fusemnt-".$ENV{LOGNAME},$ENV{'PWD'} . "/test/s/mounted.pid","$tmp/fusetest-".$ENV{LOGNAME}, '');
13 $_opts = '--pidfile ' . $_pidfile;
14 $_opts .= $Config{useithreads} ? ' --use-threads' : '';
15 if($0 !~ qr|s/u?mount\.t$|) {
16         my ($reject) = 1;
17         if(open my $fh, '<', $_pidfile) {
18                 my $pid = do {local $/ = undef; <$fh>};
19                 close $fh;
20                 if(kill 0, $pid) {
21                         if(`mount` =~ m{on (?:/private)?$_point }) {
22                                 $reject = 0;
23                         } else {
24                                 kill 1, $pid;
25                         }
26                 }
27         }
28         system("ls $_point >/dev/null");
29         $reject = 1 if (POSIX::WEXITSTATUS($?));
30         die "not properly mounted\n" if $reject;
31 }
32 1;