aboutsummaryrefslogtreecommitdiff
path: root/tests/sh.test
blob: ecfa27916d369ebf5d36f2d364c1904e739205bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

# Testing shell corner cases _within_ a shell script is kind of hard.

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

[ -z "$SH" ] && { [ -z "$TEST_HOST" ] && SH="sh" || export SH="bash" ; }
export EVAL="$SH -c"

#testing "leading assignments don't affect current line" \
#  'VAR=12345 echo ${VAR}a' "a\n" "" ""
#testing "can't have space before first : but yes around arguments" \
#  'BLAH=abcdefghi; echo ${BLAH: 1 : 3 }' "bcd\n" "" ""

# texpect "name" "command" E/O/I"string"

# Prompt changes for root/normal user
[ $(id -u) -eq 0 ] && P='# ' || P='$ '
# run sufficiently isolated shell child process to get predictable results
SH="env -i PATH=${PATH@Q} PS1='\\$ ' $SH --noediting --noprofile --norc -is"

txpect "prompt and exit" "$SH" "E$P" "Iexit\n" X0
txpect "prompt and echo" "$SH" "E$P" "Iecho hello\n" "Ohello"$'\n' "E$P" X0