rust: refactor tests setup
Move to a builder pattern to increase flexibility when generating the
test configuration. The testRust, testRustCov and testRustError are kept
as main entry points for standard tests. Add documentation.
Test: m nothing
Change-Id: I891bec982ff2d65413f150d2395edf0fb0d68a43
diff --git a/rust/project_json_test.go b/rust/project_json_test.go
index 11964f3..69288fc 100644
--- a/rust/project_json_test.go
+++ b/rust/project_json_test.go
@@ -22,22 +22,15 @@
"testing"
"android/soong/android"
- "android/soong/cc"
)
// testProjectJson run the generation of rust-project.json. It returns the raw
// content of the generated file.
-func testProjectJson(t *testing.T, bp string, fs map[string][]byte) []byte {
- cc.GatherRequiredFilesForTest(fs)
-
- env := map[string]string{"SOONG_GEN_RUST_PROJECT": "1"}
- config := android.TestArchConfig(buildDir, env, bp, fs)
- ctx := CreateTestContext()
- ctx.Register(config)
- _, errs := ctx.ParseFileList(".", []string{"Android.bp"})
- android.FailIfErrored(t, errs)
- _, errs = ctx.PrepareBuildActions(config)
- android.FailIfErrored(t, errs)
+func testProjectJson(t *testing.T, bp string) []byte {
+ tctx := newTestRustCtx(t, bp)
+ tctx.env = map[string]string{"SOONG_GEN_RUST_PROJECT": "1"}
+ tctx.generateConfig()
+ tctx.parse(t)
// The JSON file is generated via WriteFileToOutputDir. Therefore, it
// won't appear in the Output of the TestingSingleton. Manually verify
@@ -87,12 +80,8 @@
crate_name: "b",
rlibs: ["liba"],
}
- ` + GatherRequiredDepsForTest()
- fs := map[string][]byte{
- "a/src/lib.rs": nil,
- "b/src/lib.rs": nil,
- }
- jsonContent := testProjectJson(t, bp, fs)
+ `
+ jsonContent := testProjectJson(t, bp)
validateJsonCrates(t, jsonContent)
}
@@ -123,11 +112,8 @@
source_stem: "bindings2",
wrapper_src: "src/any.h",
}
- ` + GatherRequiredDepsForTest()
- fs := map[string][]byte{
- "src/lib.rs": nil,
- }
- jsonContent := testProjectJson(t, bp, fs)
+ `
+ jsonContent := testProjectJson(t, bp)
crates := validateJsonCrates(t, jsonContent)
for _, c := range crates {
crate, ok := c.(map[string]interface{})
@@ -166,13 +152,8 @@
crate_name: "b",
rustlibs: ["liba1", "liba2"],
}
- ` + GatherRequiredDepsForTest()
- fs := map[string][]byte{
- "a1/src/lib.rs": nil,
- "a2/src/lib.rs": nil,
- "b/src/lib.rs": nil,
- }
- jsonContent := testProjectJson(t, bp, fs)
+ `
+ jsonContent := testProjectJson(t, bp)
crates := validateJsonCrates(t, jsonContent)
for _, crate := range crates {
c := crate.(map[string]interface{})