Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tool/test_bash_exe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,29 @@ try {
Test-Bash 'SHELL' '"$SHELL" -c "echo nested"' '^nested\s*$'
# `bash`, `sh` are this bash (with its tools), not WSL's or Git's.
Test-Bash 'bash script.sh' 'echo "type -t rg" > nested.sh && bash nested.sh && sh -c "type -t rg"' '^builtin\nbuiltin\n$'
Test-Bash 'a script is its own BASH_SOURCE' 'echo ''[[ "${BASH_SOURCE[0]}" == "$0" ]] && echo main'' > main.sh && bash main.sh' '^main\n$'
Test-Bash 'BASH, the path of this bash' 'case "$BASH" in *[/\\]bash.exe) echo path ;; esac' '^path\n$'

# What scripts written for Git Bash test for and use.
Test-Bash 'uname and OSTYPE, as Git Bash' 'uname -s; echo "$OSTYPE"' '^MINGW64_NT-\S+\nmsys\n$'
Test-Bash 'process substitution' 'diff <(printf "a\n") <(printf "b\n"); cat <(echo sub)' '^1c1\n< a\n---\n> b\nsub\n$'
Test-Bash '/dev/stdin and /dev/stderr' 'echo in | cat /dev/stdin; echo teed | tee /dev/stderr 2>&1 >/dev/null' '^in\nteed\n$'
Test-Bash '/dev/urandom and /dev/zero' 'head -c 16 /dev/urandom | wc -c; tr -dc a-z < /dev/urandom | head -c 5 | wc -c; head -c 3 /dev/zero | od -An -tx1' '^\s*16\n\s*5\n\s*00 00 00\n$'
Test-Bash 'env and xargs find .exe programs' 'env A=1 git --version; echo --version | xargs git' '^git version.*\ngit version'
Test-Bash 'sed, on input not in UTF-8' 'printf "caf\xe9 x\n" | sed s/x/y/ | od -An -tx1' '^\s*63 61 66 e9 20 79 0a\n$'
Test-Bash 'a #! line' 'printf "#!/usr/bin/env node\nconsole.log(process.argv[2])\n" > shebang.js && ./shebang.js arg' '^arg\n$'
Test-Bash 'chmod' 'touch ro.txt && chmod 444 ro.txt && [ ! -w ro.txt ] && chmod u+w ro.txt && [ -w ro.txt ] && echo ok' '^ok\n$'

# A script run as `bash script.sh` has the tools ahead of PATH, as `-c`
# has (System32's `sort`, Git's `xargs` came first).
[IO.File]::WriteAllText((Join-Path $work 'tools.sh'), "printf 'b\na\n' | sort | tr '\n' ' '; printf 'x\n' | xargs -I{} echo `"got {}`"; exit 4`n")
$ran = Invoke-Bash @('tools.sh')
if ($ran.Status -ne 4 -or $ran.Out -ne "a b got x`n") {
Write-Host "FAIL a script's tools: $($ran.Status) '$($ran.Out)' $($ran.Err)"
$failed++
} else {
Write-Host "ok a script's tools"
}

# A job left in the background is not waited for, as bash's are not.
$started = Get-Date
Expand Down
Loading