xref: /unit/test/unit/check/go.py (revision 2004:ca4c5855f139)
1import os
2import subprocess
3
4
5def check_go(current_dir, temp_dir, test_dir):
6    if not os.path.exists(temp_dir + '/go'):
7        os.mkdir(temp_dir + '/go')
8
9    env = os.environ.copy()
10    env['GOPATH'] = current_dir + '/build/go'
11    env['GO111MODULE'] = 'auto'
12
13    try:
14        process = subprocess.run(
15            [
16                'go',
17                'build',
18                '-o',
19                temp_dir + '/go/app',
20                test_dir + '/go/empty/app.go',
21            ],
22            env=env,
23            stderr=subprocess.STDOUT,
24            stdout=subprocess.PIPE,
25        )
26
27        if process.returncode == 0:
28            return True
29
30    except KeyboardInterrupt:
31        raise
32
33    except subprocess.CalledProcessError:
34        return None
35