Skip to content

Commit 4469a4d

Browse files
committed
add root to agg
1 parent 97a58f9 commit 4469a4d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

agg

+20-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ or to check whether specific tests can pass under Test2::Aggregate.
1919
Options:
2020
--out <s>, -o <s> : Specify the test file to be created (tmp file by default).
2121
--lists, -l : Use files specified as lists.
22-
--prove, -p : Force prove (default is yath/Test2 if detected).
22+
--prove, -p : Force prove (default is yath/Test2 if installed).
2323
--verbose, -v : Verbose (passed to yath/prove)
24-
--absolute, -a : Use absolute paths in generated files.
24+
--absolute, -a : Use absolute paths in generated files. Disabled with -r.
25+
--root <s> -r <s> : Define a custom root dir (default is current dir).
2526
--include <s>, -I <s> : Library paths to include.
2627
--test_warnings, -w : Fail tests on warnings.
2728
--test_bundle <s>, -t : Test bundle (def: Test2::V0 or Test::More if -p). Can be comma-separated list.
@@ -39,6 +40,7 @@ use warnings;
3940

4041
use lib 'lib';
4142

43+
use Carp;
4244
use Cwd;
4345
use File::Temp 'tempfile';
4446
use Getopt::Long;
@@ -48,13 +50,15 @@ use Pod::Usage;
4850
my %opt = (framework => 'Test2::V0');
4951
GetOptions(
5052
\%opt,
53+
'absolute|a',
5154
'help|h',
5255
'include|I=s',
53-
'out|o=s',
5456
'lists|l',
57+
'out|o=s',
5558
'pass_output|po=s',
5659
'prove|p',
5760
'reverse',
61+
'root|r=s',
5862
'shuffle',
5963
'sort',
6064
'stats_output|so=s',
@@ -69,6 +73,18 @@ pod2usage({-verbose => 1, -output => \*STDOUT, -noperldoc => 1})
6973
$opt{test_bundle} ||= $opt{prove} ? 'Test::More' : 'Test2::V0';
7074
$opt{stats_output} = $opt{pass_output} if $opt{pass_output};
7175

76+
if ($opt{root}) {
77+
$opt{absolute} = undef;
78+
croak "Specified --root does not exist" unless -e $opt{root};
79+
my $slash = '';
80+
$slash = '/' unless $opt{root} =~ m#/$#;
81+
foreach (@ARGV) {
82+
croak "$opt{root}$slash$_ doesn't exist" unless -e "$opt{root}$slash$_";
83+
}
84+
} elsif (!$opt{absolute}) {
85+
$opt{root} = "./";
86+
}
87+
7288
unless ($opt{prove}) {
7389
eval "use Test2::Harness";
7490
$opt{prove} = 1 if $@;
@@ -82,7 +98,7 @@ my $file = $opt{out} ? path($opt{out}) : Path::Tiny->tempfile(
8298

8399
print "Writing output to $file\n" if $opt{verbose};
84100

85-
my $cwd = getcwd();
101+
my $cwd = $opt{root} || getcwd();
86102
my $code = test_bundle_use($opt{test_bundle});
87103

88104
$code .= "

0 commit comments

Comments
 (0)