Source file src/cmd/go/internal/toolchain/toolchain_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  package toolchain
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  func TestNewerToolchain(t *testing.T) {
    13  	for _, tt := range newerToolchainTests {
    14  		out, err := newerToolchain(tt.need, tt.list)
    15  		if (err != nil) != (out == "") {
    16  			t.Errorf("newerToolchain(%v, %v) = %v, %v, want error", tt.need, tt.list, out, err)
    17  			continue
    18  		}
    19  		if out != tt.out {
    20  			t.Errorf("newerToolchain(%v, %v) = %v, %v want %v, nil", tt.need, tt.list, out, err, tt.out)
    21  		}
    22  	}
    23  }
    24  
    25  var f = strings.Fields
    26  
    27  var relRC = []string{"1.39.0", "1.39.1", "1.39.2", "1.40.0", "1.40.1", "1.40.2", "1.41rc1"}
    28  var rel2 = []string{"1.39.0", "1.39.1", "1.39.2", "1.40.0", "1.40.1", "1.40.2"}
    29  var rel0 = []string{"1.39.0", "1.39.1", "1.39.2", "1.40.0"}
    30  var newerToolchainTests = []struct {
    31  	need string
    32  	list []string
    33  	out  string
    34  }{
    35  	{"1.30", rel0, "go1.39.2"},
    36  	{"1.30", rel2, "go1.39.2"},
    37  	{"1.30", relRC, "go1.39.2"},
    38  	{"1.38", rel0, "go1.39.2"},
    39  	{"1.38", rel2, "go1.39.2"},
    40  	{"1.38", relRC, "go1.39.2"},
    41  	{"1.38.1", rel0, "go1.39.2"},
    42  	{"1.38.1", rel2, "go1.39.2"},
    43  	{"1.38.1", relRC, "go1.39.2"},
    44  	{"1.39", rel0, "go1.39.2"},
    45  	{"1.39", rel2, "go1.39.2"},
    46  	{"1.39", relRC, "go1.39.2"},
    47  	{"1.39.2", rel0, "go1.39.2"},
    48  	{"1.39.2", rel2, "go1.39.2"},
    49  	{"1.39.2", relRC, "go1.39.2"},
    50  	{"1.39.3", rel0, "go1.40.0"},
    51  	{"1.39.3", rel2, "go1.40.2"},
    52  	{"1.39.3", relRC, "go1.40.2"},
    53  	{"1.40", rel0, "go1.40.0"},
    54  	{"1.40", rel2, "go1.40.2"},
    55  	{"1.40", relRC, "go1.40.2"},
    56  	{"1.40.1", rel0, ""},
    57  	{"1.40.1", rel2, "go1.40.2"},
    58  	{"1.40.1", relRC, "go1.40.2"},
    59  	{"1.41", rel0, ""},
    60  	{"1.41", rel2, ""},
    61  	{"1.41", relRC, "go1.41rc1"},
    62  	{"1.41.0", rel0, ""},
    63  	{"1.41.0", rel2, ""},
    64  	{"1.41.0", relRC, ""},
    65  	{"1.40", nil, ""},
    66  }
    67  

View as plain text