dongsheng commited on
Commit
6d5b09d
·
verified ·
1 Parent(s): a642abc

Update src/eval_go.py

Browse files
Files changed (1) hide show
  1. 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
- build = subprocess.run(["go", "test", path],
16
- timeout=30,
17
- stdout=subprocess.PIPE,
18
- stderr=subprocess.PIPE)
 
 
 
 
 
 
 
 
19
 
20
- stdout = build.stdout.decode("utf-8", errors="ignore")
21
- stderr = build.stderr.decode("utf-8", errors="ignore")
22
- exit_code = build.returncode
23
- # write to stderr just so that we can redirect stdout to a csv
24
 
25
- if "[setup failed]" in stdout or "[build failed]" in stdout:
26
- status = "SyntaxError"
27
- elif "FAIL" in stdout:
28
- status = "Exception"
29
- else:
30
- status = "OK"
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