Alien-Xrepo
view release on metacpan or search on metacpan
t/002_argv.t view on Meta::CPAN
my ( $action, $flags, @spec ) = @$case;
my @argv = $repo->_argv( $action, $flags, @spec );
is $argv[0], $xmake_exe, "$action: argv starts with the xmake exe";
is [ @argv[ 1 .. 3 ] ], [ qw[lua private.xrepo], $action ], "$action: runs `xmake lua private.xrepo $action`";
# The spec (versioned single-string or multi-token) is the trailing argv.
my @tail = @argv[ 4 .. $#argv ];
my $n = @spec;
my $start = $#tail + 1 - $n;
is [ @tail[ $start .. $#tail ] ], [@spec], "$action: package spec is the trailing argument(s)";
# No dash-prefixed flag may appear after the first spec token: that is
# exactly the parser-leak the invariant guards against.
my $first_spec = $#argv + 1 - $n;
for my $i ( $first_spec + 1 .. $#argv ) {
unlike $argv[$i], qr{^-}, "$action: no flag follows the spec";
}
}
# A versioned spec stays a single argv element so spaces never split argv.
my @argv = $repo->_argv( 'install', ['-y'], 'libsdl3_ttf >=3.2.2' );
is $argv[-1], 'libsdl3_ttf >=3.2.2', 'versioned spec is a single trailing element';
};
subtest '_full_spec composes a pinned version into a single spec token' => sub {
is $repo->_full_spec( 'raylib', undef ), 'raylib', 'no version keeps the bare name';
is $repo->_full_spec( 'raylib', '' ), 'raylib', 'empty version ignored';
is $repo->_full_spec( 'raylib', '6.0.x' ), 'raylib 6.0.x', 'a pinned version joins the name';
my @argv = $repo->_argv( 'install', ['-y'], $repo->_full_spec( 'raylib', '6.0.x' ) );
is scalar @argv, 6, 'one spec token, no argv inflation';
is $argv[-1], 'raylib 6.0.x', 'pinned spec is the single trailing element';
};
subtest '_build_args configs boolean rendering' => sub {
# A Perl built-in boolean (use feature 'true'/'false' via use v5.40) must render as the
# literal string 'true'/'false' that xrepo expects, never as 1 / "".
my @bool = $repo->_build_args( { configs => { shared => true } } );
my ($flag_bool) = grep {/^--configs=/} @bool;
is $flag_bool, '--configs=shared=true', 'built-in true renders as --configs=shared=true';
my @boolf = $repo->_build_args( { configs => { shared => false } } );
my ($flag_boolf) = grep {/^--configs=/} @boolf;
is $flag_boolf, '--configs=shared=false', 'built-in false renders as --configs=shared=false';
my @mixed = $repo->_build_args( { configs => { shared => true, vs_runtime => 'MD' } } );
my ($flag_mixed) = grep {/^--configs=/} @mixed;
is $flag_mixed, '--configs=shared=true,vs_runtime=MD', 'booleans and strings mix in key order';
# Plain numbers / strings are historical behavior: values pass through untouched.
my @vec = $repo->_build_args( { configs => { legacy => 1, mode => 'debug' } } );
my ($flag_vec) = grep {/^--configs=/} @vec;
is $flag_vec, '--configs=legacy=1,mode=debug', 'non-boolean config values pass through unchanged';
};
subtest '_package_file is only generated for a system install' => sub {
# Without `system`, an install must stay on the bare-spec path: xrepo's shim forces
# system=false there, which is what keeps an isolated/pinned install inside its own store.
ok !scalar $repo->_package_file( 'zlib', {} ), 'no package file without system';
# With it, the install is driven through a package file so our own add_requires decides system.
my $file = $repo->_package_file( 'libsdl3_ttf 3.2.2', { system => 1, kind => 'shared' } );
ok defined $file && -f $file, 'package file is created';
like $file, qr/xrepo\.lua$/, 'package file has a .lua name (the shim keys off the suffix)';
my $body = path($file)->slurp_utf8;
like $body, qr/^add_requires\("libsdl3_ttf 3\.2\.2"\)$/m, 'add_requires carries the versioned spec verbatim';
like $body, qr/^add_requireconfs\("libsdl3_ttf", \{configs = \{shared = true\}\}\)$/m, 'kind folds into configs';
# The whole point: no `system` option. `system = true` means system-only in xmake and would
# fail outright instead of falling back to a source build; leaving it unset means "prefer the
# system, else build", which is what makes add_extsources() reachable again.
unlike $body, qr/system/, 'no system option at all: prefer-system-then-build, not system-only';
# configs and kind both land in add_requireconfs rather than --configs, which the shim ignores
# once it has a package file.
my $f2 = $repo->_package_file( 'zlib', { system => 1, kind => 'shared', configs => { vs_runtime => 'MD', wsa => false, plain => 1 }, } );
my $b2 = path($f2)->slurp_utf8;
like $b2, qr/shared = true/, 'shared from kind';
like $b2, qr/vs_runtime = "MD"/, 'string config is quoted as a Lua string';
like $b2, qr/wsa = false/, 'built-in false renders as Lua false';
like $b2, qr/plain = 1/, 'numeric 1 config renders as a Lua number, like --configs does';
my $f3 = $repo->_package_file( 'zlib', { system => 1, kind => 'static' } );
like path($f3)->slurp_utf8, qr/shared = false/, 'kind => static pins shared = false';
# no_kind suppresses the shared choice, as it does for -k.
my $f4 = $repo->_package_file( 'zlib', { system => 1, kind => 'shared', no_kind => 1 } );
unlike path($f4)->slurp_utf8, qr/shared/, 'no_kind omits the shared config entirely';
};
subtest '_cache_key separates system from private installs' => sub {
my $plain = $repo->_cache_key( 'zlib', { kind => 'shared' } );
my $sys = $repo->_cache_key( 'zlib', { kind => 'shared', system => 1 } );
isnt $sys, $plain, 'a system install never reuses a private-install entry';
is $repo->_cache_key( 'zlib', { kind => 'shared', system => 0 } ), $plain, 'system => 0 stays on the private identity';
};
subtest '_build_args includes uses the OS path separator' => sub {
# xrepo's install.lua splits `--includes` with path.splitenv and rejoins with
# path.joinenv -- both keyed off the platform path separator, never a comma.
my $sep = $Config{path_sep};
# Nonexistent/plain includes pass through as absolute paths (xrepo silently
# drops anything that doesn't resolve, preserving the old no-op behavior).
my @single = $repo->_build_args( { includes => 'recipe.lua' } );
my ($flag_single) = grep {/^--includes=/} @single;
is $flag_single, '--includes=' . path('recipe.lua')->absolute->stringify, 'scalar include normalized to an absolute path';
my @multi = $repo->_build_args( { includes => [ 'a.lua', 'b.lua' ] } );
my ($flag_multi) = grep {/^--includes=/} @multi;
is $flag_multi, '--includes=' . join( $sep, map { path($_)->absolute->stringify } qw[a.lua b.lua] ),
"array includes joined with path separator ($sep)";
unlike $flag_multi, qr{,}, 'array includes never joined with a comma';
# Paths containing the separator would split, but normal single paths are fine.
# (Path::Tiny normalizes backslashes to forward slashes, which xmake accepts.)
if ( $^O eq 'MSWin32' ) {
my @win = $repo->_build_args( { includes => 'C:\path with space\recipe.lua' } );
my ($flag_win) = grep {/^--includes=/} @win;
is $flag_win, '--includes=C:/path with space/recipe.lua', 'Windows path passes through (forward-slash normalized)';
}
};
subtest '_build_args auto-confirm flags' => sub {
my @default = $repo->_build_args( {} );
is [ grep {/^-y$/} @default ], [], 'no -y when neither yes nor confirm is given';
my @yes = $repo->_build_args( { yes => 1 } );
is [ grep {/^-y$/} @yes ], ['-y'], '-y emitted for yes => 1';
my @yes0 = $repo->_build_args( { yes => 0 } );
is [ grep {/^-y$/} @yes0 ], [], 'no -y for yes => 0';
my @confirm = $repo->_build_args( { confirm => 'never' } );
is [ grep {/^--confirm=/} @confirm ], ['--confirm=never'], '--confirm= emitted for confirm =>';
is [ grep {/^-y$/} @confirm ], [], 'confirm suppresses -y';
my @both = $repo->_build_args( { yes => 1, confirm => 'never' } );
is [ grep {/^--confirm=/} @both ], ['--confirm=never'], 'confirm wins over yes';
is [ grep {/^-y$/} @both ], [], 'no -y when confirm is set';
};
subtest '_confirm_args default-confirm for mutating actions' => sub {
# install/uninstall/download/import/export auto-confirm by default so a
# captured install never hangs, but an explicit choice is honored.
is [ $repo->_confirm_args( {} ) ], ['-y'], 'default mutating action confirms';
is [ $repo->_confirm_args( { yes => 0 } ) ], [], 'yes => 0 opts out';
is [ $repo->_confirm_args( { yes => 1 } ) ], [], 'yes => 1 handled by _build_args';
is [ $repo->_confirm_args( { confirm => 'never' } ) ], [], 'confirm opts out';
};
subtest '_verbosity_args adds xmake -v/-D for installs only' => sub {
# Default instance (verbose => 0): nothing extra, so a plain install stays byte-identical.
is [ $repo->_verbosity_args( {} ) ], [], 'no flags by default';
( run in 1.194 second using v1.01-cache-2.11-cpan-234fa220139 )