github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/planner/stack.go (about)

     1  // Copyright 2022 The ChromiumOS Authors
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package planner
     6  
     7  import (
     8  	"context"
     9  
    10  	"go.chromium.org/tast/core/internal/planner/internal/fixture"
    11  	"go.chromium.org/tast/core/internal/protocol"
    12  	"go.chromium.org/tast/core/internal/testing"
    13  )
    14  
    15  type internalOrCombinedStack struct {
    16  	internal *fixture.InternalStack
    17  	combined *fixture.CombinedStack
    18  }
    19  
    20  func (s *internalOrCombinedStack) Status() fixture.Status {
    21  	if s.internal != nil {
    22  		return s.internal.Status()
    23  	}
    24  	return s.combined.Status()
    25  }
    26  
    27  func (s *internalOrCombinedStack) Errors() []*protocol.Error {
    28  	if s.internal != nil {
    29  		return s.internal.Errors()
    30  	}
    31  	return s.combined.Errors()
    32  }
    33  
    34  func (s *internalOrCombinedStack) Val() interface{} {
    35  	if s.internal != nil {
    36  		return s.internal.Val()
    37  	}
    38  	return s.combined.Val()
    39  }
    40  
    41  func (s *internalOrCombinedStack) SerializedVal(ctx context.Context) ([]byte, error) {
    42  	if s.internal != nil {
    43  		return s.internal.SerializedVal(ctx)
    44  	}
    45  	return s.combined.SerializedVal(ctx)
    46  }
    47  
    48  func (s *internalOrCombinedStack) Push(ctx context.Context, fixt *testing.FixtureInstance) error {
    49  	if s.internal != nil {
    50  		return s.internal.Push(ctx, fixt)
    51  	}
    52  	return s.combined.Push(ctx, fixt)
    53  }
    54  
    55  func (s *internalOrCombinedStack) Pop(ctx context.Context) error {
    56  	if s.internal != nil {
    57  		return s.internal.Pop(ctx)
    58  	}
    59  	return s.combined.Pop(ctx)
    60  }
    61  
    62  func (s *internalOrCombinedStack) Reset(ctx context.Context) error {
    63  	if s.internal != nil {
    64  		return s.internal.Reset(ctx)
    65  	}
    66  	return s.combined.Reset(ctx)
    67  }
    68  
    69  func (s internalOrCombinedStack) PreTest(ctx context.Context, test *protocol.Entity, outDir string, out testing.OutputStream, condition *testing.EntityCondition) (func(ctx context.Context) error, error) {
    70  	if s.internal != nil {
    71  		return s.internal.PreTest(ctx, outDir, out, condition, test)
    72  	}
    73  	return s.combined.PreTest(ctx, test, outDir, out, condition)
    74  }
    75  
    76  func (s *internalOrCombinedStack) MarkDirty(ctx context.Context) error {
    77  	if s.internal != nil {
    78  		return s.internal.MarkDirty()
    79  	}
    80  	return s.combined.SetDirty(ctx, true)
    81  }