From eda1359a31ed2af904a111596ae2650da6eebd41 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Tue, 13 Apr 2021 20:43:29 +0900 Subject: [PATCH] add a test for 'clone-modules' command --- t/command-clone-modules.t | 104 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 t/command-clone-modules.t diff --git a/t/command-clone-modules.t b/t/command-clone-modules.t new file mode 100644 index 00000000..84c378a2 --- /dev/null +++ b/t/command-clone-modules.t @@ -0,0 +1,104 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +BEGIN { $ENV{SHELL} = "/bin/bash" } + +use FindBin; +use lib $FindBin::Bin; +use App::perlbrew; +require "test_helpers.pl"; + +use Test::Spec; + +mock_perlbrew_install("perl-5.14.1"); +mock_perlbrew_install("perl-5.16.0"); + +no warnings; +my ($__from, $__to, $__notest); +sub App::perlbrew::run_command_exec { + my ($self, @args) = @_; + + diag "ARGS: @args"; + + if (grep { $_ eq '-MExtUtils::Installed' } @args) { + $__from = $args[1]; + + my ($fn) = $args[5] =~ m{open .+">", "(.+?)";}; + if ($fn) { + open my $fh, ">", $fn; + print $fh "Foo\nBar\n"; + close($fh); + } else { + die "Failed to grok output path."; + } + } elsif (grep { $_ eq 'cpanm' } @args) { + $__to = $args[1]; + ($__notest) = grep { $_ eq '--notest' } @{$self->{original_argv}}; + } + return $self; +} +use warnings; + +describe "clone-modules command," => sub { + before each => sub { + delete $ENV{PERL_MB_OPT}; + delete $ENV{PERL_MM_OPT}; + delete $ENV{PERL_LOCAL_LIB_ROOT}; + delete $ENV{PERLBREW_LIB}; + delete $ENV{PERL5LIB}; + $__from = undef; + $__to = undef; + $__notest = undef; + }; + + describe "when invoked with two arguments, A and B", sub { + it "should display clone modules from A to B", sub { + my $app = App::perlbrew->new( + "clone-modules", "perl-5.14.1", "perl-5.16.0" + ); + $app->run; + is $__from, "perl-5.14.1"; + is $__to, "perl-5.16.0"; + ok(!defined($__notest)); + }; + }; + + describe "when invoked with two arguments, A and B, with `--notest`", sub { + it "should display clone modules from A to B", sub { + my $app = App::perlbrew->new( + "clone-modules", "--notest", "perl-5.14.1", "perl-5.16.0" + ); + $app->run; + is $__from, "perl-5.14.1"; + is $__to, "perl-5.16.0"; + ok(defined($__notest)); + }; + }; + + describe "when invoked with one argument X", sub { + it "should display clone modules from current-perl to X", sub { + my $app = App::perlbrew->new("clone-modules", "perl-5.14.1"); + $app->expects("current_env")->returns("perl-5.16.0")->at_least(1); + $app->run; + + is $__from, "perl-5.16.0"; + is $__to, "perl-5.14.1"; + ok(!defined($__notest)); + }; + }; + + describe "when invoked with one argument X, with `--notest`", sub { + it "should display clone modules from current-perl to X", sub { + my $app = App::perlbrew->new("clone-modules", "--notest", "perl-5.14.1"); + $app->expects("current_env")->returns("perl-5.16.0")->at_least(1); + $app->run; + + is $__from, "perl-5.16.0"; + is $__to, "perl-5.14.1"; + ok(defined($__notest)); + }; + }; +}; + +runtests unless caller;