Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 9843c2f12c2a9c3e4943d84697c2b2298e78877e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,472 +0,0 @@ |
| 1 |
-// +build ignore |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "bufio" |
|
| 7 |
- "bytes" |
|
| 8 |
- "errors" |
|
| 9 |
- "flag" |
|
| 10 |
- "fmt" |
|
| 11 |
- "go/format" |
|
| 12 |
- "io/ioutil" |
|
| 13 |
- "os" |
|
| 14 |
- "os/exec" |
|
| 15 |
- "path/filepath" |
|
| 16 |
- "regexp" |
|
| 17 |
- "strings" |
|
| 18 |
- "sync" |
|
| 19 |
-) |
|
| 20 |
- |
|
| 21 |
-var ( |
|
| 22 |
- shouldCommit = flag.Bool("commit", false, "if set, each step will result in a commit")
|
|
| 23 |
- filter = flag.String("filter", "", "only run on files matching filter")
|
|
| 24 |
- titlePrefix = flag.String("prefix", "rm-gocheck: ", "commit title prefix")
|
|
| 25 |
- allFiles []string |
|
| 26 |
- fileToCmp = map[string]string{}
|
|
| 27 |
- cmps = map[string][]string{}
|
|
| 28 |
-) |
|
| 29 |
- |
|
| 30 |
-type action func(*step) string |
|
| 31 |
- |
|
| 32 |
-type step struct {
|
|
| 33 |
- files []string |
|
| 34 |
- pkgs map[string]string |
|
| 35 |
- |
|
| 36 |
- title string |
|
| 37 |
- pattern string |
|
| 38 |
- action action |
|
| 39 |
- comment string |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 |
-func mustSh(format string, args ...interface{}) (output []string) {
|
|
| 43 |
- var err error |
|
| 44 |
- output, err = sh(format, args...) |
|
| 45 |
- if err != nil {
|
|
| 46 |
- panic(err) |
|
| 47 |
- } |
|
| 48 |
- return |
|
| 49 |
-} |
|
| 50 |
- |
|
| 51 |
-func sh(format string, args ...interface{}) (output []string, err error) {
|
|
| 52 |
- cmdargs := fmt.Sprintf(format, args...) |
|
| 53 |
- out, err := exec.Command("sh", "-c", cmdargs).CombinedOutput()
|
|
| 54 |
- if err != nil {
|
|
| 55 |
- return nil, fmt.Errorf("cmd=%s\nout=%s\n", cmdargs, out)
|
|
| 56 |
- } |
|
| 57 |
- l := strings.Split(string(out), "\n") |
|
| 58 |
- // remove last element if empty |
|
| 59 |
- if len(l[len(l)-1]) == 0 {
|
|
| 60 |
- l = l[:len(l)-1] |
|
| 61 |
- } |
|
| 62 |
- return l, nil |
|
| 63 |
-} |
|
| 64 |
- |
|
| 65 |
-func listToArgs(l []string) string {
|
|
| 66 |
- s := fmt.Sprintf("%q", l)
|
|
| 67 |
- s = s[1 : len(s)-1] |
|
| 68 |
- return s |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 |
-func Replace(subst string) action {
|
|
| 72 |
- return func(s *step) string {
|
|
| 73 |
- return fmt.Sprintf("sed -E -i 's#%s#%s#g' \\\n-- %s", s.pattern, subst, listToArgs(s.files))
|
|
| 74 |
- } |
|
| 75 |
-} |
|
| 76 |
- |
|
| 77 |
-func CmpReplace(subst string) action {
|
|
| 78 |
- return func(s *step) string {
|
|
| 79 |
- var allCmdArgs, filesNeedingCmpImport []string |
|
| 80 |
- for _, file := range s.files {
|
|
| 81 |
- cmp, ok := fileToCmp[file] |
|
| 82 |
- if !ok {
|
|
| 83 |
- cmp = "cmp" |
|
| 84 |
- l := mustSh(`grep -m 1 -F '"gotest.tools/assert/cmp"' %s | awk '{print $1}'`, file)
|
|
| 85 |
- if len(l) > 0 {
|
|
| 86 |
- cmp = l[0] |
|
| 87 |
- } else {
|
|
| 88 |
- filesNeedingCmpImport = append(filesNeedingCmpImport, file) |
|
| 89 |
- } |
|
| 90 |
- fileToCmp[file] = cmp |
|
| 91 |
- cmps[cmp] = append(cmps[cmp], file) |
|
| 92 |
- } |
|
| 93 |
- } |
|
| 94 |
- |
|
| 95 |
- if len(filesNeedingCmpImport) > 0 {
|
|
| 96 |
- linesep := " \\\n" |
|
| 97 |
- importCmd := fmt.Sprintf(`sed -E -i '0,/^import "github\.com/ s/^(import "github\.com.*)/\1\nimport "gotest.tools\/assert\/cmp")/'%s-- %s`, linesep, listToArgs(filesNeedingCmpImport)) |
|
| 98 |
- allCmdArgs = append(allCmdArgs, importCmd) |
|
| 99 |
- importCmd = fmt.Sprintf(`sed -E -i '0,/^\t+"github\.com/ s/(^\t+"github\.com.*)/\1\n"gotest.tools\/assert\/cmp"/'%s-- %s`, linesep, listToArgs(filesNeedingCmpImport)) |
|
| 100 |
- allCmdArgs = append(allCmdArgs, importCmd) |
|
| 101 |
- } |
|
| 102 |
- |
|
| 103 |
- for cmp, files := range cmps {
|
|
| 104 |
- cmdargs := fmt.Sprintf("sed -E -i 's#%s#%s#g' \\\n-- %s", s.pattern, strings.ReplaceAll(subst, "${cmp}", cmp), listToArgs(files))
|
|
| 105 |
- allCmdArgs = append(allCmdArgs, cmdargs) |
|
| 106 |
- } |
|
| 107 |
- return strings.Join(allCmdArgs, " \\\n&& \\\n") |
|
| 108 |
- } |
|
| 109 |
-} |
|
| 110 |
- |
|
| 111 |
-func redress(pattern string, files ...string) error {
|
|
| 112 |
- rgx, err := regexp.Compile(pattern) |
|
| 113 |
- if err != nil {
|
|
| 114 |
- return err |
|
| 115 |
- } |
|
| 116 |
- if len(files) == 0 {
|
|
| 117 |
- return errors.New("no files provided")
|
|
| 118 |
- } |
|
| 119 |
- fn := func(file string) error {
|
|
| 120 |
- f, err := os.Open(file) |
|
| 121 |
- if err != nil {
|
|
| 122 |
- return err |
|
| 123 |
- } |
|
| 124 |
- defer f.Close() |
|
| 125 |
- |
|
| 126 |
- tmpName := file + ".tmp" |
|
| 127 |
- fixed, err := os.Create(tmpName) |
|
| 128 |
- if err != nil {
|
|
| 129 |
- return err |
|
| 130 |
- } |
|
| 131 |
- defer fixed.Close() |
|
| 132 |
- |
|
| 133 |
- const ( |
|
| 134 |
- searching = iota |
|
| 135 |
- found |
|
| 136 |
- line_done |
|
| 137 |
- ) |
|
| 138 |
- state := searching |
|
| 139 |
- s := bufio.NewScanner(f) |
|
| 140 |
- for s.Scan() {
|
|
| 141 |
- b := s.Bytes() |
|
| 142 |
- if state != found {
|
|
| 143 |
- bb := bytes.TrimRight(b, " \t") |
|
| 144 |
- if state == line_done && len(bb) == 0 {
|
|
| 145 |
- continue |
|
| 146 |
- } |
|
| 147 |
- state = searching |
|
| 148 |
- if !rgx.Match(b) {
|
|
| 149 |
- fixed.Write(b) |
|
| 150 |
- fixed.Write([]byte{'\n'})
|
|
| 151 |
- } else {
|
|
| 152 |
- fixed.Write(bb) |
|
| 153 |
- fixed.Write([]byte{' '})
|
|
| 154 |
- state = found |
|
| 155 |
- } |
|
| 156 |
- continue |
|
| 157 |
- } |
|
| 158 |
- b = bytes.TrimRight(b, " \t") |
|
| 159 |
- fixed.Write(b) |
|
| 160 |
- if len(b) > 0 {
|
|
| 161 |
- switch b[len(b)-1] {
|
|
| 162 |
- case ',', '(':
|
|
| 163 |
- fixed.Write([]byte{' '})
|
|
| 164 |
- continue |
|
| 165 |
- case ')': |
|
| 166 |
- fixed.Write([]byte{'\n'})
|
|
| 167 |
- state = line_done |
|
| 168 |
- } |
|
| 169 |
- } |
|
| 170 |
- } |
|
| 171 |
- if err := s.Err(); err != nil {
|
|
| 172 |
- return err |
|
| 173 |
- } |
|
| 174 |
- |
|
| 175 |
- fixed.Close() |
|
| 176 |
- f.Close() |
|
| 177 |
- src, err := ioutil.ReadFile(tmpName) |
|
| 178 |
- if err != nil {
|
|
| 179 |
- return err |
|
| 180 |
- } |
|
| 181 |
- src, err = format.Source(src) |
|
| 182 |
- if err != nil {
|
|
| 183 |
- return err |
|
| 184 |
- } |
|
| 185 |
- os.Remove(tmpName) |
|
| 186 |
- return ioutil.WriteFile(file, src, 0644) |
|
| 187 |
- } |
|
| 188 |
- |
|
| 189 |
- var wg sync.WaitGroup |
|
| 190 |
- wg.Add(len(files)) |
|
| 191 |
- for _, file := range files {
|
|
| 192 |
- go func(file string) {
|
|
| 193 |
- defer wg.Done() |
|
| 194 |
- if err := fn(file); err != nil {
|
|
| 195 |
- panic(fmt.Sprintf("redress %s: %v", file, err))
|
|
| 196 |
- } |
|
| 197 |
- }(file) |
|
| 198 |
- } |
|
| 199 |
- wg.Wait() |
|
| 200 |
- return nil |
|
| 201 |
-} |
|
| 202 |
- |
|
| 203 |
-func Redress(s *step) string {
|
|
| 204 |
- return fmt.Sprintf("go run rm-gocheck.go redress '%s' \\\n %s", s.pattern, listToArgs(s.files))
|
|
| 205 |
-} |
|
| 206 |
- |
|
| 207 |
-func Format(s *step) string {
|
|
| 208 |
- pkgs := make([]string, 0, len(s.pkgs)) |
|
| 209 |
- for dir := range s.pkgs {
|
|
| 210 |
- pkgs = append(pkgs, "./"+dir) |
|
| 211 |
- } |
|
| 212 |
- files := listToArgs(pkgs) |
|
| 213 |
- return fmt.Sprintf("goimports -w \\\n-- %s \\\n&& \\\n gofmt -w -s \\\n-- %s", files, files)
|
|
| 214 |
-} |
|
| 215 |
- |
|
| 216 |
-func CommentInterface(s *step) string {
|
|
| 217 |
- cmds := make([]string, 0, len(s.pkgs)) |
|
| 218 |
- for dir := range s.pkgs {
|
|
| 219 |
- cmd := fmt.Sprintf(`while :; do \ |
|
| 220 |
- out=$(go test -c ./%s 2>&1 | grep 'cannot use nil as type string in return argument') || break |
|
| 221 |
- echo "$out" | while read line; do |
|
| 222 |
- file=$(echo "$line" | cut -d: -f1) |
|
| 223 |
- n=$(echo "$line" | cut -d: -f2) |
|
| 224 |
- sed -E -i "${n}"'s#\b(return .*, )nil#\1""#g' "$file"
|
|
| 225 |
- done |
|
| 226 |
-done`, dir) |
|
| 227 |
- cmds = append(cmds, cmd) |
|
| 228 |
- } |
|
| 229 |
- return strings.Join(cmds, " \\\n&& \\\n") |
|
| 230 |
-} |
|
| 231 |
- |
|
| 232 |
-func Eg(template string, prehook action, helperTypes string) action {
|
|
| 233 |
- return func(s *step) string {
|
|
| 234 |
- cmds := make([]string, 0, 3+4*len(s.pkgs)) |
|
| 235 |
- |
|
| 236 |
- if prehook != nil {
|
|
| 237 |
- cmds = append(cmds, prehook(s)) |
|
| 238 |
- } |
|
| 239 |
- |
|
| 240 |
- cmdstr := fmt.Sprintf(`go get -d golang.org/x/tools/cmd/eg && dir=$(go env GOPATH)/src/golang.org/x/tools && git -C "$dir" fetch https://github.com/tiborvass/tools handle-variadic && git -C "$dir" checkout 61a94b82347c29b3289e83190aa3dda74d47abbb && go install golang.org/x/tools/cmd/eg`) |
|
| 241 |
- cmds = append(cmds, cmdstr) |
|
| 242 |
- |
|
| 243 |
- for dir, pkg := range s.pkgs {
|
|
| 244 |
- cmds = append(cmds, fmt.Sprintf(`/bin/echo -e 'package %s\n%s' > ./%s/eg_helper.go`, pkg, helperTypes, dir)) |
|
| 245 |
- cmds = append(cmds, fmt.Sprintf(`goimports -w ./%s`, dir)) |
|
| 246 |
- cmds = append(cmds, fmt.Sprintf(`eg -w -t %s -- ./%s`, template, dir)) |
|
| 247 |
- cmds = append(cmds, fmt.Sprintf(`rm -f ./%s/eg_helper.go`, dir)) |
|
| 248 |
- } |
|
| 249 |
- cmds = append(cmds, fmt.Sprintf("go run rm-gocheck.go redress '%s' \\\n %s", `\bassert\.Assert\b.*(\(|,)\s*$`, listToArgs(s.files)))
|
|
| 250 |
- return strings.Join(cmds, " \\\n&& \\\n") |
|
| 251 |
- } |
|
| 252 |
-} |
|
| 253 |
- |
|
| 254 |
-func do(steps []step) {
|
|
| 255 |
- fileArgs := listToArgs(allFiles) |
|
| 256 |
- for _, s := range steps {
|
|
| 257 |
- fmt.Print(s.title, "... ") |
|
| 258 |
- s.files, _ = sh(`git grep --name-only -E '%s' -- %s`, s.pattern, fileArgs) |
|
| 259 |
- if len(s.files) == 0 {
|
|
| 260 |
- fmt.Println("no files match")
|
|
| 261 |
- continue |
|
| 262 |
- } |
|
| 263 |
- s.pkgs = map[string]string{}
|
|
| 264 |
- pkg := "" |
|
| 265 |
- if len(s.files) > 0 {
|
|
| 266 |
- x := mustSh(`grep -m1 '^package ' -- %s | cut -d' ' -f2`, s.files[0]) |
|
| 267 |
- pkg = x[0] |
|
| 268 |
- } |
|
| 269 |
- for _, file := range s.files {
|
|
| 270 |
- s.pkgs[filepath.Dir(file)] = pkg |
|
| 271 |
- } |
|
| 272 |
- cmdstr := s.action(&s) |
|
| 273 |
- mustSh(cmdstr) |
|
| 274 |
- if *shouldCommit {
|
|
| 275 |
- if len(s.comment) > 0 {
|
|
| 276 |
- s.comment = "\n\n" + s.comment |
|
| 277 |
- } |
|
| 278 |
- msg := fmt.Sprintf("%s%s\n\n%s%s", *titlePrefix, s.title, cmdstr, s.comment)
|
|
| 279 |
- sh(`git add %s`, listToArgs(s.files)) |
|
| 280 |
- cmd := exec.Command("git", "commit", "-s", "-F-")
|
|
| 281 |
- cmd.Stdin = strings.NewReader(msg) |
|
| 282 |
- out, err := cmd.CombinedOutput() |
|
| 283 |
- if err != nil {
|
|
| 284 |
- panic(string(out)) |
|
| 285 |
- } |
|
| 286 |
- fmt.Println("committed")
|
|
| 287 |
- } else {
|
|
| 288 |
- fmt.Println("done")
|
|
| 289 |
- } |
|
| 290 |
- } |
|
| 291 |
-} |
|
| 292 |
- |
|
| 293 |
-func main() {
|
|
| 294 |
- flag.Parse() |
|
| 295 |
- |
|
| 296 |
- args := flag.Args() |
|
| 297 |
- if len(args) > 0 {
|
|
| 298 |
- switch cmd := args[0]; cmd {
|
|
| 299 |
- case "redress": |
|
| 300 |
- if len(args) < 3 {
|
|
| 301 |
- panic(fmt.Sprintf("usage: %s [flags] redress <pattern> <files...>", os.Args[0]))
|
|
| 302 |
- } |
|
| 303 |
- if err := redress(args[1], args[2:]...); err != nil {
|
|
| 304 |
- panic(fmt.Sprintf("redress: %v", err))
|
|
| 305 |
- } |
|
| 306 |
- return |
|
| 307 |
- default: |
|
| 308 |
- panic(fmt.Sprintf("unknown command %s", cmd))
|
|
| 309 |
- } |
|
| 310 |
- } |
|
| 311 |
- |
|
| 312 |
- allFiles, _ = sh(`git grep --name-only '"github.com/go-check/check"' :**.go | grep -vE '^(vendor/|integration-cli/checker|rm-gocheck\.go|template\..*\.go)' | grep -E '%s'`, *filter) |
|
| 313 |
- if len(allFiles) == 0 {
|
|
| 314 |
- return |
|
| 315 |
- } |
|
| 316 |
- |
|
| 317 |
- do([]step{
|
|
| 318 |
- {
|
|
| 319 |
- title: "normalize c.Check to c.Assert", |
|
| 320 |
- pattern: `\bc\.Check\(`, |
|
| 321 |
- action: Replace(`c.Assert(`), |
|
| 322 |
- }, |
|
| 323 |
- {
|
|
| 324 |
- title: "redress multiline c.Assert calls", |
|
| 325 |
- pattern: `\bc\.Assert\b.*(,|\()\s*$`, |
|
| 326 |
- action: Redress, |
|
| 327 |
- }, |
|
| 328 |
- {
|
|
| 329 |
- title: "c.Assert(...) -> assert.Assert(c, ...)", |
|
| 330 |
- pattern: `\bc\.Assert\(`, |
|
| 331 |
- action: Replace(`assert.Assert(c, `), |
|
| 332 |
- }, |
|
| 333 |
- {
|
|
| 334 |
- title: "check.C -> testing.B for BenchmarkXXX", |
|
| 335 |
- pattern: `( Benchmark[^\(]+\([^ ]+ \*)check\.C\b`, |
|
| 336 |
- action: Replace(`\1testing.B`), |
|
| 337 |
- }, |
|
| 338 |
- {
|
|
| 339 |
- title: "check.C -> testing.T", |
|
| 340 |
- pattern: `\bcheck\.C\b`, |
|
| 341 |
- action: Replace(`testing.T`), |
|
| 342 |
- }, |
|
| 343 |
- {
|
|
| 344 |
- title: "ErrorMatches -> assert.ErrorContains", |
|
| 345 |
- pattern: `\bassert\.Assert\(c, (.*), check\.ErrorMatches,`, |
|
| 346 |
- action: Replace(`assert.ErrorContains(c, \1,`), |
|
| 347 |
- }, |
|
| 348 |
- {
|
|
| 349 |
- title: "normalize to use checker", |
|
| 350 |
- pattern: `\bcheck\.(Equals|DeepEquals|HasLen|IsNil|Matches|Not|NotNil)\b`, |
|
| 351 |
- action: Replace(`checker.\1`), |
|
| 352 |
- }, |
|
| 353 |
- {
|
|
| 354 |
- title: "Not(IsNil) -> != nil", |
|
| 355 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Not\(checker\.IsNil\)`, |
|
| 356 |
- action: Replace(`assert.Assert(c, \1 != nil`), |
|
| 357 |
- }, |
|
| 358 |
- {
|
|
| 359 |
- title: "Not(Equals) -> a != b", |
|
| 360 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Not\(checker\.Equals\), (.*)`, |
|
| 361 |
- action: Replace(`assert.Assert(c, \1 != \2`), |
|
| 362 |
- }, |
|
| 363 |
- {
|
|
| 364 |
- title: "Not(Matches) -> !cmp.Regexp", |
|
| 365 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Not\(checker\.Matches\), (.*)\)`, |
|
| 366 |
- action: CmpReplace(`assert.Assert(c, !${cmp}.Regexp("^"+\2+"$", \1)().Success())`),
|
|
| 367 |
- }, |
|
| 368 |
- {
|
|
| 369 |
- title: "Equals -> assert.Equal", |
|
| 370 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Equals, (.*)`, |
|
| 371 |
- action: Replace(`assert.Equal(c, \1, \2`), |
|
| 372 |
- }, |
|
| 373 |
- {
|
|
| 374 |
- title: "DeepEquals -> assert.DeepEqual", |
|
| 375 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.DeepEquals, (.*)`, |
|
| 376 |
- action: Replace(`assert.DeepEqual(c, \1, \2`), |
|
| 377 |
- }, |
|
| 378 |
- {
|
|
| 379 |
- title: "HasLen -> assert.Equal + len()", |
|
| 380 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.HasLen, (.*)`, |
|
| 381 |
- action: Replace(`assert.Equal(c, len(\1), \2`), |
|
| 382 |
- }, |
|
| 383 |
- {
|
|
| 384 |
- title: "IsNil", |
|
| 385 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.IsNil\b`, |
|
| 386 |
- action: Replace(`assert.Assert(c, \1 == nil`), |
|
| 387 |
- }, |
|
| 388 |
- {
|
|
| 389 |
- title: "NotNil", |
|
| 390 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.NotNil\b`, |
|
| 391 |
- action: Replace(`assert.Assert(c, \1 != nil`), |
|
| 392 |
- }, |
|
| 393 |
- {
|
|
| 394 |
- title: "False", |
|
| 395 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.False\b`, |
|
| 396 |
- action: Replace(`assert.Assert(c, !\1`), |
|
| 397 |
- }, |
|
| 398 |
- {
|
|
| 399 |
- title: "True", |
|
| 400 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.True`, |
|
| 401 |
- action: Replace(`assert.Assert(c, \1`), |
|
| 402 |
- }, |
|
| 403 |
- {
|
|
| 404 |
- title: "redress check.Suite calls", |
|
| 405 |
- pattern: `[^/]\bcheck\.Suite\(.*\{\s*$`,
|
|
| 406 |
- action: Redress, |
|
| 407 |
- }, |
|
| 408 |
- {
|
|
| 409 |
- title: "comment out check.Suite calls", |
|
| 410 |
- pattern: `^([^*])+?((var .*)?check\.Suite\(.*\))`, |
|
| 411 |
- action: Replace(`\1/*\2*/`), |
|
| 412 |
- }, |
|
| 413 |
- {
|
|
| 414 |
- title: "comment out check.TestingT", |
|
| 415 |
- pattern: `([^*])(check\.TestingT\([^\)]+\))`, |
|
| 416 |
- action: Replace(`\1/*\2*/`), |
|
| 417 |
- }, |
|
| 418 |
- {
|
|
| 419 |
- title: "run goimports to compile successfully", |
|
| 420 |
- action: Format, |
|
| 421 |
- }, |
|
| 422 |
- {
|
|
| 423 |
- title: "Matches -> cmp.Regexp", |
|
| 424 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Matches, (.*)\)$`, |
|
| 425 |
- action: Eg("template.matches.go",
|
|
| 426 |
- CmpReplace(`assert.Assert(c, eg_matches(${cmp}.Regexp, \1, \2))`),
|
|
| 427 |
- `var eg_matches func(func(cmp.RegexOrPattern, string) cmp.Comparison, interface{}, string, ...interface{}) bool`),
|
|
| 428 |
- }, |
|
| 429 |
- {
|
|
| 430 |
- title: "Not(Contains) -> !strings.Contains", |
|
| 431 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Not\(checker\.Contains\), (.*)\)$`, |
|
| 432 |
- action: Eg("template.not_contains.go",
|
|
| 433 |
- Replace(`assert.Assert(c, !eg_contains(\1, \2))`), |
|
| 434 |
- `var eg_contains func(arg1, arg2 string, extra ...interface{}) bool`),
|
|
| 435 |
- }, |
|
| 436 |
- {
|
|
| 437 |
- title: "Contains -> strings.Contains", |
|
| 438 |
- pattern: `\bassert\.Assert\(c, (.*), checker\.Contains, (.*)\)$`, |
|
| 439 |
- action: Eg("template.contains.go",
|
|
| 440 |
- Replace(`assert.Assert(c, eg_contains(\1, \2))`), |
|
| 441 |
- `var eg_contains func(arg1, arg2 string, extra ...interface{}) bool`),
|
|
| 442 |
- }, |
|
| 443 |
- {
|
|
| 444 |
- title: "convert check.Commentf to string - with multiple args", |
|
| 445 |
- pattern: `\bcheck.Commentf\(([^,]+),(.*)\)`, |
|
| 446 |
- action: Replace(`fmt.Sprintf(\1,\2)`), |
|
| 447 |
- }, |
|
| 448 |
- {
|
|
| 449 |
- title: "convert check.Commentf to string - with just one string", |
|
| 450 |
- pattern: `\bcheck.Commentf\(("[^"]+")\)`,
|
|
| 451 |
- action: Replace(`\1`), |
|
| 452 |
- }, |
|
| 453 |
- {
|
|
| 454 |
- title: "convert check.Commentf to string - other", |
|
| 455 |
- pattern: `\bcheck.Commentf\(([^\)]+)\)`, |
|
| 456 |
- action: Replace(`\1`), |
|
| 457 |
- }, |
|
| 458 |
- {
|
|
| 459 |
- title: "check.CommentInterface -> string", |
|
| 460 |
- pattern: `(\*testing\.T\b.*)check\.CommentInterface\b`, |
|
| 461 |
- action: Replace(`\1string`), |
|
| 462 |
- }, |
|
| 463 |
- {
|
|
| 464 |
- title: "goimports", |
|
| 465 |
- action: Format, |
|
| 466 |
- }, |
|
| 467 |
- {
|
|
| 468 |
- title: "fix compile errors from converting check.CommentInterface to string", |
|
| 469 |
- action: CommentInterface, |
|
| 470 |
- }, |
|
| 471 |
- }) |
|
| 472 |
-} |
| 473 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,35 +0,0 @@ |
| 1 |
-// +build ignore |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "strings" |
|
| 7 |
- "testing" |
|
| 8 |
- |
|
| 9 |
- "gotest.tools/assert" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-type fn func(arg1, arg2 string, extra ...interface{}) bool
|
|
| 13 |
-type assertfn func(t assert.TestingT, comparison assert.BoolOrComparison, msgAndArgs ...interface{})
|
|
| 14 |
- |
|
| 15 |
-func before( |
|
| 16 |
- t *testing.T, |
|
| 17 |
- a assertfn, |
|
| 18 |
- eg_contains fn, |
|
| 19 |
- arg1 string, |
|
| 20 |
- arg2 string, |
|
| 21 |
- extra ...interface{}) {
|
|
| 22 |
- |
|
| 23 |
- a(t, eg_contains(arg1, arg2, extra...)) |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-func after( |
|
| 27 |
- t *testing.T, |
|
| 28 |
- a assertfn, |
|
| 29 |
- eg_contains fn, |
|
| 30 |
- arg1 string, |
|
| 31 |
- arg2 string, |
|
| 32 |
- extra ...interface{}) {
|
|
| 33 |
- |
|
| 34 |
- a(t, strings.Contains(arg1, arg2), extra...) |
|
| 35 |
-} |
| 36 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,37 +0,0 @@ |
| 1 |
-// +build ignore |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "testing" |
|
| 7 |
- |
|
| 8 |
- "gotest.tools/assert" |
|
| 9 |
- "gotest.tools/assert/cmp" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-type fn func(re func(cmp.RegexOrPattern, string) cmp.Comparison, r interface{}, v string, extra ...interface{}) bool
|
|
| 13 |
-type assertfn func(t assert.TestingT, comparison assert.BoolOrComparison, msgAndArgs ...interface{})
|
|
| 14 |
- |
|
| 15 |
-func before( |
|
| 16 |
- t *testing.T, |
|
| 17 |
- a assertfn, |
|
| 18 |
- eg_matches fn, |
|
| 19 |
- re func(cmp.RegexOrPattern, string) cmp.Comparison, |
|
| 20 |
- r string, |
|
| 21 |
- v string, |
|
| 22 |
- extra ...interface{}) {
|
|
| 23 |
- |
|
| 24 |
- a(t, eg_matches(re, v, r, extra...)) |
|
| 25 |
-} |
|
| 26 |
- |
|
| 27 |
-func after( |
|
| 28 |
- t *testing.T, |
|
| 29 |
- a assertfn, |
|
| 30 |
- eg_matches fn, |
|
| 31 |
- re func(cmp.RegexOrPattern, string) cmp.Comparison, |
|
| 32 |
- r string, |
|
| 33 |
- v string, |
|
| 34 |
- extra ...interface{}) {
|
|
| 35 |
- |
|
| 36 |
- a(t, re("^"+r+"$", v), extra...)
|
|
| 37 |
-} |
| 38 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,35 +0,0 @@ |
| 1 |
-// +build ignore |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "strings" |
|
| 7 |
- "testing" |
|
| 8 |
- |
|
| 9 |
- "gotest.tools/assert" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-type fn func(arg1, arg2 string, extra ...interface{}) bool
|
|
| 13 |
-type assertfn func(t assert.TestingT, comparison assert.BoolOrComparison, msgAndArgs ...interface{})
|
|
| 14 |
- |
|
| 15 |
-func before( |
|
| 16 |
- t *testing.T, |
|
| 17 |
- a assertfn, |
|
| 18 |
- eg_contains fn, |
|
| 19 |
- arg1 string, |
|
| 20 |
- arg2 string, |
|
| 21 |
- extra ...interface{}) {
|
|
| 22 |
- |
|
| 23 |
- a(t, !eg_contains(arg1, arg2, extra...)) |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-func after( |
|
| 27 |
- t *testing.T, |
|
| 28 |
- a assertfn, |
|
| 29 |
- eg_contains fn, |
|
| 30 |
- arg1 string, |
|
| 31 |
- arg2 string, |
|
| 32 |
- extra ...interface{}) {
|
|
| 33 |
- |
|
| 34 |
- a(t, !strings.Contains(arg1, arg2), extra...) |
|
| 35 |
-} |
| 36 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,40 +0,0 @@ |
| 1 |
-// +build ignore |
|
| 2 |
- |
|
| 3 |
-package main |
|
| 4 |
- |
|
| 5 |
-import ( |
|
| 6 |
- "testing" |
|
| 7 |
- "time" |
|
| 8 |
- |
|
| 9 |
- "github.com/docker/docker/integration-cli/checker" |
|
| 10 |
- "gotest.tools/assert" |
|
| 11 |
- "gotest.tools/poll" |
|
| 12 |
-) |
|
| 13 |
- |
|
| 14 |
-func pollCheck(t *testing.T, f interface{}, compare func(x interface{}) assert.BoolOrComparison) poll.Check
|
|
| 15 |
- |
|
| 16 |
-type eg_compareFunc func(...interface{}) checker.Compare
|
|
| 17 |
- |
|
| 18 |
-type waitAndAssertFunc func(t *testing.T, timeout time.Duration, ff, comparison interface{}, args ...interface{})
|
|
| 19 |
- |
|
| 20 |
-func before( |
|
| 21 |
- waitAndAssert waitAndAssertFunc, |
|
| 22 |
- t *testing.T, |
|
| 23 |
- timeout time.Duration, |
|
| 24 |
- f interface{},
|
|
| 25 |
- comparison interface{},
|
|
| 26 |
- args ...interface{}) {
|
|
| 27 |
- |
|
| 28 |
- waitAndAssert(t, timeout, f, comparison, args...) |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-func after( |
|
| 32 |
- waitAndAssert waitAndAssertFunc, |
|
| 33 |
- t *testing.T, |
|
| 34 |
- timeout time.Duration, |
|
| 35 |
- f interface{},
|
|
| 36 |
- comparison interface{},
|
|
| 37 |
- args ...interface{}) {
|
|
| 38 |
- |
|
| 39 |
- poll.WaitOn(t, pollCheck(t, f, comparison.(eg_compareFunc)(args...)), poll.WithTimeout(timeout)) |
|
| 40 |
-} |