32 lines
1.5 KiB
Nu
32 lines
1.5 KiB
Nu
#!/usr/bin/env nu
|
|
# Compare xargs stdout and exit codes with GNU xargs in a real world.
|
|
def main [host: path, bundle: path] {
|
|
let world = (mktemp -d)
|
|
mkdir ($world | path join world)
|
|
cp -r ($bundle | path join bin) ($world | path join world bin)
|
|
let nul = (char nul)
|
|
let cases = [
|
|
{input: "a\nb\n", args: [-I{} printf '<%s>\n' '{}']}
|
|
{input: "a b\nc d\n", args: [-I REPL printf '<%s>\n' preREPLpost REPL]}
|
|
{input: " 'a b'\nc\\ d\n\n", args: [-I{} printf '<%s>\n' '{}']}
|
|
{input: $"'a b'($nul)two\nlines($nul)", args: ['-0' -I{} printf '<%s>\n' '{}']}
|
|
{input: $"a b($nul)c($nul)d($nul)", args: ['-0' -n 2 printf '<%s>\n']}
|
|
{input: "a b c\n", args: [-n 2 echo]}
|
|
{input: "'a b' c\n", args: [-n1 printf '<%s>\n']}
|
|
{input: '', args: [echo]}
|
|
{input: '', args: [-r echo]}
|
|
{input: '', args: [-I{} echo '{}']}
|
|
{input: "a\n", args: [sh -c 'exit 7']}
|
|
]
|
|
for case in $cases {
|
|
$case.input | save -f ($world | path join world input)
|
|
let native = ($case.input | ^xargs ...$case.args | complete)
|
|
let command = ($case.args | each {|arg| $arg | into string | to json -r} | str join ' ')
|
|
let guest = (^$host sh $world -c $"xargs ($command) < /input" | complete)
|
|
if $native.stdout != $guest.stdout or $native.exit_code != $guest.exit_code {
|
|
error make {msg: $"xargs mismatch ($case): native=($native) guest=($guest). World: ($world)"}
|
|
}
|
|
print $"PASS xargs ($case.args)"
|
|
}
|
|
}
|