]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: update x/tools and remove copy of txtar
authorJay Conrod <jayconrod@google.com>
Mon, 26 Jul 2021 17:39:38 +0000 (10:39 -0700)
committerJay Conrod <jayconrod@google.com>
Mon, 16 Aug 2021 20:23:19 +0000 (20:23 +0000)
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

src/cmd/go/internal/fsys/fsys_test.go
src/cmd/go/internal/txtar/archive_test.go [deleted file]
src/cmd/go/proxy_test.go
src/cmd/go/script_test.go
src/cmd/go/testdata/addmod.go
src/cmd/go/testdata/savedir.go
src/cmd/vendor/golang.org/x/tools/txtar/archive.go [moved from src/cmd/go/internal/txtar/archive.go with 96% similarity]
src/cmd/vendor/modules.txt

index 7f175c7031169dded7b720e9899f7d38909f8d74..c080c14987c37cad5928771d49bb0a4b1b602953 100644 (file)
@@ -1,7 +1,6 @@
 package fsys
 
 import (
-       "cmd/go/internal/txtar"
        "encoding/json"
        "errors"
        "fmt"
@@ -12,6 +11,8 @@ import (
        "path/filepath"
        "reflect"
        "testing"
+
+       "golang.org/x/tools/txtar"
 )
 
 // initOverlay resets the overlay state to reflect the config.
diff --git a/src/cmd/go/internal/txtar/archive_test.go b/src/cmd/go/internal/txtar/archive_test.go
deleted file mode 100644 (file)
index 3f734f6..0000000
+++ /dev/null
@@ -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()
-}
index 74bfecc08dbc6de1ca9768c536113eb878d7f3da..a387fe67dbfc83f227500b24cc9b3130d0fef8bb 100644 (file)
@@ -25,12 +25,12 @@ import (
 
        "cmd/go/internal/modfetch/codehost"
        "cmd/go/internal/par"
-       "cmd/go/internal/txtar"
 
        "golang.org/x/mod/module"
        "golang.org/x/mod/semver"
        "golang.org/x/mod/sumdb"
        "golang.org/x/mod/sumdb/dirhash"
+       "golang.org/x/tools/txtar"
 )
 
 var (
index 8a7c77a46fa0a35fa0fc3789897ca0bdf6c5d30f..3c5855bd6f24cfb088e725a9e1c6ce15b3eb87e1 100644 (file)
@@ -31,9 +31,10 @@ import (
        "cmd/go/internal/imports"
        "cmd/go/internal/par"
        "cmd/go/internal/robustio"
-       "cmd/go/internal/txtar"
        "cmd/go/internal/work"
        "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.`)
index 03869e68defe0845c5cbdef60fa08f2fd3fdf42d..a1ace4ce5907e84c7c21d5c9d4ba0df863d8f305 100644 (file)
@@ -29,7 +29,7 @@ import (
        "path/filepath"
        "strings"
 
-       "cmd/go/internal/txtar"
+       "golang.org/x/tools/txtar"
 )
 
 func usage() {
index d469c31a919821171affd2be2e88b12ef3861de0..6a8a232702f550341efd7351da97295645b28604 100644 (file)
@@ -24,7 +24,7 @@ import (
        "strings"
        "unicode/utf8"
 
-       "../internal/txtar"
+       "golang.org/x/tools/txtar"
 )
 
 func usage() {
similarity index 96%
rename from src/cmd/go/internal/txtar/archive.go
rename to src/cmd/vendor/golang.org/x/tools/txtar/archive.go
index 17966848771b3c16be035a1f583fc0f3e6e70445..214256617b58d479906b70fb2d0027e2541ab303 100644 (file)
@@ -34,7 +34,7 @@ package txtar
 import (
        "bytes"
        "fmt"
-       "os"
+       "io/ioutil"
        "strings"
 )
 
@@ -66,7 +66,7 @@ func Format(a *Archive) []byte {
 
 // ParseFile parses the named file as an archive.
 func ParseFile(file string) (*Archive, error) {
-       data, err := os.ReadFile(file)
+       data, err := ioutil.ReadFile(file)
        if err != nil {
                return nil, err
        }
@@ -121,7 +121,7 @@ func isMarker(data []byte) (name string, after []byte) {
        if i := bytes.IndexByte(data, '\n'); i >= 0 {
                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 strings.TrimSpace(string(data[len(marker) : len(data)-len(markerEnd)])), after
index c98bdcd3440168f4c76f717dc907d3eaf73f4c89..1765e3e1fc1f726cf22074a2061ed61d09c97d06 100644 (file)
@@ -93,6 +93,7 @@ golang.org/x/tools/go/types/typeutil
 golang.org/x/tools/internal/analysisinternal
 golang.org/x/tools/internal/lsp/fuzzy
 golang.org/x/tools/internal/typeparams
+golang.org/x/tools/txtar
 # golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
 ## explicit; go 1.11
 golang.org/x/xerrors