Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package provenance |
| 18 | |
| 19 | import ( |
| 20 | "strings" |
| 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
| 24 | ) |
| 25 | |
| 26 | func TestProvenanceSingleton(t *testing.T) { |
| 27 | result := android.GroupFixturePreparers( |
| 28 | PrepareForTestWithProvenanceSingleton, |
| 29 | android.PrepareForTestWithAndroidMk).RunTestWithBp(t, "") |
| 30 | |
| 31 | outputs := result.SingletonForTests("provenance_metadata_singleton").AllOutputs() |
| 32 | for _, output := range outputs { |
| 33 | testingBuildParam := result.SingletonForTests("provenance_metadata_singleton").Output(output) |
| 34 | switch { |
| 35 | case strings.Contains(output, "soong/provenance_metadata.textproto"): |
| 36 | android.AssertStringEquals(t, "Invalid build rule", "android/soong/provenance.mergeProvenanceMetaData", testingBuildParam.Rule.String()) |
| 37 | android.AssertIntEquals(t, "Invalid input", len(testingBuildParam.Inputs), 0) |
| 38 | android.AssertStringDoesContain(t, "Invalid output path", output, "soong/provenance_metadata.textproto") |
| 39 | android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0) |
| 40 | |
| 41 | case strings.HasSuffix(output, "provenance_metadata"): |
| 42 | android.AssertStringEquals(t, "Invalid build rule", "<builtin>:phony", testingBuildParam.Rule.String()) |
| 43 | android.AssertStringEquals(t, "Invalid input", testingBuildParam.Inputs[0].String(), "out/soong/provenance_metadata.textproto") |
| 44 | android.AssertStringEquals(t, "Invalid output path", output, "provenance_metadata") |
| 45 | android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0) |
| 46 | } |
| 47 | } |
| 48 | } |