| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project | 
|  | 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 rust | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "strings" | 
|  | 19 | "testing" | 
|  | 20 | ) | 
|  | 21 |  | 
|  | 22 | // Test that the prefer_dynamic property is handled correctly. | 
|  | 23 | func TestPreferDynamicBinary(t *testing.T) { | 
|  | 24 | ctx := testRust(t, ` | 
|  | 25 | rust_binary_host { | 
|  | 26 | name: "fizz-buzz-dynamic", | 
|  | 27 | srcs: ["foo.rs"], | 
|  | 28 | prefer_dynamic: true, | 
|  | 29 | } | 
|  | 30 |  | 
|  | 31 | rust_binary_host { | 
|  | 32 | name: "fizz-buzz", | 
|  | 33 | srcs: ["foo.rs"], | 
|  | 34 | }`) | 
|  | 35 |  | 
|  | 36 | fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Output("fizz-buzz") | 
|  | 37 | fizzBuzzDynamic := ctx.ModuleForTests("fizz-buzz-dynamic", "linux_glibc_x86_64").Output("fizz-buzz-dynamic") | 
|  | 38 |  | 
| Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 39 | // Do not compile binary modules with the --test flag. | 
|  | 40 | flags := fizzBuzzDynamic.Args["rustcFlags"] | 
|  | 41 | if strings.Contains(flags, "--test") { | 
|  | 42 | t.Errorf("extra --test flag, rustcFlags: %#v", flags) | 
|  | 43 | } | 
|  | 44 | if !strings.Contains(flags, "prefer-dynamic") { | 
|  | 45 | t.Errorf("missing prefer-dynamic flag, rustcFlags: %#v", flags) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 46 | } | 
|  | 47 |  | 
| Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 48 | flags = fizzBuzz.Args["rustcFlags"] | 
|  | 49 | if strings.Contains(flags, "--test") { | 
|  | 50 | t.Errorf("extra --test flag, rustcFlags: %#v", flags) | 
|  | 51 | } | 
|  | 52 | if strings.Contains(flags, "prefer-dynamic") { | 
|  | 53 | t.Errorf("unexpected prefer-dynamic flag, rustcFlags: %#v", flags) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 54 | } | 
|  | 55 | } |