Skip to content

Commit 67ff6ff

Browse files
committed
test: add fixtures
1 parent bf2bb5b commit 67ff6ff

File tree

4 files changed

+614
-2
lines changed

4 files changed

+614
-2
lines changed

internal/test_helpers/fixtures/pass_functions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ Debug = true
635635
[stage-1] [test-2] [test.lox] return isEven(n - 1);
636636
[stage-1] [test-2] [test.lox] }
637637
[stage-1] [test-2] [test.lox]
638-
[stage-1] [test-2] [test.lox] print isEven(93);
638+
[stage-1] [test-2] [test.lox] print isEven(75);
639639
[stage-1] [test-2] [test.lox] }
640640
[stage-1] [test-2] $ ./your_program.sh run test.lox
641641
[your_program] false

internal/test_helpers/fixtures/pass_functions_final

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ Debug = true
635635
[stage-1] [test-2] [test.lox] return isEven(n - 1);
636636
[stage-1] [test-2] [test.lox] }
637637
[stage-1] [test-2] [test.lox]
638-
[stage-1] [test-2] [test.lox] print isEven(93);
638+
[stage-1] [test-2] [test.lox] print isEven(75);
639639
[stage-1] [test-2] [test.lox] }
640640
[stage-1] [test-2] $ ./your_program.sh run test.lox
641641
[your_program] false
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
Debug = true
2+
3+
[stage-7] Running tests for Stage #7: r1
4+
[stage-7] [test-1] Running test case: 1
5+
[stage-7] [test-1] Writing contents to ./test.lox:
6+
[stage-7] [test-1] [test.lox] var a = "outer";
7+
[stage-7] [test-1] [test.lox] {
8+
[stage-7] [test-1] [test.lox] fun foo() {
9+
[stage-7] [test-1] [test.lox] print a;
10+
[stage-7] [test-1] [test.lox] }
11+
[stage-7] [test-1] [test.lox]
12+
[stage-7] [test-1] [test.lox] foo(); // expect: outer
13+
[stage-7] [test-1] [test.lox] var a = "inner";
14+
[stage-7] [test-1] [test.lox] foo(); // expect: outer
15+
[stage-7] [test-1] [test.lox] }
16+
[stage-7] [test-1] $ ./your_program.sh run test.lox
17+
[your_program] outer
18+
[your_program] outer
19+
[stage-7] [test-1] ✓ 2 line(s) match on stdout
20+
[stage-7] [test-1] ✓ Received exit code 0.
21+
[stage-7] [test-2] Running test case: 2
22+
[stage-7] [test-2] Writing contents to ./test.lox:
23+
[stage-7] [test-2] [test.lox] fun global() {
24+
[stage-7] [test-2] [test.lox] print "global";
25+
[stage-7] [test-2] [test.lox] }
26+
[stage-7] [test-2] [test.lox]
27+
[stage-7] [test-2] [test.lox] {
28+
[stage-7] [test-2] [test.lox] fun f() {
29+
[stage-7] [test-2] [test.lox] global();
30+
[stage-7] [test-2] [test.lox] }
31+
[stage-7] [test-2] [test.lox]
32+
[stage-7] [test-2] [test.lox] f();
33+
[stage-7] [test-2] [test.lox] fun global() {
34+
[stage-7] [test-2] [test.lox] print "local";
35+
[stage-7] [test-2] [test.lox] }
36+
[stage-7] [test-2] [test.lox] f();
37+
[stage-7] [test-2] [test.lox] }
38+
[stage-7] [test-2] $ ./your_program.sh run test.lox
39+
[your_program] global
40+
[your_program] global
41+
[stage-7] [test-2] ✓ 2 line(s) match on stdout
42+
[stage-7] [test-2] ✓ Received exit code 0.
43+
[stage-7] [test-3] Running test case: 3
44+
[stage-7] [test-3] Writing contents to ./test.lox:
45+
[stage-7] [test-3] [test.lox] // Multiple Nested Functions with Shadowing
46+
[stage-7] [test-3] [test.lox] var x = "global";
47+
[stage-7] [test-3] [test.lox]
48+
[stage-7] [test-3] [test.lox] fun outer() {
49+
[stage-7] [test-3] [test.lox] var x = "outer";
50+
[stage-7] [test-3] [test.lox]
51+
[stage-7] [test-3] [test.lox] fun middle() {
52+
[stage-7] [test-3] [test.lox] fun inner() {
53+
[stage-7] [test-3] [test.lox] print x; // Should capture "outer", not "global" or "inner"
54+
[stage-7] [test-3] [test.lox] }
55+
[stage-7] [test-3] [test.lox]
56+
[stage-7] [test-3] [test.lox] inner();
57+
[stage-7] [test-3] [test.lox] var x = "middle";
58+
[stage-7] [test-3] [test.lox] inner(); // Should still print "outer"
59+
[stage-7] [test-3] [test.lox] }
60+
[stage-7] [test-3] [test.lox]
61+
[stage-7] [test-3] [test.lox] middle();
62+
[stage-7] [test-3] [test.lox] }
63+
[stage-7] [test-3] [test.lox]
64+
[stage-7] [test-3] [test.lox] outer();
65+
[stage-7] [test-3] $ ./your_program.sh run test.lox
66+
[your_program] outer
67+
[your_program] outer
68+
[stage-7] [test-3] ✓ 2 line(s) match on stdout
69+
[stage-7] [test-3] ✓ Received exit code 0.
70+
[stage-7] [test-4] Running test case: 4
71+
[stage-7] [test-4] Writing contents to ./test.lox:
72+
[stage-7] [test-4] [test.lox] // Function Returning a Function
73+
[stage-7] [test-4] [test.lox] var count = 0;
74+
[stage-7] [test-4] [test.lox]
75+
[stage-7] [test-4] [test.lox] {
76+
[stage-7] [test-4] [test.lox] fun makeCounter() {
77+
[stage-7] [test-4] [test.lox] fun counter() {
78+
[stage-7] [test-4] [test.lox] count = count + 1;
79+
[stage-7] [test-4] [test.lox] print count;
80+
[stage-7] [test-4] [test.lox] }
81+
[stage-7] [test-4] [test.lox] return counter;
82+
[stage-7] [test-4] [test.lox] }
83+
[stage-7] [test-4] [test.lox]
84+
[stage-7] [test-4] [test.lox] var counter1 = makeCounter();
85+
[stage-7] [test-4] [test.lox] counter1(); // Should print 1
86+
[stage-7] [test-4] [test.lox] counter1(); // Should print 2
87+
[stage-7] [test-4] [test.lox]
88+
[stage-7] [test-4] [test.lox] var count = 0;
89+
[stage-7] [test-4] [test.lox] counter1(); // Should print 3
90+
[stage-7] [test-4] [test.lox] }
91+
[stage-7] [test-4] $ ./your_program.sh run test.lox
92+
[your_program] 1
93+
[your_program] 2
94+
[your_program] 3
95+
[stage-7] [test-4] ✓ 3 line(s) match on stdout
96+
[stage-7] [test-4] ✓ Received exit code 0.
97+
[stage-7] Test passed.
98+
99+
[stage-6] Running tests for Stage #6: r2
100+
[stage-6] [test-1] Running test case: 1
101+
[stage-6] [test-1] Writing contents to ./test.lox:
102+
[stage-6] [test-1] [test.lox]
103+
[stage-6] [test-1] $ ./your_program.sh run test.lox
104+
[stage-6] [test-1] ✓ 1 line(s) match on stdout
105+
[stage-6] [test-1] ✓ Received exit code 0.
106+
[stage-6] [test-2] Running test case: 2
107+
[stage-6] [test-2] Writing contents to ./test.lox:
108+
[stage-6] [test-2] [test.lox]
109+
[stage-6] [test-2] $ ./your_program.sh run test.lox
110+
[stage-6] [test-2] ✓ 1 line(s) match on stdout
111+
[stage-6] [test-2] ✓ Received exit code 0.
112+
[stage-6] [test-3] Running test case: 3
113+
[stage-6] [test-3] Writing contents to ./test.lox:
114+
[stage-6] [test-3] [test.lox]
115+
[stage-6] [test-3] $ ./your_program.sh run test.lox
116+
[stage-6] [test-3] ✓ 1 line(s) match on stdout
117+
[stage-6] [test-3] ✓ Received exit code 0.
118+
[stage-6] [test-4] Running test case: 4
119+
[stage-6] [test-4] Writing contents to ./test.lox:
120+
[stage-6] [test-4] [test.lox]
121+
[stage-6] [test-4] $ ./your_program.sh run test.lox
122+
[stage-6] [test-4] ✓ 1 line(s) match on stdout
123+
[stage-6] [test-4] ✓ Received exit code 0.
124+
[stage-6] Test passed.
125+
126+
[stage-5] Running tests for Stage #5: r3
127+
[stage-5] [test-1] Running test case: 1
128+
[stage-5] [test-1] Writing contents to ./test.lox:
129+
[stage-5] [test-1] [test.lox]
130+
[stage-5] [test-1] $ ./your_program.sh run test.lox
131+
[stage-5] [test-1] ✓ 1 line(s) match on stdout
132+
[stage-5] [test-1] ✓ Received exit code 0.
133+
[stage-5] [test-2] Running test case: 2
134+
[stage-5] [test-2] Writing contents to ./test.lox:
135+
[stage-5] [test-2] [test.lox]
136+
[stage-5] [test-2] $ ./your_program.sh run test.lox
137+
[stage-5] [test-2] ✓ 1 line(s) match on stdout
138+
[stage-5] [test-2] ✓ Received exit code 0.
139+
[stage-5] [test-3] Running test case: 3
140+
[stage-5] [test-3] Writing contents to ./test.lox:
141+
[stage-5] [test-3] [test.lox]
142+
[stage-5] [test-3] $ ./your_program.sh run test.lox
143+
[stage-5] [test-3] ✓ 1 line(s) match on stdout
144+
[stage-5] [test-3] ✓ Received exit code 0.
145+
[stage-5] [test-4] Running test case: 4
146+
[stage-5] [test-4] Writing contents to ./test.lox:
147+
[stage-5] [test-4] [test.lox]
148+
[stage-5] [test-4] $ ./your_program.sh run test.lox
149+
[stage-5] [test-4] ✓ 1 line(s) match on stdout
150+
[stage-5] [test-4] ✓ Received exit code 0.
151+
[stage-5] Test passed.
152+
153+
[stage-4] Running tests for Stage #4: r4
154+
[stage-4] [test-1] Running test case: 1
155+
[stage-4] [test-1] Writing contents to ./test.lox:
156+
[stage-4] [test-1] [test.lox] var a = "value";
157+
[stage-4] [test-1] [test.lox] var a = a; // global scope, so this is allowed
158+
[stage-4] [test-1] [test.lox] print a; // expect: value
159+
[stage-4] [test-1] [test.lox]
160+
[stage-4] [test-1] $ ./your_program.sh run test.lox
161+
[your_program] value
162+
[stage-4] [test-1] ✓ 1 line(s) match on stdout
163+
[stage-4] [test-1] ✓ Received exit code 0.
164+
[stage-4] [test-2] Running test case: 2
165+
[stage-4] [test-2] Writing contents to ./test.lox:
166+
[stage-4] [test-2] [test.lox] var a = "outer";
167+
[stage-4] [test-2] [test.lox] {
168+
[stage-4] [test-2] [test.lox] var a = a; // Error at 'a': Can't read local variable in its own initializer.
169+
[stage-4] [test-2] [test.lox] }
170+
[stage-4] [test-2] $ ./your_program.sh run test.lox
171+
[your_program] [line 3] Error at 'a': Can't read local variable in its own initializer.
172+
[stage-4] [test-2] ✓ 1 line(s) match on stdout
173+
[stage-4] [test-2] ✓ Received exit code 65.
174+
[stage-4] [test-3] Running test case: 3
175+
[stage-4] [test-3] Writing contents to ./test.lox:
176+
[stage-4] [test-3] [test.lox]
177+
[stage-4] [test-3] $ ./your_program.sh run test.lox
178+
[stage-4] [test-3] ✓ 1 line(s) match on stdout
179+
[stage-4] [test-3] ✓ Received exit code 0.
180+
[stage-4] [test-4] Running test case: 4
181+
[stage-4] [test-4] Writing contents to ./test.lox:
182+
[stage-4] [test-4] [test.lox]
183+
[stage-4] [test-4] $ ./your_program.sh run test.lox
184+
[stage-4] [test-4] ✓ 1 line(s) match on stdout
185+
[stage-4] [test-4] ✓ Received exit code 0.
186+
[stage-4] Test passed.
187+
188+
[stage-3] Running tests for Stage #3: r5
189+
[stage-3] [test-1] Running test case: 1
190+
[stage-3] [test-1] Writing contents to ./test.lox:
191+
[stage-3] [test-1] [test.lox] return "foo";
192+
[stage-3] [test-1] $ ./your_program.sh run test.lox
193+
[your_program] [line 1] Error at 'return': Can't return from top-level code.
194+
[stage-3] [test-1] ✓ 1 line(s) match on stdout
195+
[stage-3] [test-1] ✓ Received exit code 65.
196+
[stage-3] [test-2] Running test case: 2
197+
[stage-3] [test-2] Writing contents to ./test.lox:
198+
[stage-3] [test-2] [test.lox]
199+
[stage-3] [test-2] $ ./your_program.sh run test.lox
200+
[stage-3] [test-2] ✓ 1 line(s) match on stdout
201+
[stage-3] [test-2] ✓ Received exit code 0.
202+
[stage-3] [test-3] Running test case: 3
203+
[stage-3] [test-3] Writing contents to ./test.lox:
204+
[stage-3] [test-3] [test.lox]
205+
[stage-3] [test-3] $ ./your_program.sh run test.lox
206+
[stage-3] [test-3] ✓ 1 line(s) match on stdout
207+
[stage-3] [test-3] ✓ Received exit code 0.
208+
[stage-3] [test-4] Running test case: 4
209+
[stage-3] [test-4] Writing contents to ./test.lox:
210+
[stage-3] [test-4] [test.lox]
211+
[stage-3] [test-4] $ ./your_program.sh run test.lox
212+
[stage-3] [test-4] ✓ 1 line(s) match on stdout
213+
[stage-3] [test-4] ✓ Received exit code 0.
214+
[stage-3] Test passed.
215+
216+
[stage-2] Running tests for Stage #2: r6
217+
[stage-2] [test-1] Running test case: 1
218+
[stage-2] [test-1] Writing contents to ./test.lox:
219+
[stage-2] [test-1] [test.lox] if (false) {
220+
[stage-2] [test-1] [test.lox] print notDefined;
221+
[stage-2] [test-1] [test.lox] }
222+
[stage-2] [test-1] [test.lox]
223+
[stage-2] [test-1] [test.lox] print "ok"; // expect: ok
224+
[stage-2] [test-1] [test.lox]
225+
[stage-2] [test-1] $ ./your_program.sh run test.lox
226+
[your_program] ok
227+
[stage-2] [test-1] ✓ 1 line(s) match on stdout
228+
[stage-2] [test-1] ✓ Received exit code 0.
229+
[stage-2] [test-2] Running test case: 2
230+
[stage-2] [test-2] Writing contents to ./test.lox:
231+
[stage-2] [test-2] [test.lox] print a; // expect: compile error
232+
[stage-2] [test-2] [test.lox] var a = "value";
233+
[stage-2] [test-2] [test.lox] print a; // expect: value
234+
[stage-2] [test-2] [test.lox]
235+
[stage-2] [test-2] $ ./your_program.sh run test.lox
236+
[your_program] Undefined variable 'a'.
237+
[your_program] [line 1]
238+
[stage-2] [test-2] ✓ 1 line(s) match on stdout
239+
[stage-2] [test-2] ✓ Received exit code 70.
240+
[stage-2] [test-3] Running test case: 3
241+
[stage-2] [test-3] Writing contents to ./test.lox:
242+
[stage-2] [test-3] [test.lox]
243+
[stage-2] [test-3] $ ./your_program.sh run test.lox
244+
[stage-2] [test-3] ✓ 1 line(s) match on stdout
245+
[stage-2] [test-3] ✓ Received exit code 0.
246+
[stage-2] [test-4] Running test case: 4
247+
[stage-2] [test-4] Writing contents to ./test.lox:
248+
[stage-2] [test-4] [test.lox]
249+
[stage-2] [test-4] $ ./your_program.sh run test.lox
250+
[stage-2] [test-4] ✓ 1 line(s) match on stdout
251+
[stage-2] [test-4] ✓ Received exit code 0.
252+
[stage-2] Test passed.
253+
254+
[stage-1] Running tests for Stage #1: r7
255+
[stage-1] [test-1] Running test case: 1
256+
[stage-1] [test-1] Writing contents to ./test.lox:
257+
[stage-1] [test-1] [test.lox] {
258+
[stage-1] [test-1] [test.lox] var a = "value";
259+
[stage-1] [test-1] [test.lox] var a = "other"; // Error at 'a': Already a variable with this name in this scope.
260+
[stage-1] [test-1] [test.lox] }
261+
[stage-1] [test-1] [test.lox]
262+
[stage-1] [test-1] $ ./your_program.sh run test.lox
263+
[your_program] [line 3] Error at 'a': Already a variable with this name in this scope.
264+
[stage-1] [test-1] ✓ 1 line(s) match on stdout
265+
[stage-1] [test-1] ✓ Received exit code 65.
266+
[stage-1] [test-2] Running test case: 2
267+
[stage-1] [test-2] Writing contents to ./test.lox:
268+
[stage-1] [test-2] [test.lox] fun foo(a) {
269+
[stage-1] [test-2] [test.lox] var a; // Error at 'a': Already a variable with this name in this scope.
270+
[stage-1] [test-2] [test.lox] }
271+
[stage-1] [test-2] [test.lox]
272+
[stage-1] [test-2] $ ./your_program.sh run test.lox
273+
[your_program] [line 2] Error at 'a': Already a variable with this name in this scope.
274+
[stage-1] [test-2] ✓ 1 line(s) match on stdout
275+
[stage-1] [test-2] ✓ Received exit code 65.
276+
[stage-1] [test-3] Running test case: 3
277+
[stage-1] [test-3] Writing contents to ./test.lox:
278+
[stage-1] [test-3] [test.lox] fun foo(arg,
279+
[stage-1] [test-3] [test.lox] arg) { // Error at 'arg': Already a variable with this name in this scope.
280+
[stage-1] [test-3] [test.lox] "body";
281+
[stage-1] [test-3] [test.lox] }
282+
[stage-1] [test-3] [test.lox]
283+
[stage-1] [test-3] $ ./your_program.sh run test.lox
284+
[your_program] [line 2] Error at 'arg': Already a variable with this name in this scope.
285+
[stage-1] [test-3] ✓ 1 line(s) match on stdout
286+
[stage-1] [test-3] ✓ Received exit code 65.
287+
[stage-1] [test-4] Running test case: 4
288+
[stage-1] [test-4] Writing contents to ./test.lox:
289+
[stage-1] [test-4] [test.lox] var a = "1";
290+
[stage-1] [test-4] [test.lox] print a; // expect: 1
291+
[stage-1] [test-4] [test.lox] var a;
292+
[stage-1] [test-4] [test.lox] print a; // expect: nil
293+
[stage-1] [test-4] [test.lox]
294+
[stage-1] [test-4] [test.lox] var a = "2";
295+
[stage-1] [test-4] [test.lox] print a; // expect: 2
296+
[stage-1] [test-4] [test.lox]
297+
[stage-1] [test-4] [test.lox] {
298+
[stage-1] [test-4] [test.lox] var a = "1";
299+
[stage-1] [test-4] [test.lox] var a = "2";
300+
[stage-1] [test-4] [test.lox] print a; // expect: compile error
301+
[stage-1] [test-4] [test.lox] }
302+
[stage-1] [test-4] $ ./your_program.sh run test.lox
303+
[your_program] [line 11] Error at 'a': Already a variable with this name in this scope.
304+
[stage-1] [test-4] ✓ 1 line(s) match on stdout
305+
[stage-1] [test-4] ✓ Received exit code 65.
306+
[stage-1] Test passed.

0 commit comments

Comments
 (0)