2017-02-28 02:12:13 +08:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package python
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
var buildDir string
|
|
|
|
|
2017-07-13 03:55:28 +08:00
|
|
|
type pyModule struct {
|
2017-12-19 05:20:23 +08:00
|
|
|
name string
|
|
|
|
actualVersion string
|
|
|
|
pyRunfiles []string
|
|
|
|
srcsZip string
|
|
|
|
depsSrcsZips []string
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
buildNamePrefix = "soong_python_test"
|
|
|
|
moduleVariantErrTemplate = "%s: module %q variant %q: "
|
|
|
|
pkgPathErrTemplate = moduleVariantErrTemplate +
|
2017-07-13 03:55:28 +08:00
|
|
|
"pkg_path: %q must be a relative path contained in par file."
|
2017-02-28 02:12:13 +08:00
|
|
|
badIdentifierErrTemplate = moduleVariantErrTemplate +
|
2020-11-17 07:42:51 +08:00
|
|
|
"srcs: the path %q contains invalid subpath %q."
|
2017-02-28 02:12:13 +08:00
|
|
|
dupRunfileErrTemplate = moduleVariantErrTemplate +
|
2018-06-01 03:49:33 +08:00
|
|
|
"found two files to be placed at the same location within zip %q." +
|
2017-02-28 02:12:13 +08:00
|
|
|
" First file: in module %s at path %q." +
|
|
|
|
" Second file: in module %s at path %q."
|
|
|
|
noSrcFileErr = moduleVariantErrTemplate + "doesn't have any source files!"
|
2017-12-23 08:12:00 +08:00
|
|
|
badSrcFileExtErr = moduleVariantErrTemplate + "srcs: found non (.py|.proto) file: %q!"
|
|
|
|
badDataFileExtErr = moduleVariantErrTemplate + "data: found (.py|.proto) file: %q!"
|
2019-12-14 12:41:13 +08:00
|
|
|
bpFile = "Android.bp"
|
2017-02-28 02:12:13 +08:00
|
|
|
|
|
|
|
data = []struct {
|
|
|
|
desc string
|
|
|
|
mockFiles map[string][]byte
|
|
|
|
|
|
|
|
errors []string
|
2017-07-13 03:55:28 +08:00
|
|
|
expectedBinaries []pyModule
|
2017-02-28 02:12:13 +08:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "module without any src files",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
}`,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
errors: []string{
|
|
|
|
fmt.Sprintf(noSrcFileErr,
|
2019-12-14 12:41:13 +08:00
|
|
|
"dir/Android.bp:1:1", "lib1", "PY3"),
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module with bad src file ext",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
srcs: [
|
|
|
|
"file1.exe",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
),
|
|
|
|
"dir/file1.exe": nil,
|
|
|
|
},
|
|
|
|
errors: []string{
|
|
|
|
fmt.Sprintf(badSrcFileExtErr,
|
2019-12-14 12:41:13 +08:00
|
|
|
"dir/Android.bp:3:11", "lib1", "PY3", "dir/file1.exe"),
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module with bad data file ext",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
data: [
|
|
|
|
"file2.py",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
),
|
|
|
|
"dir/file1.py": nil,
|
|
|
|
"dir/file2.py": nil,
|
|
|
|
},
|
|
|
|
errors: []string{
|
|
|
|
fmt.Sprintf(badDataFileExtErr,
|
2019-12-14 12:41:13 +08:00
|
|
|
"dir/Android.bp:6:11", "lib1", "PY3", "dir/file2.py"),
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module with bad pkg_path format",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
pkg_path: "a/c/../../",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
python_library_host {
|
|
|
|
name: "lib2",
|
|
|
|
pkg_path: "a/c/../../../",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
python_library_host {
|
|
|
|
name: "lib3",
|
|
|
|
pkg_path: "/a/c/../../",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
),
|
|
|
|
"dir/file1.py": nil,
|
|
|
|
},
|
|
|
|
errors: []string{
|
|
|
|
fmt.Sprintf(pkgPathErrTemplate,
|
2019-12-14 12:41:13 +08:00
|
|
|
"dir/Android.bp:11:15", "lib2", "PY3", "a/c/../../../"),
|
2017-02-28 02:12:13 +08:00
|
|
|
fmt.Sprintf(pkgPathErrTemplate,
|
2019-12-14 12:41:13 +08:00
|
|
|
"dir/Android.bp:19:15", "lib3", "PY3", "/a/c/../../"),
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module with bad runfile src path format",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
pkg_path: "a/b/c/",
|
|
|
|
srcs: [
|
|
|
|
".file1.py",
|
|
|
|
"123/file1.py",
|
|
|
|
"-e/f/file1.py",
|
|
|
|
],
|
|
|
|
}`,
|
|
|
|
),
|
|
|
|
"dir/.file1.py": nil,
|
|
|
|
"dir/123/file1.py": nil,
|
|
|
|
"dir/-e/f/file1.py": nil,
|
|
|
|
},
|
|
|
|
errors: []string{
|
2019-12-14 12:41:13 +08:00
|
|
|
fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
|
2018-06-01 03:49:33 +08:00
|
|
|
"lib1", "PY3", "a/b/c/-e/f/file1.py", "-e"),
|
2019-12-14 12:41:13 +08:00
|
|
|
fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
|
2018-06-01 03:49:33 +08:00
|
|
|
"lib1", "PY3", "a/b/c/.file1.py", ".file1"),
|
2019-12-14 12:41:13 +08:00
|
|
|
fmt.Sprintf(badIdentifierErrTemplate, "dir/Android.bp:4:11",
|
2018-06-01 03:49:33 +08:00
|
|
|
"lib1", "PY3", "a/b/c/123/file1.py", "123"),
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module with duplicate runfile path",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
|
|
|
`python_library_host {
|
|
|
|
name: "lib1",
|
|
|
|
pkg_path: "a/b/",
|
|
|
|
srcs: [
|
|
|
|
"c/file1.py",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
python_library_host {
|
|
|
|
name: "lib2",
|
|
|
|
pkg_path: "a/b/c/",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
"lib1",
|
|
|
|
],
|
|
|
|
}
|
2021-03-18 07:01:06 +08:00
|
|
|
|
|
|
|
python_binary_host {
|
|
|
|
name: "bin",
|
|
|
|
pkg_path: "e/",
|
|
|
|
srcs: [
|
|
|
|
"bin.py",
|
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
"lib2",
|
|
|
|
],
|
|
|
|
}
|
2017-02-28 02:12:13 +08:00
|
|
|
`,
|
|
|
|
),
|
|
|
|
"dir/c/file1.py": nil,
|
|
|
|
"dir/file1.py": nil,
|
2021-03-18 07:01:06 +08:00
|
|
|
"dir/bin.py": nil,
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
errors: []string{
|
2021-03-18 07:01:06 +08:00
|
|
|
fmt.Sprintf(dupRunfileErrTemplate, "dir/Android.bp:20:6",
|
|
|
|
"bin", "PY3", "a/b/c/file1.py", "bin", "dir/file1.py",
|
2017-02-28 02:12:13 +08:00
|
|
|
"lib1", "dir/c/file1.py"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "module for testing dependencies",
|
|
|
|
mockFiles: map[string][]byte{
|
|
|
|
bpFile: []byte(`subdirs = ["dir"]`),
|
|
|
|
filepath.Join("dir", bpFile): []byte(
|
2017-07-21 08:43:37 +08:00
|
|
|
`python_defaults {
|
|
|
|
name: "default_lib",
|
|
|
|
srcs: [
|
|
|
|
"default.py",
|
|
|
|
],
|
|
|
|
version: {
|
|
|
|
py2: {
|
|
|
|
enabled: true,
|
|
|
|
srcs: [
|
|
|
|
"default_py2.py",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
py3: {
|
|
|
|
enabled: false,
|
|
|
|
srcs: [
|
|
|
|
"default_py3.py",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
python_library_host {
|
2017-02-28 02:12:13 +08:00
|
|
|
name: "lib5",
|
|
|
|
pkg_path: "a/b/",
|
|
|
|
srcs: [
|
|
|
|
"file1.py",
|
|
|
|
],
|
|
|
|
version: {
|
|
|
|
py2: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
py3: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
python_library_host {
|
|
|
|
name: "lib6",
|
|
|
|
pkg_path: "c/d/",
|
|
|
|
srcs: [
|
|
|
|
"file2.py",
|
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
"lib5",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
python_binary_host {
|
|
|
|
name: "bin",
|
2017-07-21 08:43:37 +08:00
|
|
|
defaults: ["default_lib"],
|
2017-02-28 02:12:13 +08:00
|
|
|
pkg_path: "e/",
|
|
|
|
srcs: [
|
|
|
|
"bin.py",
|
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
"lib5",
|
|
|
|
],
|
|
|
|
version: {
|
|
|
|
py3: {
|
|
|
|
enabled: true,
|
|
|
|
srcs: [
|
|
|
|
"file4.py",
|
|
|
|
],
|
|
|
|
libs: [
|
|
|
|
"lib6",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}`,
|
|
|
|
),
|
2017-07-21 08:43:37 +08:00
|
|
|
filepath.Join("dir", "default.py"): nil,
|
|
|
|
filepath.Join("dir", "default_py2.py"): nil,
|
|
|
|
filepath.Join("dir", "default_py3.py"): nil,
|
|
|
|
filepath.Join("dir", "file1.py"): nil,
|
|
|
|
filepath.Join("dir", "file2.py"): nil,
|
|
|
|
filepath.Join("dir", "bin.py"): nil,
|
|
|
|
filepath.Join("dir", "file4.py"): nil,
|
2020-06-13 07:38:45 +08:00
|
|
|
StubTemplateHost: []byte(`PYTHON_BINARY = '%interpreter%'
|
2017-02-28 02:12:13 +08:00
|
|
|
MAIN_FILE = '%main%'`),
|
|
|
|
},
|
2017-07-13 03:55:28 +08:00
|
|
|
expectedBinaries: []pyModule{
|
2017-02-28 02:12:13 +08:00
|
|
|
{
|
|
|
|
name: "bin",
|
|
|
|
actualVersion: "PY3",
|
|
|
|
pyRunfiles: []string{
|
2018-06-01 03:49:33 +08:00
|
|
|
"e/default.py",
|
|
|
|
"e/bin.py",
|
|
|
|
"e/default_py3.py",
|
|
|
|
"e/file4.py",
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
2017-12-23 08:12:00 +08:00
|
|
|
srcsZip: "@prefix@/.intermediates/dir/bin/PY3/bin.py.srcszip",
|
2017-12-19 05:20:23 +08:00
|
|
|
depsSrcsZips: []string{
|
2017-12-23 08:12:00 +08:00
|
|
|
"@prefix@/.intermediates/dir/lib5/PY3/lib5.py.srcszip",
|
|
|
|
"@prefix@/.intermediates/dir/lib6/PY3/lib6.py.srcszip",
|
2017-02-28 02:12:13 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPythonModule(t *testing.T) {
|
|
|
|
for _, d := range data {
|
|
|
|
t.Run(d.desc, func(t *testing.T) {
|
2019-12-14 12:41:13 +08:00
|
|
|
config := android.TestConfig(buildDir, nil, "", d.mockFiles)
|
2020-10-30 08:09:13 +08:00
|
|
|
ctx := android.NewTestContext(config)
|
2020-06-13 07:38:45 +08:00
|
|
|
ctx.PreDepsMutators(RegisterPythonPreDepsMutators)
|
2019-11-23 07:25:03 +08:00
|
|
|
ctx.RegisterModuleType("python_library_host", PythonLibraryHostFactory)
|
|
|
|
ctx.RegisterModuleType("python_binary_host", PythonBinaryHostFactory)
|
|
|
|
ctx.RegisterModuleType("python_defaults", defaultsFactory)
|
2017-07-21 08:43:37 +08:00
|
|
|
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
|
2020-10-30 08:09:13 +08:00
|
|
|
ctx.Register()
|
2017-02-28 02:12:13 +08:00
|
|
|
_, testErrs := ctx.ParseBlueprintsFiles(bpFile)
|
2018-03-12 16:29:17 +08:00
|
|
|
android.FailIfErrored(t, testErrs)
|
2017-02-28 02:12:13 +08:00
|
|
|
_, actErrs := ctx.PrepareBuildActions(config)
|
2021-03-18 07:01:06 +08:00
|
|
|
if len(actErrs) > 0 || len(d.errors) > 0 {
|
2017-02-28 02:12:13 +08:00
|
|
|
testErrs = append(testErrs, expectErrors(t, actErrs, d.errors)...)
|
|
|
|
} else {
|
|
|
|
for _, e := range d.expectedBinaries {
|
|
|
|
testErrs = append(testErrs,
|
|
|
|
expectModule(t, ctx, buildDir, e.name,
|
|
|
|
e.actualVersion,
|
2017-12-19 05:20:23 +08:00
|
|
|
e.srcsZip,
|
|
|
|
e.pyRunfiles,
|
|
|
|
e.depsSrcsZips)...)
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-12 16:29:17 +08:00
|
|
|
android.FailIfErrored(t, testErrs)
|
2017-02-28 02:12:13 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func expectErrors(t *testing.T, actErrs []error, expErrs []string) (testErrs []error) {
|
|
|
|
actErrStrs := []string{}
|
|
|
|
for _, v := range actErrs {
|
|
|
|
actErrStrs = append(actErrStrs, v.Error())
|
|
|
|
}
|
|
|
|
sort.Strings(actErrStrs)
|
|
|
|
if len(actErrStrs) != len(expErrs) {
|
|
|
|
t.Errorf("got (%d) errors, expected (%d) errors!", len(actErrStrs), len(expErrs))
|
|
|
|
for _, v := range actErrStrs {
|
|
|
|
testErrs = append(testErrs, errors.New(v))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sort.Strings(expErrs)
|
|
|
|
for i, v := range actErrStrs {
|
2020-11-17 07:42:51 +08:00
|
|
|
if !strings.Contains(v, expErrs[i]) {
|
2017-02-28 02:12:13 +08:00
|
|
|
testErrs = append(testErrs, errors.New(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:20:23 +08:00
|
|
|
func expectModule(t *testing.T, ctx *android.TestContext, buildDir, name, variant, expectedSrcsZip string,
|
|
|
|
expectedPyRunfiles, expectedDepsSrcsZips []string) (testErrs []error) {
|
2017-07-14 05:43:27 +08:00
|
|
|
module := ctx.ModuleForTests(name, variant)
|
2017-02-28 02:12:13 +08:00
|
|
|
|
2017-07-13 03:55:28 +08:00
|
|
|
base, baseOk := module.Module().(*Module)
|
2017-02-28 02:12:13 +08:00
|
|
|
if !baseOk {
|
|
|
|
t.Fatalf("%s is not Python module!", name)
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:20:23 +08:00
|
|
|
actualPyRunfiles := []string{}
|
2017-02-28 02:12:13 +08:00
|
|
|
for _, path := range base.srcsPathMappings {
|
2017-12-19 05:20:23 +08:00
|
|
|
actualPyRunfiles = append(actualPyRunfiles, path.dest)
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:20:23 +08:00
|
|
|
if !reflect.DeepEqual(actualPyRunfiles, expectedPyRunfiles) {
|
2017-02-28 02:12:13 +08:00
|
|
|
testErrs = append(testErrs, errors.New(fmt.Sprintf(
|
2020-10-31 06:44:09 +08:00
|
|
|
`binary "%s" variant "%s" has unexpected pyRunfiles: %q! (expected: %q)`,
|
2017-02-28 02:12:13 +08:00
|
|
|
base.Name(),
|
2017-07-13 03:55:28 +08:00
|
|
|
base.properties.Actual_version,
|
2020-10-31 06:44:09 +08:00
|
|
|
actualPyRunfiles,
|
|
|
|
expectedPyRunfiles)))
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:20:23 +08:00
|
|
|
if base.srcsZip.String() != strings.Replace(expectedSrcsZip, "@prefix@", buildDir, 1) {
|
2017-02-28 02:12:13 +08:00
|
|
|
testErrs = append(testErrs, errors.New(fmt.Sprintf(
|
2017-12-19 05:20:23 +08:00
|
|
|
`binary "%s" variant "%s" has unexpected srcsZip: %q!`,
|
2017-02-28 02:12:13 +08:00
|
|
|
base.Name(),
|
2017-07-13 03:55:28 +08:00
|
|
|
base.properties.Actual_version,
|
2017-12-19 05:20:23 +08:00
|
|
|
base.srcsZip)))
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
|
2017-12-19 05:20:23 +08:00
|
|
|
for i, _ := range expectedDepsSrcsZips {
|
|
|
|
expectedDepsSrcsZips[i] = strings.Replace(expectedDepsSrcsZips[i], "@prefix@", buildDir, 1)
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
2017-12-19 05:20:23 +08:00
|
|
|
if !reflect.DeepEqual(base.depsSrcsZips.Strings(), expectedDepsSrcsZips) {
|
2017-02-28 02:12:13 +08:00
|
|
|
testErrs = append(testErrs, errors.New(fmt.Sprintf(
|
2017-12-19 05:20:23 +08:00
|
|
|
`binary "%s" variant "%s" has unexpected depsSrcsZips: %q!`,
|
2017-02-28 02:12:13 +08:00
|
|
|
base.Name(),
|
2017-07-13 03:55:28 +08:00
|
|
|
base.properties.Actual_version,
|
2017-12-19 05:20:23 +08:00
|
|
|
base.depsSrcsZips)))
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
func setUp() {
|
|
|
|
var err error
|
|
|
|
buildDir, err = ioutil.TempDir("", "soong_python_test")
|
2017-02-28 02:12:13 +08:00
|
|
|
if err != nil {
|
2019-12-14 12:41:13 +08:00
|
|
|
panic(err)
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-14 12:41:13 +08:00
|
|
|
func tearDown() {
|
2017-06-13 01:49:42 +08:00
|
|
|
os.RemoveAll(buildDir)
|
2017-02-28 02:12:13 +08:00
|
|
|
}
|
2019-12-14 12:41:13 +08:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
run := func() int {
|
|
|
|
setUp()
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
return m.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Exit(run())
|
|
|
|
}
|