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