blob: a31ef165486beadd16647fb21aee2ca7e717901f [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
Paul Duffina560d5a2021-02-28 01:38:51 +000035 preparer1Then2 := GroupFixturePreparers(preparer1, preparer2)
Paul Duffin35816122021-02-24 01:49:52 +000036
Paul Duffina560d5a2021-02-28 01:38:51 +000037 preparer2Then1 := GroupFixturePreparers(preparer2, preparer1)
Paul Duffin35816122021-02-24 01:49:52 +000038
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
Paul Duffin3d0ddff2021-03-12 12:20:59 +000046 AssertDeepEquals(t, "preparers called in wrong order",
Paul Duffin35816122021-02-24 01:49:52 +000047 []string{"preparer1", "preparer2", "preparer4", "preparer3"}, list)
48}