@@ -160,31 +160,49 @@ class IntegrationTests(TestUtils):
160
160
These test the programs found in general_tests/* for proper functionality.
161
161
"""
162
162
163
- def test_count (self ):
164
- """Test the Count.c program from the first pset of CPSC 223 at Yale."""
165
-
166
- rel_dir = "general_tests/count"
163
+ def io_test (self , rel_dir , cfile , stdin ):
164
+ """Run a general I/O test.
165
+
166
+ Args:
167
+ rel_dir (str): Directory for the test
168
+ cfile (str): The .c file to compile and run
169
+ stdin (str): The file to pipe into stdin of the executable, or None
170
+ """
167
171
dir = str (pathlib .Path (__file__ ).parent .joinpath (rel_dir ))
168
172
169
173
# Remove leftover files from last test
170
174
rm = "rm -f {0}/gcc_out {0}/out {0}/shivyc_output {0}/gcc_output"
171
175
subprocess .run (rm .format (dir ), shell = True , check = True )
172
176
173
- # Compile Count.c with ShivyC
174
- compile_with_shivyc (dir + "/Count.c" )
177
+ # Compile with ShivyC
178
+ compile_with_shivyc (str ( pathlib . Path ( dir ). joinpath ( cfile )) )
175
179
self .assertEqual (error_collector .issues , [])
176
180
177
181
# Compile Count.c with gcc
178
- gcc_compile = "gcc {0}/Count.c -o gcc_out" .format (dir )
182
+ gcc_compile = "gcc {0}/{1} -o gcc_out" .format (dir , cfile )
179
183
subprocess .run (gcc_compile , shell = True , check = True )
180
184
181
185
# Run ShivyC executable on sample input
182
- shivyc_run = "./out < {0}/input.c > {0}/shivyc_output" .format (dir )
183
- subprocess .run (shivyc_run , shell = True , check = True )
186
+ if stdin :
187
+ shivyc_run = "./out < {0}/input.c > {0}/shivyc_output" .format (dir )
188
+ gcc_run = "./gcc_out < {0}/input.c > {0}/gcc_output" .format (dir )
189
+ else :
190
+ shivyc_run = "./out > {0}/shivyc_output" .format (dir )
191
+ gcc_run = "./gcc_out > {0}/gcc_output" .format (dir )
184
192
185
- # Run gcc executable on sample input
186
- gcc_run = "./gcc_out < {0}/input.c > {0}/gcc_output" .format (dir )
193
+ subprocess .run (shivyc_run , shell = True , check = True )
187
194
subprocess .run (gcc_run , shell = True , check = True )
188
195
196
+ # Diff the two output files
189
197
diff = "diff {0}/gcc_output {0}/shivyc_output" .format (dir )
190
198
subprocess .run (diff , shell = True , check = True )
199
+
200
+ def test_count (self ):
201
+ """Test the Count.c program from the first pset of CPSC 223 at Yale."""
202
+
203
+ self .io_test ("general_tests/count" , "Count.c" , "input.c" )
204
+
205
+ def test_pi (self ):
206
+ """Test the pi.c program."""
207
+
208
+ self .io_test ("general_tests/pi" , "pi.c" , None )
0 commit comments