Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | ) |
| 20 | |
Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 21 | func testNinjaDepsSingletonFactory() Singleton { |
| 22 | return testNinjaDepsSingleton{} |
| 23 | } |
| 24 | |
| 25 | type testNinjaDepsSingleton struct{} |
| 26 | |
| 27 | func (testNinjaDepsSingleton) GenerateBuildActions(ctx SingletonContext) { |
Colin Cross | 662d614 | 2022-11-03 20:38:01 -0700 | [diff] [blame] | 28 | ctx.Config().addNinjaFileDeps("foo") |
Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func TestNinjaDeps(t *testing.T) { |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 32 | result := GroupFixturePreparers( |
Paul Duffin | d9ec7d2 | 2021-03-16 23:57:12 +0000 | [diff] [blame] | 33 | FixtureRegisterWithContext(func(ctx RegistrationContext) { |
| 34 | ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory) |
| 35 | ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory) |
| 36 | }), |
Paul Duffin | 30ac3e7 | 2021-03-20 00:36:14 +0000 | [diff] [blame] | 37 | ).RunTest(t) |
Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 38 | |
| 39 | // Verify that the ninja file has a dependency on the test_ninja_deps directory. |
Colin Cross | 662d614 | 2022-11-03 20:38:01 -0700 | [diff] [blame] | 40 | if g, w := result.NinjaDeps, "foo"; !InList(w, g) { |
Colin Cross | 1212929 | 2020-10-29 18:23:58 -0700 | [diff] [blame] | 41 | t.Errorf("expected %q in %q", w, g) |
| 42 | } |
| 43 | } |