summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp1
-rw-r--r--android/android_test.go46
-rw-r--r--android/namespace_test.go8
-rw-r--r--android/neverallow_test.go8
-rw-r--r--android/paths_test.go20
-rw-r--r--android/prebuilt_etc_test.go19
-rw-r--r--android/prebuilt_test.go8
-rw-r--r--android/rule_builder_test.go8
-rw-r--r--android/sh_binary_test.go8
-rw-r--r--android/visibility_test.go8
-rw-r--r--android/vts_config_test.go8
11 files changed, 48 insertions, 94 deletions
diff --git a/Android.bp b/Android.bp
index 4db98f851..ec4eb61e9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -78,6 +78,7 @@ bootstrap_go_package {
"android/env.go",
],
testSrcs: [
+ "android/android_test.go",
"android/arch_test.go",
"android/config_test.go",
"android/expand_test.go",
diff --git a/android/android_test.go b/android/android_test.go
new file mode 100644
index 000000000..46b705468
--- /dev/null
+++ b/android/android_test.go
@@ -0,0 +1,46 @@
+// Copyright 2019 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 android
+
+import (
+ "io/ioutil"
+ "os"
+ "testing"
+)
+
+var buildDir string
+
+func setUp() {
+ var err error
+ buildDir, err = ioutil.TempDir("", "soong_android_test")
+ if err != nil {
+ panic(err)
+ }
+}
+
+func tearDown() {
+ os.RemoveAll(buildDir)
+}
+
+func TestMain(m *testing.M) {
+ run := func() int {
+ setUp()
+ defer tearDown()
+
+ return m.Run()
+ }
+
+ os.Exit(run())
+}
diff --git a/android/namespace_test.go b/android/namespace_test.go
index 9a791a534..51a0af225 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -16,8 +16,6 @@ package android
import (
"errors"
- "io/ioutil"
- "os"
"path/filepath"
"reflect"
"testing"
@@ -613,12 +611,6 @@ func mockFiles(bps map[string]string) (files map[string][]byte) {
}
func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
- buildDir, err := ioutil.TempDir("", "soong_namespace_test")
- if err != nil {
- return nil, []error{err}
- }
- defer os.RemoveAll(buildDir)
-
config := TestConfig(buildDir, nil)
ctx = NewTestContext()
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 00c51eaab..d0d22d890 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -15,8 +15,6 @@
package android
import (
- "io/ioutil"
- "os"
"testing"
)
@@ -151,12 +149,6 @@ var neverallowTests = []struct {
}
func TestNeverallow(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_neverallow_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
config := TestConfig(buildDir, nil)
for _, test := range neverallowTests {
diff --git a/android/paths_test.go b/android/paths_test.go
index e0c2f6c96..7bcfe41d1 100644
--- a/android/paths_test.go
+++ b/android/paths_test.go
@@ -17,8 +17,6 @@ package android
import (
"errors"
"fmt"
- "io/ioutil"
- "os"
"reflect"
"strings"
"testing"
@@ -880,12 +878,6 @@ func testPathForModuleSrc(t *testing.T, buildDir string, tests []pathForModuleSr
}
func TestPathsForModuleSrc(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
tests := []pathForModuleSrcTestCase{
{
name: "path",
@@ -966,12 +958,6 @@ func TestPathsForModuleSrc(t *testing.T) {
}
func TestPathForModuleSrc(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_path_for_module_src_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
tests := []pathForModuleSrcTestCase{
{
name: "path",
@@ -1039,12 +1025,6 @@ func TestPathForModuleSrc(t *testing.T) {
}
func TestPathsForModuleSrc_AllowMissingDependencies(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_paths_for_module_src_allow_missing_dependencies_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
config := TestConfig(buildDir, nil)
config.TestProductVariables.Allow_missing_dependencies = proptools.BoolPtr(true)
diff --git a/android/prebuilt_etc_test.go b/android/prebuilt_etc_test.go
index d977c307e..0a2c7a4f5 100644
--- a/android/prebuilt_etc_test.go
+++ b/android/prebuilt_etc_test.go
@@ -15,16 +15,13 @@
package android
import (
- "io/ioutil"
- "os"
"path/filepath"
"reflect"
"testing"
)
func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
- config, buildDir := setUp(t)
- defer tearDown(buildDir)
+ config := TestArchConfig(buildDir, nil)
ctx := NewTestArchContext()
ctx.RegisterModuleType("prebuilt_etc", ModuleFactoryAdaptor(PrebuiltEtcFactory))
ctx.RegisterModuleType("prebuilt_etc_host", ModuleFactoryAdaptor(PrebuiltEtcHostFactory))
@@ -51,20 +48,6 @@ func testPrebuiltEtc(t *testing.T, bp string) (*TestContext, Config) {
return ctx, config
}
-func setUp(t *testing.T) (config Config, buildDir string) {
- buildDir, err := ioutil.TempDir("", "soong_prebuilt_etc_test")
- if err != nil {
- t.Fatal(err)
- }
-
- config = TestArchConfig(buildDir, nil)
- return
-}
-
-func tearDown(buildDir string) {
- os.RemoveAll(buildDir)
-}
-
func TestPrebuiltEtcVariants(t *testing.T) {
ctx, _ := testPrebuiltEtc(t, `
prebuilt_etc {
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index a5b85c8c2..0a18e2c90 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -16,8 +16,6 @@ package android
import (
"fmt"
- "io/ioutil"
- "os"
"testing"
"github.com/google/blueprint"
@@ -127,12 +125,6 @@ var prebuiltsTests = []struct {
}
func TestPrebuilts(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_prebuilt_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
config := TestConfig(buildDir, nil)
for _, test := range prebuiltsTests {
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index df0f25640..cfbc2abee 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -16,8 +16,6 @@ package android
import (
"fmt"
- "io/ioutil"
- "os"
"path/filepath"
"reflect"
"strings"
@@ -418,12 +416,6 @@ func testRuleBuilder_Build(ctx BuilderContext, in Path, out, outDep, outDir Writ
}
func TestRuleBuilder_Build(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_test_rule_builder")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
bp := `
rule_builder_test {
name: "foo",
diff --git a/android/sh_binary_test.go b/android/sh_binary_test.go
index becb35a21..c99e18c3e 100644
--- a/android/sh_binary_test.go
+++ b/android/sh_binary_test.go
@@ -1,19 +1,11 @@
package android
import (
- "io/ioutil"
- "os"
"reflect"
"testing"
)
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
- buildDir, err := ioutil.TempDir("", "soong_sh_binary_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
config := TestArchConfig(buildDir, nil)
ctx := NewTestArchContext()
diff --git a/android/visibility_test.go b/android/visibility_test.go
index 5ea32a2ef..1a514955d 100644
--- a/android/visibility_test.go
+++ b/android/visibility_test.go
@@ -1,8 +1,6 @@
package android
import (
- "io/ioutil"
- "os"
"testing"
"github.com/google/blueprint"
@@ -663,12 +661,6 @@ var visibilityTests = []struct {
}
func TestVisibility(t *testing.T) {
- buildDir, err := ioutil.TempDir("", "soong_neverallow_test")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(buildDir)
-
for _, test := range visibilityTests {
t.Run(test.name, func(t *testing.T) {
_, errs := testVisibility(buildDir, test.fs)
diff --git a/android/vts_config_test.go b/android/vts_config_test.go
index 7d4c9b1cf..142b2f591 100644
--- a/android/vts_config_test.go
+++ b/android/vts_config_test.go
@@ -15,19 +15,11 @@
package android
import (
- "io/ioutil"
- "os"
"testing"
)
func testVtsConfig(test *testing.T, bpFileContents string) *TestContext {
- buildDir, err := ioutil.TempDir("", "soong_vts_config_test")
- if err != nil {
- test.Fatal(err)
- }
-
config := TestArchConfig(buildDir, nil)
- defer func() { os.RemoveAll(buildDir) }()
ctx := NewTestArchContext()
ctx.RegisterModuleType("vts_config", ModuleFactoryAdaptor(VtsConfigFactory))