github.com/tencent/goom@v1.0.1/mocker_comp_test.go (about)

     1  package mocker_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/tencent/goom/test"
    10  )
    11  
    12  // TestCompatibility 测试针对不同 go 版本的兼容情况
    13  func TestCompatibility(t *testing.T) {
    14  	if os.Getenv(testEnv) == "true" {
    15  		return
    16  	}
    17  
    18  	os.Setenv(testEnv, "true")
    19  	for _, v := range versions {
    20  		fmt.Printf("> [%s] start testing..\n", v)
    21  		if err := test.Run(v, nil, "version"); err != nil {
    22  			t.Errorf("[%s] env prepare fail: %v", v, err)
    23  		}
    24  
    25  		logHandler := func(log string) {
    26  			if strings.Contains(log, "--- FAIL:") {
    27  				t.Errorf("[%s] run fail: see details in the log above.", v)
    28  			}
    29  		}
    30  		if err := test.Run(v, logHandler, "test", "-v", "-gcflags=all=-l", "."); err != nil {
    31  			t.Errorf("[%s] run error: %v, see details in the log above.", v, err)
    32  		}
    33  		if t.Failed() {
    34  			break
    35  		}
    36  		t.Logf("[%s] testing success.", v)
    37  	}
    38  }