diff options
author | ThiƩbaud Weksteen <tweek@google.com> | 2020-10-07 14:30:03 +0200 |
---|---|---|
committer | ThiƩbaud Weksteen <tweek@google.com> | 2020-10-08 15:51:10 +0200 |
commit | 0a75e524604d63da90d68f86b1d1a67e983d85b3 (patch) | |
tree | 6398e59aa955f681fd92ac9a2f297bacd23c2b2f /rust/project_json_test.go | |
parent | 36e4ad1f4dcb517a741680be1fdd1d14241f8ad5 (diff) |
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
Diffstat (limited to 'rust/project_json_test.go')
-rw-r--r-- | rust/project_json_test.go | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/rust/project_json_test.go b/rust/project_json_test.go index 11964f345..69288fcfa 100644 --- a/rust/project_json_test.go +++ b/rust/project_json_test.go @@ -22,22 +22,15 @@ import ( "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 @@ func TestProjectJsonDep(t *testing.T) { 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 @@ func TestProjectJsonBindGen(t *testing.T) { 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 @@ func TestProjectJsonMultiVersion(t *testing.T) { 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{}) |