github.com/ipld/go-ipld-prime@v0.21.0/schema/gen/go/testEngine_disabled_test.go (about)

     1  //go:build skipgenbehavtests || windows
     2  
     3  package gengo
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"os"
     9  	"os/exec"
    10  	"path/filepath"
    11  	"runtime"
    12  	"testing"
    13  
    14  	"github.com/ipld/go-ipld-prime/datamodel"
    15  )
    16  
    17  func buildGennedCode(t *testing.T, prefix string, pkgName string) {
    18  	// Emit a small file with a 'main' method.
    19  	//  'go build' doesn't like it we're in a package called "main" and there isn't one
    20  	//   (and at the same time, plugins demand that they be in a package called 'main',
    21  	//    so 'pkgName' in practice is almost always "main").
    22  	//  I dunno, friend.  I didn't write the rules.
    23  	if pkgName == "main" {
    24  		withFile(filepath.Join(tmpGenBuildDir, prefix, "main.go"), func(w io.Writer) {
    25  			fmt.Fprintf(w, "package %s\n\n", pkgName)
    26  			fmt.Fprintf(w, "func main() {}\n")
    27  		})
    28  	}
    29  
    30  	// If windows, remove all files in tmpGenBuildDir with the .exe extension so we don't get a "already exists" error
    31  	// https://github.com/golang/go/issues/57039
    32  	if runtime.GOOS == "windows" {
    33  		files, err := filepath.Glob(filepath.Join(tmpGenBuildDir, prefix, "*.exe"))
    34  		if err != nil {
    35  			t.Fatal(err)
    36  		}
    37  		for _, file := range files {
    38  			if err := os.Remove(file); err != nil {
    39  				t.Fatal(err)
    40  			}
    41  		}
    42  	}
    43  
    44  	// Invoke 'go build' -- nothing fancy.
    45  	files, err := filepath.Glob(filepath.Join(tmpGenBuildDir, prefix, "*.go"))
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	args := []string{"build"}
    50  	args = append(args, files...)
    51  	cmd := exec.Command("go", args...)
    52  	cmd.Stdout = os.Stdout
    53  	cmd.Stderr = os.Stderr
    54  	err = cmd.Run()
    55  	if err != nil {
    56  		t.Fatalf("genned code failed to compile: %s", err)
    57  	}
    58  
    59  	t.Skip("behavioral tests for generated code skipped: you used the 'skipgenbehavtests' build tag.")
    60  }
    61  
    62  func fnPrototypeByName(prefix string) func(string) datamodel.NodePrototype {
    63  	return nil // unused
    64  }