| 1 | #!/bin/sh |
| 2 | TEST_PREFIX="[cd-pwd]" |
| 3 | . "$(cd "$(dirname "$0")" && pwd)/test_harness.sh" |
| 4 | |
| 5 | section "1. cd basic" |
| 6 | compare_output "cd no args goes to HOME" 'cd && pwd | tail -1' |
| 7 | compare_output "cd to absolute /tmp" 'cd /tmp && pwd' |
| 8 | compare_output "cd to relative subdir" "mkdir -p $TEST_TMPDIR/sub && cd $TEST_TMPDIR && cd sub && pwd" |
| 9 | compare_exit "cd to nonexistent dir fails" 'cd /nonexistent_dir_xyz_12345' |
| 10 | compare_exit "cd to nonexistent dir exit code" 'cd /nonexistent_dir_xyz_12345 2>/dev/null' |
| 11 | compare_output "cd to root" 'cd / && pwd' |
| 12 | compare_output "cd with trailing slash" 'cd /tmp/ && pwd' |
| 13 | |
| 14 | section "2. cd special" |
| 15 | compare_output "cd - returns to OLDPWD" 'cd /tmp && cd / && cd - 2>/dev/null && pwd' |
| 16 | compare_output "OLDPWD is set after cd" 'cd /tmp && cd / && echo $OLDPWD' |
| 17 | compare_output "cd .. parent directory" 'cd /tmp && cd .. && pwd' |
| 18 | compare_output "cd ../.. grandparent" 'cd /tmp && cd ../.. 2>/dev/null && pwd' |
| 19 | compare_output "cd . stays in same dir" 'cd /tmp && cd . && pwd' |
| 20 | |
| 21 | section "3. pwd" |
| 22 | compare_output "pwd outputs current dir" 'pwd' |
| 23 | compare_exit "pwd exits 0" 'pwd' |
| 24 | compare_output "pwd -L logical path" 'pwd -L' |
| 25 | compare_output "pwd -P physical path" 'pwd -P' |
| 26 | |
| 27 | section "4. cd with CDPATH" |
| 28 | compare_output "cd with CDPATH" "mkdir -p $TEST_TMPDIR/base/target && CDPATH=$TEST_TMPDIR/base && cd target 2>/dev/null && pwd" |
| 29 | |
| 30 | print_summary |