about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/httpd.t23
-rw-r--r--t/test_common.perl20
2 files changed, 31 insertions, 12 deletions
diff --git a/t/httpd.t b/t/httpd.t
index bf9100e..76fe7d1 100644
--- a/t/httpd.t
+++ b/t/httpd.t
@@ -11,8 +11,10 @@ my $f1 = "$mwrap_tmp/f1";
 my $f2 = "$mwrap_tmp/f2";
 mkfifo($f1, 0600) // plan(skip_all => "mkfifo: $!");
 mkfifo($f2, 0600) // plan(skip_all => "mkfifo: $!");
-my $pid = mwrap_run('httpd test', $env, '-e',
-        "open my \$f1, '>', '$f1'; close \$f1; open my \$f2, '<', '$f2'");
+my $src = $mwrap_src ? # $mwrap_src is Perl-only, Ruby otherwise
+        "open my \$f1, '>', '$f1'; close \$f1; open my \$f2, '<', '$f2'" :
+        "File.open('$f1', 'w').close; File.open('$f2', 'r').close";
+my $pid = mwrap_run('httpd test', $env, '-e', $src);
 my $spid;
 my $mw_exit;
 my $cleanup = sub {
@@ -85,9 +87,21 @@ SKIP: {
 }
 
 SKIP: {
+        my (@rproxy, @missing);
+        if (-e 'script/mwrap-rproxy') { # Perl version
+                @rproxy = ($^X, '-w', './blib/script/mwrap-rproxy');
+        } else {
+                my $exe = `which mwrap-rproxy`;
+                if ($? == 0 && defined($exe)) {
+                        chomp($rproxy[0] = $exe);
+                } else {
+                        push @missing, 'mwrap-rproxy';
+                }
+        }
         for my $m (qw(Plack::Util HTTP::Tiny)) {
-                eval "require $m" or skip "$m missing", 1;
+                eval "require $m" or push(@missing, $m);
         }
+        skip join(', ', @missing).' missing', 1 if @missing;
         my $srv = IO::Socket::INET->new(LocalAddr => '127.0.0.1',
                                 ReuseAddr => 1, Proto => 'tcp',
                                 Type => SOCK_STREAM,
@@ -103,8 +117,7 @@ SKIP: {
                 }
                 local $ENV{PLACK_ENV} = 'deployment' if !$ENV{V};
                 no warnings 'exec';
-                exec $^X, '-w', './blib/script/mwrap-rproxy',
-                        "--socket-dir=$mwrap_tmp";
+                exec @rproxy, "--socket-dir=$mwrap_tmp";
                 _exit(1);
         }
         my $http = HTTP::Tiny->new;
diff --git a/t/test_common.perl b/t/test_common.perl
index 8827362..3a073cf 100644
--- a/t/test_common.perl
+++ b/t/test_common.perl
@@ -6,8 +6,9 @@ use v5.12;
 use parent qw(Exporter);
 use Test::More;
 use File::Temp 0.19 (); # 0.19 for ->newdir
-our $mwrap_src = slurp('blib/script/mwrap-perl');
-our $mwrap_tmp = File::Temp->newdir('mwrap-perl-XXXX', TMPDIR => 1);
+our $mwrap_src;
+$mwrap_src = slurp('blib/script/mwrap-perl') if -e 'script/mwrap-perl';
+our $mwrap_tmp = File::Temp->newdir('mwrap-XXXX', TMPDIR => 1);
 our $mwrap_out = "$mwrap_tmp/out";
 our $mwrap_err = "$mwrap_tmp/err";
 our @EXPORT = qw(mwrap_run slurp $mwrap_err $mwrap_out $mwrap_src $mwrap_tmp);
@@ -20,9 +21,6 @@ sub slurp {
 
 sub mwrap_run {
         my ($msg, $env, @args) = @_;
-        unless (grep(/\A-.+\bMwrap\b/, @args)) {
-                unshift @args, '-MDevel::Mwrap';
-        }
         my $pid = fork;
         if ($pid == 0) {
                 while (my ($k, $v) = each %$env) {
@@ -30,8 +28,16 @@ sub mwrap_run {
                 }
                 open STDERR, '>', $mwrap_err or die "open: $!";
                 open STDOUT, '>', $mwrap_out or die "open: $!";
-                @ARGV = ($^X, @args);
-                eval $mwrap_src;
+                if (defined $mwrap_src) {
+                        unless (grep(/\A-.+\bMwrap\b/, @args)) {
+                                unshift @args, '-MDevel::Mwrap';
+                        }
+                        @ARGV = ($^X, @args);
+                        eval $mwrap_src;
+                } else {
+                        my $ruby = $ENV{RUBY} // 'ruby';
+                        exec $ruby, '-Ilib', 'bin/mwrap', $ruby, @args;
+                }
                 die "fail: $! ($@)";
         }
         if (defined(wantarray)) {