@@ -42,7 +42,7 @@ type TestTypes struct {
42
42
var prolog = []byte (`
43
43
package constrainttest
44
44
45
- import "constraints"
45
+ import "golang.org/x/exp/ constraints"
46
46
47
47
type (
48
48
testSigned[T constraints.Signed] struct{ f T }
@@ -71,9 +71,40 @@ func TestFailure(t *testing.T) {
71
71
72
72
tmpdir := t .TempDir ()
73
73
74
- if err := os .WriteFile (filepath .Join (tmpdir , "go.mod" ), []byte ("module constraintest" ), 0666 ); err != nil {
74
+ cwd , err := os .Getwd ()
75
+ if err != nil {
75
76
t .Fatal (err )
76
77
}
78
+ // This package is golang.org/x/exp/constraints, so the root of the x/exp
79
+ // module is the parent directory of the directory in which this test runs.
80
+ expModDir := filepath .Dir (cwd )
81
+
82
+ modFile := fmt .Sprintf (`module constraintest
83
+
84
+ go 1.18
85
+
86
+ replace golang.org/x/exp => %s
87
+ ` , expModDir )
88
+ if err := os .WriteFile (filepath .Join (tmpdir , "go.mod" ), []byte (modFile ), 0666 ); err != nil {
89
+ t .Fatal (err )
90
+ }
91
+
92
+ // Write the prolog as its own file so that 'go mod tidy' has something to inspect.
93
+ // This will ensure that the go.mod and go.sum files include any dependencies
94
+ // needed by the constraints package (which should just be some version of
95
+ // x/exp itself).
96
+ if err := os .WriteFile (filepath .Join (tmpdir , "prolog.go" ), []byte (prolog ), 0666 ); err != nil {
97
+ t .Fatal (err )
98
+ }
99
+
100
+ tidyCmd := exec .Command (gocmd , "mod" , "tidy" )
101
+ tidyCmd .Dir = tmpdir
102
+ tidyCmd .Env = append (os .Environ (), "PWD=" + tmpdir )
103
+ if out , err := tidyCmd .CombinedOutput (); err != nil {
104
+ t .Fatalf ("%v: %v\n %s" , tidyCmd , err , out )
105
+ } else {
106
+ t .Logf ("%v:\n %s" , tidyCmd , out )
107
+ }
77
108
78
109
// Test for types that should not satisfy a constraint.
79
110
// For each pair of constraint and type, write a Go file
0 commit comments