LCOV - code coverage report
Current view: top level - pebble/internal/metamorphic/metarunner - main.go (source / functions) Hit Total Coverage
Test: 2024-04-16 08:16Z c34894c4 - meta test only.lcov Lines: 14 29 48.3 %
Date: 2024-04-16 08:16:49 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : // metarunner is a utility which runs metamorphic.RunOnce or Compare. It is
       6             : // equivalent to executing `internal/metamorphic.TestMeta` with `--run-dir` or
       7             : // `--compare`. It is used for code coverage instrumentation.
       8             : package main
       9             : 
      10             : import (
      11             :         "flag"
      12             :         "fmt"
      13             :         "os"
      14             :         "path/filepath"
      15             : 
      16             :         "github.com/cockroachdb/pebble/internal/metamorphic/metaflags"
      17             :         "github.com/cockroachdb/pebble/metamorphic"
      18             : )
      19             : 
      20             : var runOnceFlags = metaflags.InitRunOnceFlags()
      21             : var _ = flag.String("test.run", "", `ignored; used for compatibility with TestMeta`)
      22             : 
      23           1 : func main() {
      24           1 :         flag.Parse()
      25           1 :         onceOpts := runOnceFlags.MakeRunOnceOptions()
      26           1 :         t := &mockT{}
      27           1 :         switch {
      28           0 :         case runOnceFlags.Compare != "":
      29           0 :                 testRootDir, runSubdirs := runOnceFlags.ParseCompare()
      30           0 :                 metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs, onceOpts...)
      31             : 
      32           1 :         case runOnceFlags.RunDir != "":
      33           1 :                 // The --run-dir flag is specified either in the child process (see
      34           1 :                 // runOptions() below) or the user specified it manually in order to re-run
      35           1 :                 // a test.
      36           1 :                 metamorphic.RunOnce(t, runOnceFlags.RunDir, runOnceFlags.Seed, filepath.Join(runOnceFlags.RunDir, "history"), onceOpts...)
      37             : 
      38           0 :         default:
      39           0 :                 t.Errorf("--compare or --run-dir must be used")
      40             :         }
      41             : 
      42           1 :         if t.Failed() {
      43           0 :                 // Make sure we return an error code.
      44           0 :                 t.FailNow()
      45           0 :         }
      46             : }
      47             : 
      48             : type mockT struct {
      49             :         failed bool
      50             : }
      51             : 
      52             : var _ metamorphic.TestingT = (*mockT)(nil)
      53             : 
      54           0 : func (t *mockT) Errorf(format string, args ...interface{}) {
      55           0 :         t.failed = true
      56           0 :         fmt.Fprintf(os.Stderr, format+"\n", args...)
      57           0 : }
      58             : 
      59           0 : func (t *mockT) FailNow() {
      60           0 :         os.Exit(2)
      61           0 : }
      62             : 
      63           1 : func (t *mockT) Failed() bool {
      64           1 :         return t.failed
      65           1 : }

Generated by: LCOV version 1.14