1 package App::Rgit::TestUtils;
7 use File::Temp qw/tempfile/;
8 use File::Spec (); # curdir, catfile
9 use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG/;
12 no warnings 'redefine';
13 *WIFEXITED = sub { 1 } unless eval { WIFEXITED(0); 1 };
14 *WEXITSTATUS = sub { shift() >> 8 } unless eval { WEXITSTATUS(0); 1 };
15 *WIFSIGNALED = sub { shift() & 127 } unless eval { WIFSIGNALED(0); 1 };
16 *WTERMSIG = sub { shift() & 127 } unless eval { WTERMSIG(0); 1 };
19 use base qw/Exporter/;
21 our @EXPORT_OK = (qw/can_run_git/);
24 my ($fh, $filename) = tempfile(UNLINK => 1);
35 my $git = File::Spec->catfile(File::Spec->curdir, qw/t bin git/);
36 if ($^O eq 'MSWin32') {
40 @ret = (0, "no $git executable");
46 @ret = (0, "no $git executable");
51 system { $git } $git, @args;
54 @ret = (0, $! || "unknown");
59 $status = WEXITSTATUS($?) if WIFEXITED($?);
61 if (WIFSIGNALED($?)) {
62 @ret = (0, 'process recieved signal ' . WTERMSIG($?));
64 @ret = (0, "process exited with code $status");
68 return wantarray ? @ret : $ret[0];