Skip to content

Instantly share code, notes, and snippets.

@hideo55
Created May 1, 2014 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideo55/1e837e3d4ec4d2fc7930 to your computer and use it in GitHub Desktop.
Save hideo55/1e837e3d4ec4d2fc7930 to your computer and use it in GitHub Desktop.
use Test::More;
use Config;
use File::Spec::Functions qw(catdir catfile rel2abs);
use File::Path;
use File::Temp qw(tempdir);
use File::Copy::Recursive 'dircopy';
use Cwd::Guard qw(cwd_guard);
use Capture::Tiny qw(capture);
my $perl = $Config{perlpath};
my @perl = ($perl, map { "-I" . $_ } @INC);
my $eg_dir = rel2abs(catdir(qw/eg Foo/));
my $tmp_dir = tempdir( CLEANUP => 1 );
dircopy($eg_dir, $tmp_dir);
like run_cmd($tmp_dir, @perl, catfile($tmp_dir, 'Build.PL')), qr/Creating new 'Build' script for 'Foo' version '0.01'/;
run_cmd($tmp_dir, @perl, catfile($tmp_dir, 'Build'));
like run_cmd($tmp_dir, @perl, catfile($tmp_dir, 'Build test')), qr/Result\:\s*PASS/;
done_testing;
sub run_cmd {
my ($work_dir, @cmd) = @_;
my $cmd = join ' ', @cmd;
my $guard = cwd_guard($work_dir);
my ($stdout, $stderr, $result) = capture{
system($cmd);
};
return $stdout;
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment