mirror of
https://github.com/golang/go
synced 2024-11-26 06:38:00 -07:00
cmd: update x/tools and remove copy of txtar
golang.org/x/tools/txtar is the main location for this package. We don't need our own copy. For golang/go#47193 Change-Id: I480eb591f57a0d05b433a657653e2021e39354eb Reviewed-on: https://go-review.googlesource.com/c/go/+/337352 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/341937
This commit is contained in:
parent
742dcba7bb
commit
54ce8793a8
@ -1,7 +1,6 @@
|
|||||||
package fsys
|
package fsys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cmd/go/internal/txtar"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -12,6 +11,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/tools/txtar"
|
||||||
)
|
)
|
||||||
|
|
||||||
// initOverlay resets the overlay state to reflect the config.
|
// initOverlay resets the overlay state to reflect the config.
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
// 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 txtar
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var tests = []struct {
|
|
||||||
name string
|
|
||||||
text string
|
|
||||||
parsed *Archive
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "basic",
|
|
||||||
text: `comment1
|
|
||||||
comment2
|
|
||||||
-- file1 --
|
|
||||||
File 1 text.
|
|
||||||
-- foo ---
|
|
||||||
More file 1 text.
|
|
||||||
-- file 2 --
|
|
||||||
File 2 text.
|
|
||||||
-- empty --
|
|
||||||
-- noNL --
|
|
||||||
hello world`,
|
|
||||||
parsed: &Archive{
|
|
||||||
Comment: []byte("comment1\ncomment2\n"),
|
|
||||||
Files: []File{
|
|
||||||
{"file1", []byte("File 1 text.\n-- foo ---\nMore file 1 text.\n")},
|
|
||||||
{"file 2", []byte("File 2 text.\n")},
|
|
||||||
{"empty", []byte{}},
|
|
||||||
{"noNL", []byte("hello world\n")},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
a := Parse([]byte(tt.text))
|
|
||||||
if !reflect.DeepEqual(a, tt.parsed) {
|
|
||||||
t.Fatalf("Parse: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
|
|
||||||
}
|
|
||||||
text := Format(a)
|
|
||||||
a = Parse(text)
|
|
||||||
if !reflect.DeepEqual(a, tt.parsed) {
|
|
||||||
t.Fatalf("Parse after Format: wrong output:\nhave:\n%s\nwant:\n%s", shortArchive(a), shortArchive(tt.parsed))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func shortArchive(a *Archive) string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
fmt.Fprintf(&buf, "comment: %q\n", a.Comment)
|
|
||||||
for _, f := range a.Files {
|
|
||||||
fmt.Fprintf(&buf, "file %q: %q\n", f.Name, f.Data)
|
|
||||||
}
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
@ -25,12 +25,12 @@ import (
|
|||||||
|
|
||||||
"cmd/go/internal/modfetch/codehost"
|
"cmd/go/internal/modfetch/codehost"
|
||||||
"cmd/go/internal/par"
|
"cmd/go/internal/par"
|
||||||
"cmd/go/internal/txtar"
|
|
||||||
|
|
||||||
"golang.org/x/mod/module"
|
"golang.org/x/mod/module"
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
"golang.org/x/mod/sumdb"
|
"golang.org/x/mod/sumdb"
|
||||||
"golang.org/x/mod/sumdb/dirhash"
|
"golang.org/x/mod/sumdb/dirhash"
|
||||||
|
"golang.org/x/tools/txtar"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -31,9 +31,10 @@ import (
|
|||||||
"cmd/go/internal/imports"
|
"cmd/go/internal/imports"
|
||||||
"cmd/go/internal/par"
|
"cmd/go/internal/par"
|
||||||
"cmd/go/internal/robustio"
|
"cmd/go/internal/robustio"
|
||||||
"cmd/go/internal/txtar"
|
|
||||||
"cmd/go/internal/work"
|
"cmd/go/internal/work"
|
||||||
"cmd/internal/sys"
|
"cmd/internal/sys"
|
||||||
|
|
||||||
|
"golang.org/x/tools/txtar"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`)
|
var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`)
|
||||||
|
2
src/cmd/go/testdata/addmod.go
vendored
2
src/cmd/go/testdata/addmod.go
vendored
@ -29,7 +29,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cmd/go/internal/txtar"
|
"golang.org/x/tools/txtar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
|
2
src/cmd/go/testdata/savedir.go
vendored
2
src/cmd/go/testdata/savedir.go
vendored
@ -24,7 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"../internal/txtar"
|
"golang.org/x/tools/txtar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
|
@ -34,7 +34,7 @@ package txtar
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ func Format(a *Archive) []byte {
|
|||||||
|
|
||||||
// ParseFile parses the named file as an archive.
|
// ParseFile parses the named file as an archive.
|
||||||
func ParseFile(file string) (*Archive, error) {
|
func ParseFile(file string) (*Archive, error) {
|
||||||
data, err := os.ReadFile(file)
|
data, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ func isMarker(data []byte) (name string, after []byte) {
|
|||||||
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
||||||
data, after = data[:i], data[i+1:]
|
data, after = data[:i], data[i+1:]
|
||||||
}
|
}
|
||||||
if !bytes.HasSuffix(data, markerEnd) {
|
if !(bytes.HasSuffix(data, markerEnd) && len(data) >= len(marker)+len(markerEnd)) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
|
return strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
|
1
src/cmd/vendor/modules.txt
vendored
1
src/cmd/vendor/modules.txt
vendored
@ -93,6 +93,7 @@ golang.org/x/tools/go/types/typeutil
|
|||||||
golang.org/x/tools/internal/analysisinternal
|
golang.org/x/tools/internal/analysisinternal
|
||||||
golang.org/x/tools/internal/lsp/fuzzy
|
golang.org/x/tools/internal/lsp/fuzzy
|
||||||
golang.org/x/tools/internal/typeparams
|
golang.org/x/tools/internal/typeparams
|
||||||
|
golang.org/x/tools/txtar
|
||||||
# golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
|
# golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
|
||||||
## explicit; go 1.11
|
## explicit; go 1.11
|
||||||
golang.org/x/xerrors
|
golang.org/x/xerrors
|
||||||
|
Loading…
Reference in New Issue
Block a user