1use strict;
2use Test::More;
3use xt::CLI;
4
5subtest 'carton exec without a command', sub {
6    my $app = cli();
7    $app->write_cpanfile('');
8    $app->run("install");
9    $app->run("exec");
10    like $app->stderr, qr/carton exec needs a command/;
11    is $app->exit_code, 255;
12};
13
14subtest 'exec without cpanfile', sub {
15    my $app = cli();
16    $app->run("exec", "perl", "-e", 1);
17    like $app->stderr, qr/Can't locate cpanfile/;
18    is $app->exit_code, 255;
19};
20
21subtest 'exec without a snapshot', sub {
22    my $app = cli();
23    $app->write_cpanfile();
24    $app->run("exec", "perl", "-e", 1);
25    like $app->stderr, qr/cpanfile\.snapshot/;
26    is $app->exit_code, 255;
27};
28
29subtest 'carton exec', sub {
30    my $app = cli();
31    $app->write_cpanfile('');
32    $app->run("install");
33
34 TODO: {
35        local $TODO = "exec now does not strip site_perl";
36        $app->run("exec", "perl", "-e", "use Try::Tiny");
37        like $app->stderr, qr/Can't locate Try\/Tiny.pm/;
38    }
39
40    $app->write_cpanfile(<<EOF);
41requires 'Try::Tiny', '== 0.11';
42EOF
43
44    $app->run("install");
45
46    $app->run("exec", "--", "perl", "-e", 'use Try::Tiny; print $Try::Tiny::VERSION, "\n"');
47    like $app->stdout, qr/0\.11/;
48
49    $app->run("exec", "perl", "-e", 'use Try::Tiny; print $Try::Tiny::VERSION, "\n"');
50    like $app->stdout, qr/0\.11/, "No need for -- as well";
51
52    $app->run("exec", "perl", "-MTry::Tiny", "-e", 'print $Try::Tiny::VERSION, "\n"');
53    like $app->stdout, qr/0\.11/;
54
55    $app->write_cpanfile(<<EOF);
56requires 'Try::Tiny';
57requires 'App::Ack', '== 2.02';
58EOF
59
60    $app->run("install");
61    $app->run("exec", "--", "ack", "--version");
62
63    like $app->stdout, qr/ack 2\.02/;
64};
65
66subtest 'carton exec perl -Ilib', sub {
67    my $app = cli();
68    $app->write_cpanfile('');
69    $app->run("install");
70
71    $app->dir->child("lib")->mkpath;
72    $app->dir->child("lib/FooBarBaz.pm")->spew("package FooBarBaz; 1");
73
74    $app->run("exec", "perl", "-Ilib", "-e", 'use FooBarBaz; print "foo"');
75    like $app->stdout, qr/foo/;
76    unlike $app->stderr, qr/exec -Ilib is deprecated/;
77
78    $app->run("exec", "-Ilib", "perl", "-e", 'print "foo"');
79    like $app->stdout, qr/foo/;
80    like $app->stderr, qr/exec -Ilib is deprecated/;
81};
82
83done_testing;
84
85