blob: cd41fcfaed1229c7597e1cc65ce9f582afcf95ea [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
18 "strings"
19 "testing"
20)
21
22// Test that the prefer_dynamic property is handled correctly.
23func 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
39 if !strings.Contains(fizzBuzzDynamic.Args["rustcFlags"], "prefer-dynamic") {
40 t.Errorf("missing prefer-dynamic flag, rustcFlags: %#v", fizzBuzzDynamic.Args["rustcFlags"])
41 }
42
43 if strings.Contains(fizzBuzz.Args["rustcFlags"], "prefer-dynamic") {
44 t.Errorf("unexpected prefer-dynamic flag, rustcFlags: %#v", fizzBuzz.Args["rustcFlags"])
45 }
46}