Commit 6140829e authored by Russ Cox's avatar Russ Cox

cmd/go: convert still more module tests to scripts

Change-Id: I249bb848c9911948dbd84cd88ad043a61ed6ea6b
Reviewed-on: https://go-review.googlesource.com/124699Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent e3f15e3b
This diff is collapsed.
......@@ -569,7 +569,9 @@ func scriptMatch(ts *testScript, neg bool, args []string, text, name string) {
re, err := regexp.Compile(`(?m)` + pattern)
ts.check(err)
if name == "grep" {
isGrep := name == "grep"
if isGrep {
name = args[1] // for error messages
data, err := ioutil.ReadFile(ts.mkabs(args[1]))
ts.check(err)
text = string(data)
......@@ -577,15 +579,24 @@ func scriptMatch(ts *testScript, neg bool, args []string, text, name string) {
if neg {
if re.MatchString(text) {
ts.fatalf("unexpected match for %#q found in %s: %s %q", pattern, name, text, re.FindString(text))
if isGrep {
fmt.Fprintf(&ts.log, "[%s]\n%s\n", name, text)
}
ts.fatalf("unexpected match for %#q found in %s: %s", pattern, name, re.FindString(text))
}
} else {
if !re.MatchString(text) {
if isGrep {
fmt.Fprintf(&ts.log, "[%s]\n%s\n", name, text)
}
ts.fatalf("no match for %#q found in %s", pattern, name)
}
if n > 0 {
count := len(re.FindAllString(text, -1))
if count != n {
if isGrep {
fmt.Fprintf(&ts.log, "[%s]\n%s\n", name, text)
}
ts.fatalf("have %d matches for %#q, want %d", count, pattern, n)
}
}
......
generated by: go run savedir.go .
-- LICENSE --
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- README.md --
This package collects pithy sayings.
It's part of a demonstration of
[package versioning in Go](https://research.swtch.com/vgo1).
-- buggy/buggy_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buggy
import "testing"
func Test(t *testing.T) {
t.Fatal("buggy!")
}
-- go.mod --
module rsc.io/quote
require rsc.io/sampler v1.3.0
-- quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/quote/v2"
// Hello returns a greeting.
func Hello() string {
return quote.HelloV2()
}
// Glass returns a useful phrase for world travelers.
func Glass() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return quote.GlassV2()
}
// Go returns a Go proverb.
func Go() string {
return quote.GoV2()
}
// Opt returns an optimization truth.
func Opt() string {
// Wisdom from ken.
return quote.OptV2()
}
-- quote_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quote
import (
"os"
"testing"
)
func init() {
os.Setenv("LC_ALL", "en")
}
func TestHello(t *testing.T) {
hello := "Hello, world."
if out := Hello(); out != hello {
t.Errorf("Hello() = %q, want %q", out, hello)
}
}
func TestGlass(t *testing.T) {
glass := "I can eat glass and it doesn't hurt me."
if out := Glass(); out != glass {
t.Errorf("Glass() = %q, want %q", out, glass)
}
}
func TestGo(t *testing.T) {
go1 := "Don't communicate by sharing memory, share memory by communicating."
if out := Go(); out != go1 {
t.Errorf("Go() = %q, want %q", out, go1)
}
}
func TestOpt(t *testing.T) {
opt := "If a program is too slow, it must have a loop."
if out := Opt(); out != opt {
t.Errorf("Opt() = %q, want %q", out, opt)
}
}
-- v3/go.mod --
module rsc.io/quote/v3
require rsc.io/sampler v1.3.0
-- v3/go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/sampler v1.99.99 h1:7i08f/p5TBU5joCPW3GjWG1ZFCmr28ybGqlXtelhEK8=
rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- v3/quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/sampler"
// Hello returns a greeting.
func HelloV3() string {
return sampler.Hello()
}
// Glass returns a useful phrase for world travelers.
func GlassV3() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return "I can eat glass and it doesn't hurt me."
}
// Go returns a Go proverb.
func GoV3() string {
return "Don't communicate by sharing memory, share memory by communicating."
}
// Opt returns an optimization truth.
func OptV3() string {
// Wisdom from ken.
return "If a program is too slow, it must have a loop."
}
generated by: go run savedir.go .
-- LICENSE --
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- README.md --
This package collects pithy sayings.
It's part of a demonstration of
[package versioning in Go](https://research.swtch.com/vgo1).
-- buggy/buggy_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buggy
import "testing"
func Test(t *testing.T) {
t.Fatal("buggy!")
}
-- go.mod --
module rsc.io/quote
require (
rsc.io/quote/v3 v3.0.0
rsc.io/sampler v1.3.0
)
-- quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/quote/v3"
// Hello returns a greeting.
func Hello() string {
return quote.HelloV3()
}
// Glass returns a useful phrase for world travelers.
func Glass() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return quote.GlassV3()
}
// Go returns a Go proverb.
func Go() string {
return quote.GoV3()
}
// Opt returns an optimization truth.
func Opt() string {
// Wisdom from ken.
return quote.OptV3()
}
-- quote_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quote
import (
"os"
"testing"
)
func init() {
os.Setenv("LC_ALL", "en")
}
func TestHello(t *testing.T) {
hello := "Hello, world."
if out := Hello(); out != hello {
t.Errorf("Hello() = %q, want %q", out, hello)
}
}
func TestGlass(t *testing.T) {
glass := "I can eat glass and it doesn't hurt me."
if out := Glass(); out != glass {
t.Errorf("Glass() = %q, want %q", out, glass)
}
}
func TestGo(t *testing.T) {
go1 := "Don't communicate by sharing memory, share memory by communicating."
if out := Go(); out != go1 {
t.Errorf("Go() = %q, want %q", out, go1)
}
}
func TestOpt(t *testing.T) {
opt := "If a program is too slow, it must have a loop."
if out := Opt(); out != opt {
t.Errorf("Opt() = %q, want %q", out, opt)
}
}
-- v3/go.mod --
module rsc.io/quote/v3
require rsc.io/sampler v1.3.0
-- v3/go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/sampler v1.99.99 h1:7i08f/p5TBU5joCPW3GjWG1ZFCmr28ybGqlXtelhEK8=
rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- v3/quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/sampler"
// Hello returns a greeting.
func HelloV3() string {
return sampler.Hello()
generated by: go run savedir.go .
-- LICENSE --
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- README.md --
This package collects pithy sayings.
It's part of a demonstration of
[package versioning in Go](https://research.swtch.com/vgo1).
-- buggy/buggy_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buggy
import "testing"
func Test(t *testing.T) {
t.Fatal("buggy!")
}
-- go.mod --
module rsc.io/quote
require rsc.io/sampler v1.3.0
-- quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/quote/v3"
// Hello returns a greeting.
func Hello() string {
return quote.HelloV3()
}
// Glass returns a useful phrase for world travelers.
func Glass() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return quote.GlassV3()
}
// Go returns a Go proverb.
func Go() string {
return quote.GoV3()
}
// Opt returns an optimization truth.
func Opt() string {
// Wisdom from ken.
return quote.OptV3()
}
-- quote_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quote
import (
"os"
"testing"
)
func init() {
os.Setenv("LC_ALL", "en")
}
func TestHello(t *testing.T) {
hello := "Hello, world."
if out := Hello(); out != hello {
t.Errorf("Hello() = %q, want %q", out, hello)
}
}
func TestGlass(t *testing.T) {
glass := "I can eat glass and it doesn't hurt me."
if out := Glass(); out != glass {
t.Errorf("Glass() = %q, want %q", out, glass)
}
}
func TestGo(t *testing.T) {
go1 := "Don't communicate by sharing memory, share memory by communicating."
if out := Go(); out != go1 {
t.Errorf("Go() = %q, want %q", out, go1)
}
}
func TestOpt(t *testing.T) {
opt := "If a program is too slow, it must have a loop."
if out := Opt(); out != opt {
t.Errorf("Opt() = %q, want %q", out, opt)
}
}
-- v3/go.mod --
module rsc.io/quote/v3
require rsc.io/sampler v1.3.0
-- v3/go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/sampler v1.99.99 h1:7i08f/p5TBU5joCPW3GjWG1ZFCmr28ybGqlXtelhEK8=
rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- v3/quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/sampler"
// Hello returns a greeting.
func HelloV3() string {
return sampler.Hello()
generated by: go run savedir.go .
-- LICENSE --
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- README.md --
This package collects pithy sayings.
It's part of a demonstration of
[package versioning in Go](https://research.swtch.com/vgo1).
-- buggy/buggy_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buggy
import "testing"
func Test(t *testing.T) {
t.Fatal("buggy!")
}
-- go.mod --
module rsc.io/quote
require (
rsc.io/quote/v2 v2.0.1
rsc.io/sampler v1.3.0
)
-- quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/quote/v2"
// Hello returns a greeting.
func Hello() string {
return quote.HelloV2()
}
// Glass returns a useful phrase for world travelers.
func Glass() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return quote.GlassV2()
}
// Go returns a Go proverb.
func Go() string {
return quote.GoV2()
}
// Opt returns an optimization truth.
func Opt() string {
// Wisdom from ken.
return quote.OptV2()
}
-- quote_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quote
import (
"os"
"testing"
)
func init() {
os.Setenv("LC_ALL", "en")
}
func TestHello(t *testing.T) {
hello := "Hello, world."
if out := Hello(); out != hello {
t.Errorf("Hello() = %q, want %q", out, hello)
}
}
func TestGlass(t *testing.T) {
glass := "I can eat glass and it doesn't hurt me."
if out := Glass(); out != glass {
t.Errorf("Glass() = %q, want %q", out, glass)
}
}
func TestGo(t *testing.T) {
go1 := "Don't communicate by sharing memory, share memory by communicating."
if out := Go(); out != go1 {
t.Errorf("Go() = %q, want %q", out, go1)
}
}
func TestOpt(t *testing.T) {
opt := "If a program is too slow, it must have a loop."
if out := Opt(); out != opt {
t.Errorf("Opt() = %q, want %q", out, opt)
}
}
-- v3/go.mod --
module rsc.io/quote/v3
require rsc.io/sampler v1.3.0
-- v3/go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/sampler v1.99.99 h1:7i08f/p5TBU5joCPW3GjWG1ZFCmr28ybGqlXtelhEK8=
rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- v3/quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/sampler"
// Hello returns a greeting.
func HelloV3() string {
return sampler.Hello()
}
// Glass returns a useful phrase for world travelers.
func GlassV3() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return "I can eat glass and it doesn't hurt me."
}
// Go returns a Go proverb.
func GoV3() string {
return "Don't communicate by sharing memory, share memory by communicating."
}
// Opt returns an optimization truth.
func OptV3() string {
// Wisdom from ken.
return "If a program is too slow, it must have a loop."
}
generated by: go run savedir.go .
-- LICENSE --
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- README.md --
This package collects pithy sayings.
It's part of a demonstration of
[package versioning in Go](https://research.swtch.com/vgo1).
-- buggy/buggy_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buggy
import "testing"
func Test(t *testing.T) {
t.Fatal("buggy!")
}
-- go.mod --
module rsc.io/quote
require (
rsc.io/quote/v2 v2.0.1
rsc.io/sampler v1.3.0
)
-- quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/quote/v2"
// Hello returns a greeting.
func Hello() string {
return quote.HelloV2()
}
// Glass returns a useful phrase for world travelers.
func Glass() string {
// See http://www.oocities.org/nodotus/hbglass.html.
return quote.GlassV2()
}
// Go returns a Go proverb.
func Go() string {
return quote.GoV2()
}
// Opt returns an optimization truth.
func Opt() string {
// Wisdom from ken.
return quote.OptV2()
}
-- quote_test.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quote
import (
"os"
"testing"
)
func init() {
os.Setenv("LC_ALL", "en")
}
func TestHello(t *testing.T) {
hello := "Hello, world."
if out := Hello(); out != hello {
t.Errorf("Hello() = %q, want %q", out, hello)
}
}
func TestGlass(t *testing.T) {
glass := "I can eat glass and it doesn't hurt me."
if out := Glass(); out != glass {
t.Errorf("Glass() = %q, want %q", out, glass)
}
}
func TestGo(t *testing.T) {
go1 := "Don't communicate by sharing memory, share memory by communicating."
if out := Go(); out != go1 {
t.Errorf("Go() = %q, want %q", out, go1)
}
}
func TestOpt(t *testing.T) {
opt := "If a program is too slow, it must have a loop."
if out := Opt(); out != opt {
t.Errorf("Opt() = %q, want %q", out, opt)
}
}
-- v3/go.mod --
module rsc.io/quote/v3
require rsc.io/sampler v1.3.0
-- v3/go.sum --
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
rsc.io/sampler v1.99.99 h1:7i08f/p5TBU5joCPW3GjWG1ZFCmr28ybGqlXtelhEK8=
rsc.io/sampler v1.99.99/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
-- v3/quote.go --
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package quote collects pithy sayings.
package quote // import "rsc.io/quote"
import "rsc.io/sampler"
// Hello returns a greeting.
func HelloV3() string {
return sampler.Hello()
......@@ -2,21 +2,21 @@
env GO111MODULE=on
env GOPATH=$WORK/gopath1
cd $WORK/x
! go list -getmode=local all
go list all
go list -getmode=local all
! go list -getmode=local
go list
go list -getmode=local
env GOPROXY=file:///nonexist
go list -getmode=local all
go list -getmode=local
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list
# Use download cache as file:/// proxy.
env GOPATH=$WORK/gopath2
env GOPROXY=file:///nonexist
! go list -getmode=local all
! go list all
! go list -getmode=local
! go list
env GOPROXY=file://$WORK/gopath1/src/mod/cache/download
! go list -getmode=local all
go list all
! go list -getmode=local
go list
grep v1.5.1 $GOPATH/src/mod/cache/download/rsc.io/quote/@v/list
-- $WORK/x/go.mod --
......
env GO111MODULE=on
# @commit should resolve
# go get should skip build with no Go files in root
go get golang.org/x/text@14c0d48
# ... and go get should skip build with -m
go get -m golang.org/x/text@14c0d48
# golang.org/x/text/language@commit should not resolve with -m,
# because that's not a module path.
! go get -m golang.org/x/text/language@14c0d48
# ... but it should work without -m.
# because of -d, the compiler should not run
go get -d -x golang.org/x/text/language@14c0d48
! stderr 'compile|cp|gccgo .*language\.a$'
# dropping -d, we should see a build.
go get -x golang.org/x/text/language@14c0d48
stderr 'compile|cp|gccgo .*language\.a$'
# even with -d, we should see an error for unknown packages.
! go get -d -x golang.org/x/text/foo@14c0d48
# get pseudo-version should record that version
go get rsc.io/quote@v0.0.0-20180214005840-23179ee8a569
grep 'rsc.io/quote v0.0.0-20180214005840-23179ee8a569' go.mod
# but as commit should record as v1.5.1
go get rsc.io/quote@23179ee8
grep 'rsc.io/quote v1.5.1' go.mod
# go mod -require does not interpret commits
go mod -require rsc.io/quote@23179ee
grep 'rsc.io/quote 23179ee' go.mod
# but go mod -fix fixes them
go mod -fix
grep 'rsc.io/quote v1.5.1' go.mod
-- go.mod --
module x
env GO111MODULE=on
go get rsc.io/quote@v2.0.0
go list -m all
stdout 'rsc.io/quote v0.0.0-'
-- go.mod --
module x
require rsc.io/quote v1.5.1
-- x.go --
package x
env GO111MODULE=on
# get -u should find quote v1.5.2
go get -u
go list -m all
stdout 'quote v1.5.2$'
grep 'rsc.io/quote v1.5.2$' go.mod
# it should also update x/text later than requested by v1.5.2
go list -m -f '{{.Path}} {{.Version}}{{if .Indirect}} // indirect{{end}}' all
stdout '^golang.org/x/text [v0-9a-f\.-]+ // indirect'
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod
# indirect tag should be removed upon seeing direct import
cp $WORK/tmp/usetext.go x.go
go list
grep 'rsc.io/quote v1.5.2$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod
# indirect tag should be added by go mod -sync
cp $WORK/tmp/usequote.go x.go
go mod -sync
grep 'rsc.io/quote v1.5.2$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod
# requirement should be dropped entirely if not needed
cp $WORK/tmp/usetext.go x.go
go mod -sync
! grep rsc.io/quote go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+$' go.mod
-- go.mod --
module x
require rsc.io/quote v1.5.1
-- x.go --
package x
-- $WORK/tmp/usetext.go --
package x
import _ "golang.org/x/text"
-- $WORK/tmp/usequote.go --
package x
import _ "rsc.io/quote"
env GO111MODULE=on
go get rsc.io/quote@v1.5.1
go list -m all
stdout 'rsc.io/quote v1.5.1'
grep 'rsc.io/quote v1.5.1$' go.mod
# get -u should update all dependencies
go get -u
grep 'rsc.io/quote v1.5.2$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod
# get -u rsc.io/sampler should update only sampler's dependencies
cp go.mod-v1.5.1 go.mod
go get -u rsc.io/sampler
grep 'rsc.io/quote v1.5.1$' go.mod
grep 'golang.org/x/text [v0-9a-f\.-]+ // indirect' go.mod
# move to a pseudo-version after any tags
go get -m rsc.io/quote@dd9747d
grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod
# get -u should not jump off newer pseudo-version to earlier tag
go get -m -u
grep 'rsc.io/quote v0.0.0-20180628003336-dd9747d19b04' go.mod
# move to earlier pseudo-version
go get -m rsc.io/quote@e7a685a342
grep 'rsc.io/quote v0.0.0-20180214005133-e7a685a342c0' go.mod
# get -u should jump off earlier pseudo-version to newer tag
go get -m -u
grep 'rsc.io/quote v1.5.2' go.mod
-- go.mod --
module x
require rsc.io/quote v1.1.0
-- go.mod-v1.5.1 --
module x
require rsc.io/quote v1.5.1
env GO111MODULE=on
go get -m rsc.io/quote@v1.5.1
go mod -vendor
env GOPATH=$WORK/empty
env GOPROXY=file:///nonexist
go list -getmode=vendor
go list -getmode=vendor -m -f '{{.Path}} {{.Version}} {{.Dir}}' all
stdout '^rsc.io/quote v1.5.1 .*vendor[\\/]rsc.io[\\/]quote$'
stdout '^golang.org/x/text v0.0.0.* .*vendor[\\/]golang.org[\\/]x[\\/]text$'
! go list -getmode=vendor -m rsc.io/quote@latest
stderr 'module lookup disabled by -getmode=vendor'
! go get -getmode=vendor -u
stderr 'go get: disabled by -getmode=vendor'
-- go.mod --
module x
-- x.go --
package x
import _ "rsc.io/quote"
env GO111MODULE=on
# latest rsc.io/quote should be v1.5.2 not v1.5.3-pre1
go list
go list -m all
stdout 'rsc.io/quote v1.5.2'
# but v1.5.3-pre1 should be a known version
go list -m -versions rsc.io/quote
stdout '^rsc.io/quote v1.0.0 v1.1.0 v1.2.0 v1.2.1 v1.3.0 v1.4.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3-pre1$'
-- go.mod --
module x
-- x.go --
package x
import _ "rsc.io/quote"
env GO111MODULE=on
go list -m -u all
stdout 'rsc.io/quote v1.2.0 \[v1\.5\.2\]'
-- go.mod --
module x
require rsc.io/quote v1.2.0
env GO111MODULE=on
# initial standalone module should use no downloaded modules
go list -deps -f {{.Dir}}
! stdout 'src[\\/]mod'
# v2 import should use a downloaded module
# both without an explicit go.mod entry ...
cp tmp/use_v2.go x.go
go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
# ... and with one ...
cp tmp/use_v2.mod go.mod
go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
# ... and even if there is a v2 module in a subdirectory.
mkdir v2
cp x.go v2/x.go
cp tmp/v2.mod v2/go.mod
go list -deps -f {{.Dir}}
stdout 'src[\\/]mod[\\/]rsc.io[\\/]quote[\\/]v2@v2.0.1$'
-- go.mod --
module rsc.io/quote
-- x.go --
package quote
-- tmp/use_v2.go --
package quote
import _ "rsc.io/quote/v2"
-- tmp/use_v2.mod --
module rsc.io/quote
require rsc.io/quote/v2 v2.0.1
-- tmp/v2.mod --
package rsc.io/quote/v2
env GO111MODULE=on
go list -m -versions rsc.io/quote
stdout '^rsc.io/quote v1.0.0 v1.1.0 v1.2.0 v1.2.1 v1.3.0 v1.4.0 v1.5.0 v1.5.1 v1.5.2 v1.5.3-pre1$'
# latest rsc.io/quote should be v1.5.2 not v1.5.3-pre1
go list -m rsc.io/quote@latest
stdout 'rsc.io/quote v1.5.2$'
go list -m rsc.io/quote@>v1.5.2
stdout 'rsc.io/quote v1.5.3-pre1$'
go list -m rsc.io/quote@<v1.5.4
stdout 'rsc.io/quote v1.5.2$'
! go list -m rsc.io/quote@>v1.5.3
stderr 'go list -m rsc.io/quote: no matching versions for query ">v1.5.3"'
go list -m -e -f '{{.Error.Err}}' rsc.io/quote@>v1.5.3
stdout 'no matching versions for query ">v1.5.3"'
-- go.mod --
module x
require rsc.io/quote v1.0.0
env GO111MODULE=on
go list -m all
stdout '^rsc.io/quote v1.4.0'
stdout '^rsc.io/sampler v1.0.0'
# get -u=patch rsc.io/quote should take latest quote & patch update its deps
go get -m -u=patch rsc.io/quote
go list -m all
stdout '^rsc.io/quote v1.5.2'
stdout '^rsc.io/sampler v1.3.1'
stdout '^golang.org/x/text v0.0.0-'
# get -u=patch quote@v1.2.0 should take that version of quote & patch update its deps
go get -m -u=patch rsc.io/quote@v1.2.0
go list -m all
stdout '^rsc.io/quote v1.2.0'
stdout '^rsc.io/sampler v1.3.1'
stdout '^golang.org/x/text v0.0.0-'
# get -u=patch with no args applies to all deps
go get -m -u=patch
go list -m all
stdout '^rsc.io/quote v1.2.1'
-- go.mod --
module x
require rsc.io/quote v1.4.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment