Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 1 | package android |
| 2 | |
| 3 | import ( |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func testShBinary(t *testing.T, bp string) (*TestContext, Config) { |
Jaewoong Jung | 8eaeb09 | 2019-05-16 14:58:29 -0700 | [diff] [blame] | 9 | config := TestArchConfig(buildDir, nil) |
| 10 | |
| 11 | ctx := NewTestArchContext() |
| 12 | ctx.RegisterModuleType("sh_test", ModuleFactoryAdaptor(ShTestFactory)) |
| 13 | ctx.Register() |
| 14 | mockFiles := map[string][]byte{ |
| 15 | "Android.bp": []byte(bp), |
| 16 | "test.sh": nil, |
| 17 | "testdata/data1": nil, |
| 18 | "testdata/sub/data2": nil, |
| 19 | } |
| 20 | ctx.MockFileSystem(mockFiles) |
| 21 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 22 | FailIfErrored(t, errs) |
| 23 | _, errs = ctx.PrepareBuildActions(config) |
| 24 | FailIfErrored(t, errs) |
| 25 | |
| 26 | return ctx, config |
| 27 | } |
| 28 | |
| 29 | func TestShTestTestData(t *testing.T) { |
| 30 | ctx, config := testShBinary(t, ` |
| 31 | sh_test { |
| 32 | name: "foo", |
| 33 | src: "test.sh", |
| 34 | filename: "test.sh", |
| 35 | data: [ |
| 36 | "testdata/data1", |
| 37 | "testdata/sub/data2", |
| 38 | ], |
| 39 | } |
| 40 | `) |
| 41 | |
| 42 | mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest) |
| 43 | |
| 44 | entries := AndroidMkEntriesForTest(t, config, "", mod) |
| 45 | expected := []string{":testdata/data1", ":testdata/sub/data2"} |
| 46 | actual := entries.EntryMap["LOCAL_TEST_DATA"] |
| 47 | if !reflect.DeepEqual(expected, actual) { |
| 48 | t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual) |
| 49 | } |
| 50 | } |