Spaces:
Sleeping
Sleeping
Update src/eval_go.py
Browse files- src/eval_go.py +24 -15
src/eval_go.py
CHANGED
@@ -2,6 +2,8 @@ import argparse
|
|
2 |
from sys import exit
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
|
|
|
|
5 |
from .generic_eval import main as gmain
|
6 |
|
7 |
|
@@ -10,24 +12,31 @@ def eval_script(path: Path):
|
|
10 |
stdout = None
|
11 |
stderr = None
|
12 |
exit_code = None
|
13 |
-
print(f'path:{path}')
|
14 |
try:
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
except subprocess.TimeoutExpired:
|
32 |
status = "Timeout"
|
33 |
|
|
|
2 |
from sys import exit
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
5 |
+
import os
|
6 |
+
import tempfile
|
7 |
from .generic_eval import main as gmain
|
8 |
|
9 |
|
|
|
12 |
stdout = None
|
13 |
stderr = None
|
14 |
exit_code = None
|
|
|
15 |
try:
|
16 |
+
# 创建临时目录用于Go缓存
|
17 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
18 |
+
# 设置Go环境变量
|
19 |
+
env = os.environ.copy()
|
20 |
+
env["GOCACHE"] = os.path.join(temp_dir, "go-build")
|
21 |
+
env["GOPATH"] = os.path.join(temp_dir, "gopath")
|
22 |
+
|
23 |
+
build = subprocess.run(["go", "test", path],
|
24 |
+
env=env,
|
25 |
+
timeout=30,
|
26 |
+
stdout=subprocess.PIPE,
|
27 |
+
stderr=subprocess.PIPE)
|
28 |
|
29 |
+
stdout = build.stdout.decode("utf-8", errors="ignore")
|
30 |
+
stderr = build.stderr.decode("utf-8", errors="ignore")
|
31 |
+
exit_code = build.returncode
|
32 |
+
# write to stderr just so that we can redirect stdout to a csv
|
33 |
|
34 |
+
if "[setup failed]" in stdout or "[build failed]" in stdout:
|
35 |
+
status = "SyntaxError"
|
36 |
+
elif "FAIL" in stdout:
|
37 |
+
status = "Exception"
|
38 |
+
else:
|
39 |
+
status = "OK"
|
40 |
except subprocess.TimeoutExpired:
|
41 |
status = "Timeout"
|
42 |
|