Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ffb9a8d authored by Colin Cross's avatar Colin Cross
Browse files

Share buildDir for android/soong/android tests

There is no need to create a separate buildDir for each test
file, use TestMain to create a global one for the package.

Test: all soong tests
Change-Id: I435ee7aa88b7e0bb8ccc1ba79f82833a7accf3e9
parent 6c4f21f3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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",
+46 −0
Original line number Diff line number Diff line
// 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())
}
+0 −8
Original line number Diff line number Diff line
@@ -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()
+0 −8
Original line number Diff line number Diff line
@@ -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 {
+0 −20
Original line number Diff line number Diff line
@@ -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)

Loading