blob: 08a308515401c82834fa4e6c9df41e7d330fc565 [file] [log] [blame]
Colin Cross21fc9bb2019-01-18 15:05:09 -08001// Copyright 2017 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 "strings"
19 "testing"
20)
21
22func TestKotlin(t *testing.T) {
23 ctx := testJava(t, `
24 java_library {
25 name: "foo",
26 srcs: ["a.java", "b.kt"],
27 }
28
29 java_library {
30 name: "bar",
31 srcs: ["b.kt"],
32 libs: ["foo"],
33 static_libs: ["baz"],
34 }
35
36 java_library {
37 name: "baz",
38 srcs: ["c.java"],
39 }
40 `)
41
42 fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
43 fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
44 fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar")
45
46 if len(fooKotlinc.Inputs) != 2 || fooKotlinc.Inputs[0].String() != "a.java" ||
47 fooKotlinc.Inputs[1].String() != "b.kt" {
48 t.Errorf(`foo kotlinc inputs %v != ["a.java", "b.kt"]`, fooKotlinc.Inputs)
49 }
50
51 if len(fooJavac.Inputs) != 1 || fooJavac.Inputs[0].String() != "a.java" {
52 t.Errorf(`foo inputs %v != ["a.java"]`, fooJavac.Inputs)
53 }
54
55 if !strings.Contains(fooJavac.Args["classpath"], fooKotlinc.Output.String()) {
56 t.Errorf("foo classpath %v does not contain %q",
57 fooJavac.Args["classpath"], fooKotlinc.Output.String())
58 }
59
60 if !inList(fooKotlinc.Output.String(), fooJar.Inputs.Strings()) {
61 t.Errorf("foo jar inputs %v does not contain %q",
62 fooJar.Inputs.Strings(), fooKotlinc.Output.String())
63 }
64
65 fooHeaderJar := ctx.ModuleForTests("foo", "android_common").Output("turbine-combined/foo.jar")
66 bazHeaderJar := ctx.ModuleForTests("baz", "android_common").Output("turbine-combined/baz.jar")
67 barKotlinc := ctx.ModuleForTests("bar", "android_common").Rule("kotlinc")
68
69 if len(barKotlinc.Inputs) != 1 || barKotlinc.Inputs[0].String() != "b.kt" {
70 t.Errorf(`bar kotlinc inputs %v != ["b.kt"]`, barKotlinc.Inputs)
71 }
72
73 if !inList(fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) {
74 t.Errorf(`expected %q in bar implicits %v`,
75 fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
76 }
77
78 if !inList(bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) {
79 t.Errorf(`expected %q in bar implicits %v`,
80 bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings())
81 }
82}