blob: 7bc033be7f4358a428e3087a6e7b7bdc128dcac5 [file] [log] [blame]
Paul Duffin35816122021-02-24 01:49:52 +00001// Copyright 2021 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 android
16
17import "testing"
18
19// Make sure that FixturePreparer instances are only called once per fixture and in the order in
20// which they were added.
21func TestFixtureDedup(t *testing.T) {
22 list := []string{}
23
24 appendToList := func(s string) FixturePreparer {
25 return FixtureModifyConfig(func(_ Config) {
26 list = append(list, s)
27 })
28 }
29
30 preparer1 := appendToList("preparer1")
31 preparer2 := appendToList("preparer2")
32 preparer3 := appendToList("preparer3")
33 preparer4 := appendToList("preparer4")
34
35 preparer1Then2 := FixturePreparers(preparer1, preparer2)
36
37 preparer2Then1 := FixturePreparers(preparer2, preparer1)
38
39 buildDir := "build"
40 factory := NewFixtureFactory(&buildDir, preparer1, preparer2, preparer1, preparer1Then2)
41
42 extension := factory.Extend(preparer4, preparer2)
43
44 extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3)
45
46 h := TestHelper{t}
47 h.AssertDeepEquals("preparers called in wrong order",
48 []string{"preparer1", "preparer2", "preparer4", "preparer3"}, list)
49}