1// Copyright 2020 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 rust 16 17import ( 18 "io/ioutil" 19 "path/filepath" 20 "testing" 21 22 "android/soong/android" 23 "android/soong/cc" 24) 25 26func TestProjectJson(t *testing.T) { 27 bp := `rust_library { 28 name: "liba", 29 srcs: ["src/lib.rs"], 30 crate_name: "a" 31 }` + GatherRequiredDepsForTest() 32 env := map[string]string{"SOONG_GEN_RUST_PROJECT": "1"} 33 fs := map[string][]byte{ 34 "foo.rs": nil, 35 "src/lib.rs": nil, 36 } 37 38 cc.GatherRequiredFilesForTest(fs) 39 40 config := android.TestArchConfig(buildDir, env, bp, fs) 41 ctx := CreateTestContext() 42 ctx.Register(config) 43 _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) 44 android.FailIfErrored(t, errs) 45 _, errs = ctx.PrepareBuildActions(config) 46 android.FailIfErrored(t, errs) 47 48 // The JSON file is generated via WriteFileToOutputDir. Therefore, it 49 // won't appear in the Output of the TestingSingleton. Manually verify 50 // it exists. 51 _, err := ioutil.ReadFile(filepath.Join(buildDir, "rust-project.json")) 52 if err != nil { 53 t.Errorf("rust-project.json has not been generated") 54 } 55} 56