Migrate sh package to a per test build directory

Bug: 182885307
Test: m nothing
Change-Id: I8e379c555e48ab482c56a19630d83a3a54126fc5
diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go
index 7a24168..5887b56 100644
--- a/sh/sh_binary_test.go
+++ b/sh/sh_binary_test.go
@@ -1,44 +1,20 @@
 package sh
 
 import (
-	"io/ioutil"
 	"os"
-	"path"
 	"path/filepath"
-	"reflect"
 	"testing"
 
 	"android/soong/android"
 	"android/soong/cc"
 )
 
-var buildDir string
-
-func setUp() {
-	var err error
-	buildDir, err = ioutil.TempDir("", "soong_sh_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())
+	os.Exit(m.Run())
 }
 
 var shFixtureFactory = android.NewFixtureFactory(
-	&buildDir,
+	nil,
 	cc.PrepareForTestWithCcBuildComponents,
 	PrepareForTestWithShBuildComponents,
 	android.FixtureMergeMockFs(android.MockFS{
@@ -66,7 +42,7 @@
 }
 
 func TestShTestSubDir(t *testing.T) {
-	ctx, _ := testShBinary(t, `
+	ctx, config := testShBinary(t, `
 		sh_test {
 			name: "foo",
 			src: "test.sh",
@@ -78,16 +54,13 @@
 
 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
 
-	expectedPath := path.Join(buildDir,
-		"../target/product/test_device/data/nativetest64/foo_test")
+	expectedPath := "out/target/product/test_device/data/nativetest64/foo_test"
 	actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
-	if expectedPath != actualPath {
-		t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
-	}
+	android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath)
 }
 
 func TestShTest(t *testing.T) {
-	ctx, _ := testShBinary(t, `
+	ctx, config := testShBinary(t, `
 		sh_test {
 			name: "foo",
 			src: "test.sh",
@@ -103,22 +76,17 @@
 
 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
 
-	expectedPath := path.Join(buildDir,
-		"../target/product/test_device/data/nativetest64/foo")
+	expectedPath := "out/target/product/test_device/data/nativetest64/foo"
 	actualPath := entries.EntryMap["LOCAL_MODULE_PATH"][0]
-	if expectedPath != actualPath {
-		t.Errorf("Unexpected LOCAL_MODULE_PATH expected: %q, actual: %q", expectedPath, actualPath)
-	}
+	android.AssertStringPathRelativeToTopEquals(t, "LOCAL_MODULE_PATH[0]", config, expectedPath, actualPath)
 
 	expectedData := []string{":testdata/data1", ":testdata/sub/data2"}
 	actualData := entries.EntryMap["LOCAL_TEST_DATA"]
-	if !reflect.DeepEqual(expectedData, actualData) {
-		t.Errorf("Unexpected test data expected: %q, actual: %q", expectedData, actualData)
-	}
+	android.AssertDeepEquals(t, "LOCAL_TEST_DATA", expectedData, actualData)
 }
 
 func TestShTest_dataModules(t *testing.T) {
-	ctx, _ := testShBinary(t, `
+	ctx, config := testShBinary(t, `
 		sh_test {
 			name: "foo",
 			src: "test.sh",
@@ -157,22 +125,17 @@
 			libExt = ".dylib"
 		}
 		relocated := variant.Output("relocated/lib64/libbar" + libExt)
-		expectedInput := filepath.Join(buildDir, ".intermediates/libbar/"+arch+"_shared/libbar"+libExt)
-		if relocated.Input.String() != expectedInput {
-			t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
-				expectedInput, relocated.Input.String())
-		}
+		expectedInput := "out/soong/.intermediates/libbar/" + arch + "_shared/libbar" + libExt
+		android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
 
 		mod := variant.Module().(*ShTest)
 		entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
 		expectedData := []string{
-			filepath.Join(buildDir, ".intermediates/bar", arch, ":bar"),
-			filepath.Join(buildDir, ".intermediates/foo", arch, "relocated/:lib64/libbar"+libExt),
+			filepath.Join("out/soong/.intermediates/bar", arch, ":bar"),
+			filepath.Join("out/soong/.intermediates/foo", arch, "relocated/:lib64/libbar"+libExt),
 		}
 		actualData := entries.EntryMap["LOCAL_TEST_DATA"]
-		if !reflect.DeepEqual(expectedData, actualData) {
-			t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
-		}
+		android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
 	}
 }
 
@@ -197,7 +160,7 @@
 }
 
 func TestShTestHost_dataDeviceModules(t *testing.T) {
-	ctx, _ := testShBinary(t, `
+	ctx, config := testShBinary(t, `
 		sh_test_host {
 			name: "foo",
 			src: "test.sh",
@@ -227,21 +190,16 @@
 	variant := ctx.ModuleForTests("foo", buildOS+"_x86_64")
 
 	relocated := variant.Output("relocated/lib64/libbar.so")
-	expectedInput := filepath.Join(buildDir, ".intermediates/libbar/android_arm64_armv8-a_shared/libbar.so")
-	if relocated.Input.String() != expectedInput {
-		t.Errorf("Unexpected relocation input, expected: %q, actual: %q",
-			expectedInput, relocated.Input.String())
-	}
+	expectedInput := "out/soong/.intermediates/libbar/android_arm64_armv8-a_shared/libbar.so"
+	android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
 
 	mod := variant.Module().(*ShTest)
 	entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
 	expectedData := []string{
-		filepath.Join(buildDir, ".intermediates/bar/android_arm64_armv8-a/:bar"),
+		"out/soong/.intermediates/bar/android_arm64_armv8-a/:bar",
 		// libbar has been relocated, and so has a variant that matches the host arch.
-		filepath.Join(buildDir, ".intermediates/foo/"+buildOS+"_x86_64/relocated/:lib64/libbar.so"),
+		"out/soong/.intermediates/foo/" + buildOS + "_x86_64/relocated/:lib64/libbar.so",
 	}
 	actualData := entries.EntryMap["LOCAL_TEST_DATA"]
-	if !reflect.DeepEqual(expectedData, actualData) {
-		t.Errorf("Unexpected test data, expected: %q, actual: %q", expectedData, actualData)
-	}
+	android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", config, expectedData, actualData)
 }