App-Yath-Script
view release on metacpan or search on metacpan
t/unit/Script.t view on Meta::CPAN
subtest 'clean_path' => sub {
my $cwd = getcwd();
like(dies { clean_path(undef) }, qr/No path was provided/, 'undef dies');
like(dies { clean_path('') }, qr/No path was provided/, 'empty string dies');
my $result = clean_path('lib');
ok(-d $result, 'result is a real directory');
is($result, File::Spec->rel2abs(realpath('lib')), 'resolves to absolute realpath');
# With absolute=0, skip realpath
my $no_real = clean_path('lib', 0);
is($no_real, File::Spec->rel2abs('lib'), 'absolute=0 skips realpath');
};
subtest 'find_in_updir' => sub {
# Create a temp file in cwd so we have something reliable to find
my $marker = ".yath_test_marker_$$";
open(my $fh, '>', $marker) or die "Cannot create $marker: $!";
close($fh);
my $found = find_in_updir($marker);
ok(defined $found, 'found marker file');
ok(-f $found, 'marker file is a file');
like($found, qr/\Q$marker\E$/, 'path ends with marker filename');
unlink $marker;
# Non-existent file returns undef
my $missing = find_in_updir('.nonexistent_file_that_should_not_exist');
is($missing, undef, 'returns undef for missing file');
};
subtest 'script and module accessors' => sub {
# Before do_begin, these depend on package state. Just verify they are callable.
ok(defined &App::Yath::Script::script, 'script() is defined');
ok(defined &App::Yath::Script::module, 'module() is defined');
};
subtest 'inject_includes' => sub {
local %ENV = %ENV;
delete $ENV{T2_HARNESS_INCLUDES};
# Should be a no-op when env var is not set
my @orig_inc = @INC;
App::Yath::Script::inject_includes();
is(\@INC, \@orig_inc, 'no-op without T2_HARNESS_INCLUDES');
# Should replace @INC when set
$ENV{T2_HARNESS_INCLUDES} = '/fake/path1;/fake/path2';
App::Yath::Script::inject_includes();
is(\@INC, ['/fake/path1', '/fake/path2'], 'replaces @INC from env var');
# Restore
@INC = @orig_inc;
};
subtest 'parse_new_dev_libs' => sub {
# No -D args, should return 0
local @ARGV = ('test', '--verbose');
is(App::Yath::Script::parse_new_dev_libs(), 0, 'returns 0 with no -D args');
# Stops at --
local @ARGV = ('--', '-D');
is(App::Yath::Script::parse_new_dev_libs(), 0, 'stops at --');
# Stops at ::
local @ARGV = ('::', '-D');
is(App::Yath::Script::parse_new_dev_libs(), 0, 'stops at ::');
};
subtest '_collect_dev_libs' => sub {
is([App::Yath::Script::_collect_dev_libs()], [], 'empty input -> empty list');
is(
[App::Yath::Script::_collect_dev_libs('test', '--verbose', 'foo')],
[],
'no -D tokens -> empty list',
);
is(
[App::Yath::Script::_collect_dev_libs('-D')],
[map { clean_path($_) } 'lib', 'blib/lib', 'blib/arch'],
'bare -D adds default trio',
);
is(
[App::Yath::Script::_collect_dev_libs('--dev-lib')],
[map { clean_path($_) } 'lib', 'blib/lib', 'blib/arch'],
'bare --dev-lib adds default trio',
);
is(
[App::Yath::Script::_collect_dev_libs('--dev-libs')],
[map { clean_path($_) } 'lib', 'blib/lib', 'blib/arch'],
'bare --dev-libs adds default trio',
);
is(
[App::Yath::Script::_collect_dev_libs('-D=/foo/bar')],
['/foo/bar'],
'-D=path adds the path',
);
is(
[App::Yath::Script::_collect_dev_libs('--dev-lib=/foo/bar')],
['/foo/bar'],
'--dev-lib=path adds the path',
);
is(
[App::Yath::Script::_collect_dev_libs('--dev-libs=/foo/bar')],
['/foo/bar'],
'--dev-libs=path adds the path',
);
is(
[App::Yath::Script::_collect_dev_libs('-D=/a,/b,/c')],
['/a', '/b', '/c'],
'comma-separated paths split',
);
is(
[App::Yath::Script::_collect_dev_libs('-D=/foo', 'middle', '--dev-libs=/bar')],
['/foo', '/bar'],
'mixed args, only -D tokens collected',
);
( run in 0.762 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )