#!perl

use strict;
use warnings;

my $n1    = 1000;
my $n2    = 100;
my $tests = 10_000;

use File::Spec;
use Benchmark qw<cmpthese :hireswallclock>;

my $has_test_tiny;
BEGIN {
 $has_test_tiny = do {
  local $@;
  eval { require Test::Tiny; 1 }
 }
}

my $dev_null = File::Spec->devnull;

my %test_modules = (
 'Test::More'   => sub { system "$^X -e 'use Test::More tests => 1; ok(1);' > $dev_null" },
 'Test::Leaner' => sub { system "$^X -Ilib -e 'use Test::Leaner tests => 1; ok(1);' > $dev_null" },
);

if ($has_test_tiny) {
 $test_modules{'Test::Tiny'} = sub { system "$^X -e 'use Test::Tiny tests => 1; ok(1);' > $dev_null" },
}

print "Loading:\n";
cmpthese $n1, \%test_modules;
print "\n";

require Test::More;
require Test::Builder;
require Test::Leaner;

open my $nullfh, '>', $dev_null or die "Can't open null fh: $!";

Test::Builder->new->output($nullfh);
Test::Leaner::tap_stream($nullfh);

Test::More::plan('no_plan');
Test::Leaner::plan('no_plan');

%test_modules = (
 'Test::More'    => sub { Test::More::ok(1)   for 1 .. $tests },
 'Test::Leaner'  => sub { Test::Leaner::ok(1) for 1 .. $tests },
);

if ($has_test_tiny) {
 $test_modules{'Test::Tiny'} = sub { my $outfh = select $nullfh; Test::Tiny::ok(1) for 1 .. $tests; select $outfh },
}

print "Simple tests:\n";
cmpthese $n2, \%test_modules;
