LCOV - code coverage report
Current view: top level - pebble/internal/metamorphic/metarunner - main.go (source / functions) Hit Total Coverage
Test: 2024-03-11 08:16Z 8df4320c - tests only.lcov Lines: 0 29 0.0 %
Date: 2024-03-11 08:16:47 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           0 : func main() {
      24           0 :         flag.Parse()
      25           0 :         onceOpts := runOnceFlags.MakeRunOnceOptions()
      26           0 :         t := &mockT{}
      27           0 :         switch {
      28           0 :         case runOnceFlags.Compare != "":
      29           0 :                 testRootDir, runSubdirs := runOnceFlags.ParseCompare()
      30           0 :                 metamorphic.Compare(t, testRootDir, runOnceFlags.Seed, runSubdirs, onceOpts...)
      31             : 
      32           0 :         case runOnceFlags.RunDir != "":
      33           0 :                 // The --run-dir flag is specified either in the child process (see
      34           0 :                 // runOptions() below) or the user specified it manually in order to re-run
      35           0 :                 // a test.
      36           0 :                 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           0 :         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           0 : func (t *mockT) Failed() bool {
      64           0 :         return t.failed
      65           0 : }

Generated by: LCOV version 1.14