| 1 | #!/bin/sh |
| 2 | TEST_PREFIX="[hash]" |
| 3 | . "$(cd "$(dirname "$0")/.." && pwd)/test_harness.sh" |
| 4 | |
| 5 | section "1. hash basic" |
| 6 | check_exit "hash with no args" 'hash' "0" |
| 7 | check_exit "hash -r clears cache" 'hash -r' "0" |
| 8 | compare_exit "hash specific command" 'hash ls' |
| 9 | compare_exit "hash nonexistent command fails" 'hash nonexistent_cmd_xyz_999 2>/dev/null' |
| 10 | compare_output "hash -r then lookup" 'hash -r; hash ls 2>/dev/null; echo $?' |
| 11 | |
| 12 | section "2. hash caching behavior" |
| 13 | compare_output "hash caches after use" 'ls >/dev/null; hash -t ls 2>/dev/null || hash ls 2>/dev/null; echo $?' |
| 14 | compare_output "hash -r clears then miss" 'ls >/dev/null; hash -r; hash -t ls 2>/dev/null; echo $?' |
| 15 | compare_output "hash multiple commands" 'ls >/dev/null; cat /dev/null; hash ls cat 2>/dev/null; echo $?' |
| 16 | |
| 17 | section "3. hash error handling" |
| 18 | compare_exit "hash nonexistent gives error" 'hash no_such_cmd_xyz 2>/dev/null' |
| 19 | compare_output "hash after PATH change" 'hash ls 2>/dev/null; PATH=""; hash -t ls 2>/dev/null; echo $?' |
| 20 | |
| 21 | print_summary |