Muennighoff commited on
Commit
9c695f9
1 Parent(s): 78bd677
Files changed (1) hide show
  1. execute.py +29 -1
execute.py CHANGED
@@ -42,6 +42,8 @@ def check_correctness(check_program, timeout, task_id, completion_id, language):
42
  p = multiprocessing.Process(target=unsafe_execute, args=(check_program, result, timeout))
43
  elif language == "cpp":
44
  p = multiprocessing.Process(target=unsafe_execute_cpp, args=(check_program, result, timeout))
 
 
45
  elif language == "java":
46
  p = multiprocessing.Process(target=unsafe_execute_java, args=(check_program, result, timeout))
47
  elif language == "javascript":
@@ -136,6 +138,33 @@ def unsafe_execute_cpp(check_program, result, timeout):
136
  except subprocess.TimeoutExpired as e:
137
  result.append("timed out")
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  def unsafe_execute_java(check_program, result, timeout):
140
 
141
  with create_tempdir():
@@ -178,7 +207,6 @@ def unsafe_execute_js(check_program, result, timeout):
178
 
179
  # Run program.
180
  try:
181
- exec_globals = {}
182
  exec_result = subprocess.run(["node", "test.js"], timeout=timeout, capture_output=True)
183
  if exec_result.stderr.decode():
184
  err = exec_result.stderr.decode()
 
42
  p = multiprocessing.Process(target=unsafe_execute, args=(check_program, result, timeout))
43
  elif language == "cpp":
44
  p = multiprocessing.Process(target=unsafe_execute_cpp, args=(check_program, result, timeout))
45
+ elif language == "go":
46
+ p = multiprocessing.Process(target=unsafe_execute_go, args=(check_program, result, timeout))
47
  elif language == "java":
48
  p = multiprocessing.Process(target=unsafe_execute_java, args=(check_program, result, timeout))
49
  elif language == "javascript":
 
138
  except subprocess.TimeoutExpired as e:
139
  result.append("timed out")
140
 
141
+
142
+ def unsafe_execute_go(check_program, result, timeout):
143
+
144
+ with create_tempdir():
145
+ open(f"main_test.go", 'w').write(check_program)
146
+
147
+ try:
148
+ exec_result = subprocess.run(["go", "test", f"-timeout={timeout}s", "main_test.go"], timeout=timeout, capture_output=True)
149
+
150
+ if exec_result.returncode == 0:
151
+ result.append("passed")
152
+ else:
153
+ if exec_result.stderr:
154
+ try:
155
+ err = exec_result.stderr.decode()
156
+ except:
157
+ err = exec_result.stderr
158
+ else:
159
+ try:
160
+ err = exec_result.stdout.decode()
161
+ except:
162
+ err = exec_result.stdout
163
+ result.append(f"failed: {err}")
164
+ except subprocess.TimeoutExpired as e:
165
+ result.append("timed out")
166
+
167
+
168
  def unsafe_execute_java(check_program, result, timeout):
169
 
170
  with create_tempdir():
 
207
 
208
  # Run program.
209
  try:
 
210
  exec_result = subprocess.run(["node", "test.js"], timeout=timeout, capture_output=True)
211
  if exec_result.stderr.decode():
212
  err = exec_result.stderr.decode()