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 };
18 use base qw/Exporter/;
20 our @EXPORT_OK = (qw/can_run_git/);
23 my ($fh, $filename) = tempfile(UNLINK => 1);
34 my $git = File::Spec->catfile(File::Spec->curdir, qw/t bin git/);
35 if ($^O eq 'MSWin32') {
39 @ret = (0, "no $git executable");
45 @ret = (0, "no $git executable");
50 system { $git } $git, @args;
53 @ret = (0, $! || "unknown");
58 $status = WEXITSTATUS($?) if WIFEXITED($?);
60 if (WIFSIGNALED($?)) {
61 @ret = (0, 'process recieved signal ' . WTERMSIG($?));
63 @ret = (0, "process exited with code $status");
67 return wantarray ? @ret : $ret[0];