#!/usr/bin/env nu # Time each corpus construct after compare.nu creates the worlds and warms the cache. def main [host: path, shell: path] { let root = '/tmp/s2-shell/comparison' let cases = [ {name: 'command substitution: pwd', script: 'printf "%s\n" "$(pwd)"'} {name: 'command substitution: cat | tr', script: 'printf "%s\n" "$(cat f | tr a-z A-Z)"'} {name: 'glob: ls | wc', script: 'ls *.txt | wc -l'} {name: 'subshell: cd', script: '( cd sub && pwd )'} {name: 'quoted heredoc', script: "cat <<'EOF'\n$HOME stays literal\nEOF\n"} {name: 'stderr and append redirects', script: 'cat missing 2>/dev/null >> log; cat f 2>/dev/null >> log; cat log'} {name: 'stdin redirect', script: 'wc -l < file'} {name: 'glob loop', script: 'for f in *; do printf "entry=%s\n" "$f"; done'} {name: 'false || echo', script: 'false || echo ok'} {name: 'exit status', script: 'false; echo $?'} {name: 'stderr and child exit', script: 'cat missing'} {name: 'whole-root traversal', script: '( cd sub && cd ../../other && pwd && cd ../work && pwd )'} {name: 'external paths across root', script: 'cd ../other; pwd; cat ../work/f; cat @ROOT@/work/f'} {name: 'yes | head', script: 'yes | head -n 2'} ] let results = ($cases | each {|case| let script = ('cd work; ' + $case.script) let native_root = ($root | path join native) let start = (date now) let native = (do { cd $native_root; ^bash --noprofile --norc -c ($script | str replace --all '@ROOT@' $native_root) } | complete) let native_ms = (((date now) - $start) / 1ms) let start = (date now) let guest = (^$host ($root | path join guest) $shell -c ($script | str replace --all '@ROOT@' '') | complete) let guest_ms = (((date now) - $start) / 1ms) let equal = (($native.stdout | str replace --all $native_root '') == $guest.stdout and $native.exit_code == $guest.exit_code) if not $equal { error make {msg: $'case failed: ($case.name)', help: $guest.stderr} } if $native.stderr != '' and $guest.stderr == '' { error make {msg: 'child stderr was lost'} } {command: $case.name, native_ms: $native_ms, guest_ms: $guest_ms, exit: $guest.exit_code, equal: $equal} }) $results | to json }