Source file src/runtime/import_test.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file and importx_test.go make it possible to write tests in the runtime
     6  // package, which is generally more convenient for testing runtime internals.
     7  // For tests that mostly touch public APIs, it's generally easier to write them
     8  // in the runtime_test package and export any runtime internals via
     9  // export_test.go.
    10  //
    11  // There are a few limitations on runtime package tests that this bridges:
    12  //
    13  // 1. Tests use the signature "XTest<name>(t TestingT)". Since runtime can't import
    14  // testing, test functions can't use testing.T, so instead we have the T
    15  // interface, which *testing.T satisfies. And we start names with "XTest"
    16  // because otherwise go test will complain about Test functions with the wrong
    17  // signature. To actually expose these as test functions, this file contains
    18  // trivial wrappers.
    19  //
    20  // 2. Runtime package tests can't directly import other std packages, so we
    21  // inject any necessary functions from std.
    22  
    23  // TODO: Generate this
    24  
    25  package runtime_test
    26  
    27  import (
    28  	"fmt"
    29  	"internal/testenv"
    30  	"runtime"
    31  	"testing"
    32  )
    33  
    34  func init() {
    35  	runtime.FmtSprintf = fmt.Sprintf
    36  	runtime.TestenvOptimizationOff = testenv.OptimizationOff
    37  }
    38  
    39  func TestInlineUnwinder(t *testing.T) {
    40  	runtime.XTestInlineUnwinder(t)
    41  }
    42  
    43  func TestSPWrite(t *testing.T) {
    44  	runtime.XTestSPWrite(t)
    45  }
    46  

View as plain text