Paul Duffin | db284be | 2021-03-11 08:07:46 +0000 | [diff] [blame^] | 1 | // Copyright 2021 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | "testing" |
| 20 | ) |
| 21 | |
| 22 | func TestJavaSystemModules(t *testing.T) { |
| 23 | ctx, _ := testJava(t, ` |
| 24 | java_system_modules { |
| 25 | name: "system-modules", |
| 26 | libs: ["system-module1", "system-module2"], |
| 27 | } |
| 28 | java_library { |
| 29 | name: "system-module1", |
| 30 | srcs: ["a.java"], |
| 31 | sdk_version: "none", |
| 32 | system_modules: "none", |
| 33 | } |
| 34 | java_library { |
| 35 | name: "system-module2", |
| 36 | srcs: ["b.java"], |
| 37 | sdk_version: "none", |
| 38 | system_modules: "none", |
| 39 | } |
| 40 | `) |
| 41 | |
| 42 | // check the existence of the module |
| 43 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 44 | |
| 45 | cmd := systemModules.Rule("jarsTosystemModules") |
| 46 | |
| 47 | // make sure the command compiles against the supplied modules. |
| 48 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 49 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 50 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 51 | module) |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestJavaSystemModulesImport(t *testing.T) { |
| 57 | ctx, _ := testJava(t, ` |
| 58 | java_system_modules_import { |
| 59 | name: "system-modules", |
| 60 | libs: ["system-module1", "system-module2"], |
| 61 | } |
| 62 | java_import { |
| 63 | name: "system-module1", |
| 64 | jars: ["a.jar"], |
| 65 | } |
| 66 | java_import { |
| 67 | name: "system-module2", |
| 68 | jars: ["b.jar"], |
| 69 | } |
| 70 | `) |
| 71 | |
| 72 | // check the existence of the module |
| 73 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 74 | |
| 75 | cmd := systemModules.Rule("jarsTosystemModules") |
| 76 | |
| 77 | // make sure the command compiles against the supplied modules. |
| 78 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 79 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 80 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 81 | module) |
| 82 | } |
| 83 | } |
| 84 | } |