Revert "Add unit test for parsing build files in bp2build"

This reverts commit e1f25230df.

Reason for revert: breaks bp2build ci

Change-Id: I7320ef679d8a1ba1d605cf0d3781854b97816358
This commit is contained in:
Cole Faust
2023-06-27 22:52:07 +00:00
committed by Gerrit Code Review
parent e1f25230df
commit 3d927238cc
5 changed files with 47 additions and 119 deletions

View File

@@ -21,7 +21,6 @@ specific-but-shared functionality among tests in package
import (
"fmt"
"path/filepath"
"sort"
"strings"
"testing"
@@ -83,12 +82,7 @@ type Bp2buildTestCase struct {
// ExpectedBazelTargets compares the BazelTargets generated in `Dir` (if not empty).
// Otherwise, it checks the BazelTargets generated by `Blueprint` in the root directory.
ExpectedBazelTargets []string
// AlreadyExistingBuildContents, if non-empty, simulates an already-present source BUILD file
// in the directory under test. The BUILD file has the given contents. This BUILD file
// will also be treated as "BUILD file to keep" by the simulated bp2build environment.
AlreadyExistingBuildContents string
Filesystem map[string]string
Filesystem map[string]string
// Dir sets the directory which will be compared against the targets in ExpectedBazelTargets.
// This should used in conjunction with the Filesystem property to check for targets
// generated from a directory that is not the root.
@@ -125,22 +119,11 @@ func RunApiBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.R
func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePreparer, tc Bp2buildTestCase) {
t.Helper()
checkDir := "."
if tc.Dir != "" {
checkDir = tc.Dir
}
keepExistingBuildDirs := tc.KeepBuildFileForDirs
buildFilesToParse := []string{}
dir := "."
filesystem := make(map[string][]byte)
for f, content := range tc.Filesystem {
filesystem[f] = []byte(content)
}
if len(tc.AlreadyExistingBuildContents) > 0 {
buildFilePath := filepath.Join(checkDir, "BUILD")
filesystem[buildFilePath] = []byte(tc.AlreadyExistingBuildContents)
keepExistingBuildDirs = append(keepExistingBuildDirs, checkDir)
buildFilesToParse = append(buildFilesToParse, buildFilePath)
}
preparers := []android.FixturePreparer{
extraPreparer,
@@ -149,7 +132,7 @@ func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePre
android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
ctx.RegisterModuleType(tc.ModuleTypeUnderTest, tc.ModuleTypeUnderTestFactory)
}),
android.FixtureModifyContextWithMockFs(func(ctx *android.TestContext) {
android.FixtureModifyContext(func(ctx *android.TestContext) {
// A default configuration for tests to not have to specify bp2build_available on top level
// targets.
bp2buildConfig := android.NewBp2BuildAllowlist().SetDefaultConfig(
@@ -157,7 +140,7 @@ func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePre
android.Bp2BuildTopLevel: allowlists.Bp2BuildDefaultTrueRecursively,
},
)
for _, f := range keepExistingBuildDirs {
for _, f := range tc.KeepBuildFileForDirs {
bp2buildConfig.SetKeepExistingBuildFile(map[string]bool{
f: /*recursive=*/ false,
})
@@ -167,10 +150,6 @@ func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePre
// from cloning modules to their original state after mutators run. This
// would lose some data intentionally set by these mutators.
ctx.SkipCloneModulesAfterMutators = true
err := ctx.ParseBuildFiles(".", buildFilesToParse)
if err != nil {
t.Errorf("error parsing build files in test setup: %s", err)
}
}),
android.FixtureModifyEnv(func(env map[string]string) {
if tc.UnconvertedDepsMode == errorModulesUnconvertedDeps {
@@ -189,6 +168,10 @@ func runBp2BuildTestCaseWithSetup(t *testing.T, extraPreparer android.FixturePre
return
}
checkDir := dir
if tc.Dir != "" {
checkDir = tc.Dir
}
expectedTargets := map[string][]string{
checkDir: tc.ExpectedBazelTargets,
}