blob: 5b557998317f0a749f452a847bb58c7624924563 [file] [log] [blame]
Colin Cross638149e2019-01-05 22:12:12 -08001// Copyright 2018 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "testing"
19)
20
21func TestDexpreoptEnabled(t *testing.T) {
22 tests := []struct {
23 name string
24 bp string
25 enabled bool
26 }{
27 {
28 name: "app",
29 bp: `
30 android_app {
31 name: "foo",
32 srcs: ["a.java"],
33 }`,
34 enabled: true,
35 },
36 {
37 name: "installable java library",
38 bp: `
39 java_library {
40 name: "foo",
41 installable: true,
42 srcs: ["a.java"],
43 }`,
44 enabled: true,
45 },
46 {
47 name: "java binary",
48 bp: `
49 java_binary {
50 name: "foo",
51 srcs: ["a.java"],
52 }`,
53 enabled: true,
54 },
55
56 {
57 name: "app without sources",
58 bp: `
59 android_app {
60 name: "foo",
61 }`,
62 // TODO(ccross): this should probably be false
63 enabled: true,
64 },
65 {
66 name: "installable java library without sources",
67 bp: `
68 java_library {
69 name: "foo",
70 installable: true,
71 }`,
72 // TODO(ccross): this should probably be false
73 enabled: true,
74 },
75
76 {
77 name: "static java library",
78 bp: `
79 java_library {
80 name: "foo",
81 srcs: ["a.java"],
82 }`,
83 enabled: false,
84 },
85 {
86 name: "android test",
87 bp: `
88 android_test {
89 name: "foo",
90 srcs: ["a.java"],
91 }`,
92 enabled: false,
93 },
94 {
95 name: "android test helper app",
96 bp: `
97 android_test_helper_app {
98 name: "foo",
99 srcs: ["a.java"],
100 }`,
101 enabled: false,
102 },
103 }
104
105 for _, test := range tests {
106 t.Run(test.name, func(t *testing.T) {
107 ctx := testJava(t, test.bp)
108
109 dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeDescription("dexpreopt")
110 enabled := dexpreopt.Rule != nil
111
112 if enabled != test.enabled {
113 t.Fatalf("want dexpreopt %s, got %s", enabledString(test.enabled), enabledString(enabled))
114 }
115 })
116
117 }
118}
119
120func enabledString(enabled bool) string {
121 if enabled {
122 return "enabled"
123 } else {
124 return "disabled"
125 }
126}