| 1 | #!/bin/sh |
| 2 | TEST_PREFIX="[history]" |
| 3 | . "$(cd "$(dirname "$0")/.." && pwd)/test_harness.sh" |
| 4 | |
| 5 | section "1. history display" |
| 6 | check_exit "history runs without error" 'history' "0" |
| 7 | check_exit "history N shows last N" 'history 5' "0" |
| 8 | skip "history produces numbered output" "requires interactive mode (no history in -c)" |
| 9 | |
| 10 | section "2. history management" |
| 11 | check_exit "history -c clears history" 'history -c' "0" |
| 12 | compare_output "history -c then history shows empty" 'history -c; history | wc -l | tr -d " "' |
| 13 | check_exit "history -d deletes entry" 'history -d 1 2>/dev/null' "0" |
| 14 | |
| 15 | section "3. history file operations" |
| 16 | check_exit "history -w writes to file" "HISTFILE=$TEST_TMPDIR/hist_test; history -w" "0" |
| 17 | check_exit "history -r reads from file" "HISTFILE=$TEST_TMPDIR/hist_test; history -r" "0" |
| 18 | check_exit "history -a appends to file" "HISTFILE=$TEST_TMPDIR/hist_test; history -a" "0" |
| 19 | check_output "history -w creates file" "HISTFILE=$TEST_TMPDIR/hist_w; history -w; test -f $TEST_TMPDIR/hist_w && echo yes" "yes" |
| 20 | skip "history -w then -r round-trip" "requires interactive mode (no history in -c)" |
| 21 | |
| 22 | section "4. history HISTSIZE" |
| 23 | skip "HISTSIZE limits history" "requires interactive mode (no history in -c)" |
| 24 | |
| 25 | section "5. history edge cases" |
| 26 | check_exit "history with invalid flag" 'history --invalid 2>/dev/null; true' "0" |
| 27 | check_exit "history 0 shows nothing" 'history 0' "0" |
| 28 | check_exit "history negative number" 'history -1 2>/dev/null; true' "0" |
| 29 | |
| 30 | print_summary |