on master help sign in
Merge pull request #3 from replit/mc-expecttest

add tests to prybar

commit4c14c515e7cc6256806d03ead78308b99310f027 authorMason Clayton <masongclayton@gmail.com> dateFri 26 Oct 2018, 20:14 (8 years ago) parent61733f48544133
20 files changed+471−5
.travis.yml+7 Dockerfile+3−3 Makefile+5−2 run_tests+24 tests/python2/1_plus_1.exp+12 tests/python2/code_print.exp+5 tests/python2/exception.exp+13 tests/python2/expr.exp+5 tests/python2/ps1.exp+12 tests/python2/ps2.exp+18 tests/python2/quiet.exp+11 tests/python2/stdout_stderr.exp+222 tests/python3/1_plus_1.exp+12 tests/python3/eval_code.exp+6 tests/python3/printing.exp+16 tests/python3/run_code.exp+6 tests/python3/set_ps1.exp+12 tests/python3/set_ps2.exp+17 tests/python3/show_header.exp+14 tests/python3/stderr_red.exp+51
.travis.ymlnew file+7
@@ -0,0 +1,7 @@
1+sudo: required
2+
3+services:
4+ - docker
5+
6+script:
7+ - docker build -t prybar .
Dockerfile+3−3
@@ -10,7 +10,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
1010 ruby2.5-dev \
1111 tcl-dev \
1212 libnspr4-dev \
13− libffi-dev
13+ libffi-dev \
14+ expect
1415
1516RUN wget \
1617 http://launchpadlibrarian.net/309343864/libmozjs185-dev_1.8.5-1.0.0+dfsg-7_amd64.deb && \
@@ -20,12 +21,11 @@ RUN wget \
2021RUN mkdir -p /gocode/src/github.com/replit/prybar
2122
2223ENV GOPATH=/gocode
23−
2424ADD . /gocode/src/github.com/replit/prybar
25−
2625WORKDIR /gocode/src/github.com/replit/prybar
2726
2827RUN make prybar-python2 prybar-python3 prybar-ruby prybar-lua prybar-spidermonkey
28+RUN make test
2929
3030ENV LC_ALL=C.UTF-8
3131
Makefile+5−2
@@ -2,14 +2,17 @@ LANGDIR := ./languages
22LANGS := $(shell ls $(LANGDIR))
33BINS := $(addprefix prybar-,$(LANGS))
44
5−.PHONY: clean default
5+.PHONY: clean test all
66
7−default: $(BINS)
7+all: $(BINS)
88
99prybar-%: ./languages/$(*) ./utils/* ./linenoise/* ./languages/$(*)/*
1010 cp inject_launch.go ./languages/$(*)/inject_launch.go
1111 CGO_LDFLAGS_ALLOW=".*" go build -o prybar-$(*) ./languages/$(*)
1212 rm ./languages/$(*)/inject_launch.go
1313
14+test:
15+ ./run_tests
16+
1417clean:
1518 @rm ./prybar-*
run_testsnew file+24
@@ -0,0 +1,24 @@
1+#!/usr/bin/env bash
2+
3+tests=$(find ./tests -printf '%P\n')
4+
5+for t in ${tests}; do
6+ if [[ $t != *.exp ]]; then
7+ echo "$t:"
8+ continue
9+ fi
10+
11+ name=$(echo -n $t | sed -s 's/.*\/\(.*\).exp/\1/' | sed -s 's/_/ /g')
12+
13+ echo -n "... $name"
14+
15+ test_out=$(timeout 10 "./tests/$t" 2>&1)
16+ if [[ $? != 0 ]]; then
17+ echo -e "\n========== \"$t\" failed =========="
18+ echo $test_out
19+ exit 1;
20+ fi
21+
22+ echo -ne '\r'
23+ echo " ✓ $name"
24+done
tests/python2/1_plus_1.expnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -i
4+match_max 100000
5+expect "Python 2.*"
6+expect -exact "--> "
7+send -- "1+1\r"
8+expect -exact "1+1\r
9+2\r
10+--> "
11+send -- ""
12+expect eof
tests/python2/code_print.expnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -q -c print('hello')
4+match_max 100000
5+expect eof
tests/python2/exception.expnew file+13
@@ -0,0 +1,13 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -q -i
4+match_max 100000
5+expect -exact "--> "
6+send -- "ohno\r"
7+expect -exact "ohno\r
8+Traceback (most recent call last):\r
9+ File \"<stdin>\", line 1, in <module>\r
10+NameError: name 'ohno' is not defined\r
11+--> "
12+send -- ""
13+expect eof
tests/python2/expr.expnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -e 1+1
4+match_max 100000
5+expect eof
tests/python2/ps1.expnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -i -ps1 somethingelse
4+match_max 100000
5+expect "Python 2.*\r"
6+expect -exact "somethingelse"
7+send -- "123\r"
8+expect -exact "123\r
9+123\r
10+somethingelse"
11+send -- ""
12+expect eof
tests/python2/ps2.expnew file+18
@@ -0,0 +1,18 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -i -ps2 continuation
4+match_max 100000
5+expect "Python 2.*\r"
6+expect -exact "--> "
7+send -- "if True:\r"
8+expect -exact "if True:\r
9+continuation"
10+send -- " print('continued!')\r"
11+expect -exact "continued!')\r
12+continuation"
13+send -- ""
14+expect -exact "\r
15+continued!\r
16+--> "
17+send -- ""
18+expect eof
tests/python2/quiet.expnew file+11
@@ -0,0 +1,11 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -q -i
4+match_max 100000
5+expect -exact "--> "
6+send -- "1+1\r"
7+expect -exact "1+1\r
8+2\r
9+--> "
10+send -- ""
11+expect eof
tests/python2/stdout_stderr.expnew file+222
@@ -0,0 +1,222 @@
1+#!/usr/bin/expect -f
2+
3+spawn ./prybar-python2 -q -i
4+match_max 100000
5+expect -exact "--> "
6+send -- "import sys\r"
7+expect -exact "import sys\r
8+--> "
9+send -- "for i in range(0, 100):\r"
10+expect -exact "in range(0, 100):\r
11+... "
12+send -- " sys.stderr.write(str(i) + '\\n')\r"
13+expect -exact " sys.stderr.write(str(i) + '\\n')\r
14+... "
15+send -- " sys.stdout.write(str(i) + '\\n')\r"
16+expect -exact " sys.stdout.write(str(i) + '\\n')\r
17+... "
18+send -- "\r"
19+expect -exact "\r
20+0\r
21+0\r
22+1\r
23+1\r
24+2\r
25+2\r
26+3\r
27+3\r
28+4\r
29+4\r
30+5\r
31+5\r
32+6\r
33+6\r
34+7\r
35+7\r
36+8\r
37+8\r
38+9\r
39+9\r
40+10\r
41+10\r
42+11\r
43+11\r
44+12\r
45+12\r
46+13\r
47+13\r
48+14\r
49+14\r
50+15\r
51+15\r
52+16\r
53+16\r
54+17\r
55+17\r
56+18\r
57+18\r
58+19\r
59+19\r
60+20\r
61+20\r
62+21\r
63+21\r
64+22\r
65+22\r
66+23\r
67+23\r
68+24\r
69+24\r
70+25\r
71+25\r
72+26\r
73+26\r
74+27\r
75+27\r
76+28\r
77+28\r
78+29\r
79+29\r
80+30\r
81+30\r
82+31\r
83+31\r
84+32\r
85+32\r
86+33\r
87+33\r
88+34\r
89+34\r
90+35\r
91+35\r
92+36\r
93+36\r
94+37\r
95+37\r
96+38\r
97+38\r
98+39\r
99+39\r
100+40\r
101+40\r
102+41\r
103+41\r
104+42\r
105+42\r
106+43\r
107+43\r
108+44\r
109+44\r
110+45\r
111+45\r
112+46\r
113+46\r
114+47\r
115+47\r
116+48\r
117+48\r
118+49\r
119+49\r
120+50\r
121+50\r
122+51\r
123+51\r
124+52\r
125+52\r
126+53\r
127+53\r
128+54\r
129+54\r
130+55\r
131+55\r
132+56\r
133+56\r
134+57\r
135+57\r
136+58\r
137+58\r
138+59\r
139+59\r
140+60\r
141+60\r
142+61\r
143+61\r
144+62\r
145+62\r
146+63\r
147+63\r
148+64\r
149+64\r
150+65\r
151+65\r
152+66\r
153+66\r
154+67\r
155+67\r
156+68\r
157+68\r
158+69\r
159+69\r
160+70\r
161+70\r
162+71\r
163+71\r
164+72\r
165+72\r
166+73\r
167+73\r
168+74\r
169+74\r
170+75\r
171+75\r
172+76\r
173+76\r
174+77\r
175+77\r
176+78\r
177+78\r
178+79\r
179+79\r
180+80\r
181+80\r
182+81\r
183+81\r
184+82\r
185+82\r
186+83\r
187+83\r
188+84\r
189+84\r
190+85\r
191+85\r
192+86\r
193+86\r
194+87\r
195+87\r
196+88\r
197+88\r
198+89\r
199+89\r
200+90\r
201+90\r
202+91\r
203+91\r
204+92\r
205+92\r
206+93\r
207+93\r
208+94\r
209+94\r
210+95\r
211+95\r
212+96\r
213+96\r
214+97\r
215+97\r
216+98\r
217+98\r
218+99\r
219+99\r
220+--> "
221+send -- ""
222+expect eof
tests/python3/1_plus_1.expnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -i -q
5+match_max 100000
6+expect -exact "--> "
7+send -- "1+1\r"
8+expect -exact "1+1\r
9+2\r
10+--> "
11+send -- ""
12+expect eof
tests/python3/eval_code.expnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -e 1+1
5+match_max 100000
6+expect eof
tests/python3/printing.expnew file+16
@@ -0,0 +1,16 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -i -q
5+match_max 100000
6+expect -exact "--> "
7+send -- "print('hello!')\r"
8+expect -exact "'hello!')\r
9+hello!\r
10+--> "
11+send -- "print(1+1)\r"
12+expect -exact "print(1+1)\r
13+2\r
14+--> "
15+send -- ""
16+expect eof
tests/python3/run_code.expnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -c print('hello')
5+match_max 100000
6+expect eof
tests/python3/set_ps1.expnew file+12
@@ -0,0 +1,12 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -i -q -ps1 custom
5+match_max 100000
6+expect -exact "custom"
7+send -- "print('hit')\r"
8+expect -exact "print('hit')\r
9+hit\r
10+custom"
11+send -- ""
12+expect eof
tests/python3/set_ps2.expnew file+17
@@ -0,0 +1,17 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -i -q -ps2 custom
5+match_max 100000
6+expect -exact "--> "
7+send -- "while False:\r"
8+expect -exact "while False:\r
9+custom"
10+send -- " pass\r"
11+expect -exact " pass\r
12+custom"
13+send -- "\r"
14+expect -exact "\r
15+--> "
16+send -- ""
17+expect eof
tests/python3/show_header.expnew file+14
@@ -0,0 +1,14 @@
1+#!/usr/bin/expect -f
2+
3+set timeout -1
4+spawn ./prybar-python3 -i
5+match_max 100000
6+expect -exact "Python 3.6.6 (default, Sep 12 2018, 18:26:19) \r
7+\[GCC 8.0.1 20180414 (experimental) \[trunk revision 259383\]\] on linux\r
8+--> "
9+send -- "1+1\r"
10+expect -exact "1+1\r
11+2\r
12+--> "
13+send -- ""
14+expect eof
tests/python3/stderr_red.expnew file+51
@@ -0,0 +1,51 @@
1+#!/usr/bin/expect -f
2+
3+# red is currently nondeterministic
4+exit 0
5+
6+spawn ./prybar-python3 -i -q -R
7+match_max 100000
8+expect -exact "--> "
9+send -- "import sys\r"
10+expect -exact "import sys\r
11+--> "
12+send -- "sys.stderr.write()\[D"
13+expect -exact ""
14+send -- "'"
15+expect -exact "')"
16+send -- "'"
17+expect -exact "')"
18+send -- "\[D"
19+expect -exact ""
20+send -- "w"
21+expect -exact "w')"
22+send -- "e"
23+expect -exact "e')"
24+send -- "e"
25+expect -exact "e')"
26+send -- "e"
27+expect -exact "e')"
28+send -- "e"
29+expect -exact "e')"
30+send -- "e"
31+expect -exact "e')"
32+send -- "e"
33+expect -exact "e')"
34+send -- "e"
35+expect -exact "e')"
36+send -- "e"
37+expect -exact "e')"
38+send -- "e"
39+expect -exact "e')"
40+send -- "e"
41+expect -exact "e')"
42+send -- "e"
43+expect -exact "e')"
44+send -- "e"
45+expect -exact "e')"
46+send -- "\\"
47+expect -exact "\\')"
48+send -- "n"
49+expect -exact "n')"
50+send -- "\r"
51+expect eof