blob: f131c6ebe9eef980e15160a332e16db3e562795c [file] [log] [blame]
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -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// Check if rust_test_host accepts multiple source files and applies --test flag.
23func TestRustTest(t *testing.T) {
24 ctx := testRust(t, `
25 rust_test_host {
26 name: "my_test",
27 srcs: ["foo.rs", "src/bar.rs"],
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -070028 crate_name: "new_test", // not used for multiple source files
Chih-Hung Hsieha5f22ed2019-10-24 20:47:54 -070029 relative_install_path: "rust/my-test",
30 }`)
31
32 for _, name := range []string{"foo", "bar"} {
33 testingModule := ctx.ModuleForTests("my_test", "linux_glibc_x86_64_"+name)
34 testingBuildParams := testingModule.Output(name)
35 rustcFlags := testingBuildParams.Args["rustcFlags"]
36 if !strings.Contains(rustcFlags, "--test") {
37 t.Errorf("%v missing --test flag, rustcFlags: %#v", name, rustcFlags)
38 }
39 outPath := "/my_test/linux_glibc_x86_64_" + name + "/" + name
40 if !strings.Contains(testingBuildParams.Output.String(), outPath) {
41 t.Errorf("wrong output: %v expect: %v", testingBuildParams.Output, outPath)
42 }
43 }
44}
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -070045
46// crate_name is output file name, when there is only one source file.
47func TestRustTestSingleFile(t *testing.T) {
48 ctx := testRust(t, `
49 rust_test_host {
50 name: "my-test",
51 srcs: ["foo.rs"],
52 crate_name: "new_test",
53 relative_install_path: "my-pkg",
54 }`)
55
56 name := "new_test"
57 testingModule := ctx.ModuleForTests("my-test", "linux_glibc_x86_64_"+name)
58 outPath := "/my-test/linux_glibc_x86_64_" + name + "/" + name
59 testingBuildParams := testingModule.Output(name)
60 if !strings.Contains(testingBuildParams.Output.String(), outPath) {
61 t.Errorf("wrong output: %v expect: %v", testingBuildParams.Output, outPath)
62 }
63}