-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·104 lines (87 loc) · 1.69 KB
/
test.sh
File metadata and controls
executable file
·104 lines (87 loc) · 1.69 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
export LC_ALL=C
pass=0
fail=0
run() {
local name="$1"
shift
if "$@"; then
printf 'ok - %s\n' "$name"
pass=$((pass + 1))
else
printf 'not ok - %s\n' "$name"
fail=$((fail + 1))
fi
}
check_line() {
local input="$1"
local needle="$2"
printf '%s\n' "$input" | ./andsh | grep -Fqx "$needle"
}
# build from a clean tree
run "build" sh -c 'make clean >/dev/null && make >/dev/null'
# simple external command
run "echo" check_line "echo hi
exit" "hi"
# cd into /
run "cd" check_line "cd /
pwd
exit" "/"
# bare cd should land in $HOME
run "cd home" check_line "cd /
cd
pwd
exit" "$HOME"
# expand a basic env var
run "env var" check_line "echo \$HOME
exit" "$HOME"
# $? should reflect the last command
run "last status" check_line "nosuchcommand
echo \$?
exit" "127"
# a small three-stage pipe
run "pipe" check_line "printf abc | tr a-z A-Z | rev
exit" "CBA"
# tab-complete a PATH command
run "completion" expect -c '
log_user 0
spawn ./andsh
expect "andsh$ "
send "unam\t"
expect {
"uname " { exit 0 }
timeout { exit 1 }
}
'
# ctrl-d should exit cleanly
run "ctrl-d exits" expect -c '
log_user 0
spawn ./andsh
expect "andsh$ "
send "\004"
expect eof
'
# up-arrow should replay history
run "history" expect -c '
log_user 0
spawn ./andsh
expect "andsh$ "
send "echo hi\r"
expect "hi"
expect "andsh$ "
send "\033\[A\r"
expect "hi"
expect "andsh$ "
'
# cursor movement should let me fix a typo inline
run "left right" expect -c '
log_user 0
spawn ./andsh
expect "andsh$ "
send "echo ac\033\[Db\r"
expect "abc"
expect "andsh$ "
'
printf '\n%s passed, %s failed\n' "$pass" "$fail"
test "$fail" -eq 0