-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh_binary_test.go
79 lines (69 loc) · 1.82 KB
/
sh_binary_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package android
import (
"io/ioutil"
"os"
"reflect"
"testing"
)
func testShBinary(t *testing.T, bp string) (*TestContext, Config) {
buildDir, err := ioutil.TempDir("", "soong_sh_binary_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(buildDir)
config := TestArchConfig(buildDir, nil)
ctx := NewTestArchContext()
ctx.RegisterModuleType("sh_test", ModuleFactoryAdaptor(ShTestFactory))
ctx.RegisterModuleType("sh_test_host", ModuleFactoryAdaptor(ShTestHostFactory))
ctx.Register()
mockFiles := map[string][]byte{
"Android.bp": []byte(bp),
"test.sh": nil,
"testdata/data1": nil,
"testdata/sub/data2": nil,
}
ctx.MockFileSystem(mockFiles)
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
return ctx, config
}
func TestShTestTestData(t *testing.T) {
ctx, config := testShBinary(t, `
sh_test {
name: "foo",
src: "test.sh",
filename: "test.sh",
data: [
"testdata/data1",
"testdata/sub/data2",
],
}
`)
mod := ctx.ModuleForTests("foo", "android_arm64_armv8-a").Module().(*ShTest)
entries := AndroidMkEntriesForTest(t, config, "", mod)
expected := []string{":testdata/data1", ":testdata/sub/data2"}
actual := entries.EntryMap["LOCAL_TEST_DATA"]
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Unexpected test data expected: %q, actual: %q", expected, actual)
}
}
func TestShTestHost(t *testing.T) {
ctx, _ := testShBinary(t, `
sh_test_host {
name: "foo",
src: "test.sh",
filename: "test.sh",
data: [
"testdata/data1",
"testdata/sub/data2",
],
}
`)
buildOS := BuildOs.String()
mod := ctx.ModuleForTests("foo", buildOS+"_x86_64").Module().(*ShTest)
if !mod.Host() {
t.Errorf("host bit is not set for a sh_test_host module.")
}
}