aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api/api_test.go
AgeCommit message (Collapse)Author
2026-03-02all: test: remove unneeded loop variablesAriel Otilibili
This CL follows from the abandoned CL 722961. Alan Donovan asked if modernize would catch these changes; it does in part. Here is how modernize was used: 1. Build the Go compiler from latest master 2. Clone x/tools and build modernize with the newest compiler 3. Then, do: PATH=PATH_TO_BIN:$PATH go list ./... | xargs env PATH=PATH_TO_BIN:$PATH GOMOD=off MODERNIZE -forvar -fix -test -debug fpstv 4. For assurance, move into a package directory (i.e, cmd), and redo Step 3. From the obtained result, it seems modernize did not remove the loop variable when: - the range notation was not used - the loop variable was not directly under the for directive. Which does happens here: # git ls-files | xargs -I {} perl -nE 'print "$ARGV:$.:$_" if /\s+(\w+) := \1$/' {} | grep _test [...] cmd/compile/internal/types2/api_test.go:2423: i := i md/go/internal/modload/query_test.go:182: tt := tt md/go/internal/web/url_test.go:17: tc := tc cmd/go/internal/web/url_test.go:49: tc := tc cmd/internal/par/queue_test.go:54: i := i runtime/syscall_windows_test.go:781: arglen := arglen Link: https://go-review.googlesource.com/c/go/+/722961/comments/e8d47866_fc399fa1 Co-authored-by: Plamerdi Makela <plamerdi447@gmail.com> Fixes #76411 Change-Id: I0c191cdca70dbea6efaf6796dca9c60e2afcd9ea GitHub-Last-Rev: 77c3e11fc21a4ede70b733b567a1690edb944dc1 GitHub-Pull-Request: golang/go#77694 Reviewed-on: https://go-review.googlesource.com/c/go/+/746502 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-05-02cmd/api: skip 3 non-TestCheck tests in -check modeDmitri Shuralyov
TestIssue64958 takes a while, so it's not worth running both without and with -check flag. The others are fast, but there's still no good reason to run anything but TestCheck when the -check flag is on. Change-Id: I13ebb90e3c863006f21441909b05364e1b316ed6 Reviewed-on: https://go-review.googlesource.com/c/go/+/668656 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2025-01-14cmd/api: report error in test instead of crashingRuss Cox
https://ci.chromium.org/ui/inv/build-8725798219051312433/test-results?sortby=&groupby= shows a mysterious failure with this stack: === RUN BenchmarkAll BenchmarkAll panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7c497f] goroutine 20 gp=0xc000004000 m=7 mp=0xc000182808 [running]: panic({0x81c5e0?, 0xabc6b0?}) /home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/panic.go:806 +0x168 fp=0xc00c7ffce0 sp=0xc00c7ffc30 pc=0x4ad4c8 runtime.panicmem(...) /home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/panic.go:262 runtime.sigpanic() /home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/signal_unix.go:925 +0x359 fp=0xc00c7ffd40 sp=0xc00c7ffce0 pc=0x4af6d9 cmd/api.(*Walker).export(0xc000034100, 0x0) /home/swarming/.swarming/w/ir/x/w/goroot/src/cmd/api/main_test.go:193 +0x3f fp=0xc00c7ffe08 sp=0xc00c7ffd40 pc=0x7c497f cmd/api.BenchmarkAll(0xc000214288) /home/swarming/.swarming/w/ir/x/w/goroot/src/cmd/api/api_test.go:205 +0x207 fp=0xc00c7ffeb0 sp=0xc00c7ffe08 pc=0x7c1c07 testing.(*B).runN(0xc000214288, 0x1) /home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:202 +0x291 fp=0xc00c7fff78 sp=0xc00c7ffeb0 pc=0x57e611 testing.(*B).run1.func1() /home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:224 +0x7c fp=0xc00c7fffe0 sp=0xc00c7fff78 pc=0x57f11c runtime.goexit({}) /home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00c7fffe8 sp=0xc00c7fffe0 pc=0x4b4a61 created by testing.(*B).run1 in goroutine 1 /home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:217 +0x173 So import_ must have returned an error, making pkg nil. Show that error. Also do the same at the other calls to import_. Change-Id: Ie782571c4bda3334a86b303f61969cf1cc7d3c32 Reviewed-on: https://go-review.googlesource.com/c/go/+/642438 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2025-01-14cmd/dist: ignore packages with no Go files in BenchmarkAllIan Lance Taylor
This case recently started happening on the builders. The synctest experiment was recently enabled for some targets (CL 642422). This caused the list of standard packages to include testing/synctest. However, BenchmarkAll tests for all configurations; some did not include testing/synctest. That caused the test to crash. Change-Id: Icade10af147c2e2bcbac25bf744919083db3e70f Reviewed-on: https://go-review.googlesource.com/c/go/+/642397 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2024-11-18cmd: change from sort functions to slices functionsIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. We did this outside of bootstrap tools in CL 587655. Now that the bootstrap compiler is 1.22, we can do this in more code. Change-Id: I9ed2dd473758cacd14f76a0639368523ccdff72f Reviewed-on: https://go-review.googlesource.com/c/go/+/626038 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-01-04cmd/api: fix panic on exported basic type aliasesDevon H. O'Dell
The order of emitting named type and type aliases in the `Walker`'s `emitType` function is inverted. When the type alias references a basic type, this causes a panic as the type assertion on `*types.Named` fails. This change reorders the logic such that type aliases are emitted prior to this type assertion. Fixes #64958 Change-Id: I52dbe13999978912ded788d9cf4948103869bcfa Reviewed-on: https://go-review.googlesource.com/c/go/+/554076 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-08-16cmd/api: rename api.go to main_test.goRuss Cox
This makes cmd/api no longer an importable package. In CL 453258 I forgot that there was no direct prohibition on importing packages from cmd - we just rely on the fact that cmd/* is all package main and everything else is cmd/internal. Fixes #62069. Change-Id: Ifed738d333b40663f85eca8f83025fcea5df89a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/520038 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-15cmd/api: skip TestIssue29837 when -short is setqmuntal
TestIssue29837 takes a long time to run, ~150s on my laptop and ~40s on CI builders. While here, warm up the go list cache in parallel, which reduces the test time by ~10%. Change-Id: Ib8d45b086453ee03e6c9f3f070d6f6b0d324bfd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/502095 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2023-05-19cmd/api: skip TestIssue21181Russ Cox
It is incredibly slow, taking half as long as the regular cmd/api checks and over 5 minutes on plan9-arm. Leave it for the longtest builders. Change-Id: Ic8bd420f174268d0b6a13d84e7bd364f6c13cf41 Reviewed-on: https://go-review.googlesource.com/c/go/+/496375 Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2023-05-03cmd/api: move support checks into individual testsBryan C. Mills
This makes 'go test -list cmd/api' work, and fixes an infinite recursion via testenv.HasExec that would otherwise occur. As of CL 488076, testenv.HasExec tries to re-exec the test executable using -list to suppress running the tests, which produces a fork bomb if TestMain itself calls HasExec. For this test, it turns out that the HasExec check is redundant anyway: if we can exec 'go build', we can certainly exec programs in general too. Change-Id: I165f98315c181098c8be8b7525b9dfa3f98e14f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/491656 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-04-27cmd/api: remove unused functionalityDmitri Shuralyov
We no longer use the optional parameter to compareAPI. We now always set allowAdd to false. (Except in tests, making them less useful than they could be.) Flags and parsing their value are no more. Remove all the unused functionality and update test cases so they're closer to what the API checker does when it runs for real. Order the features, required, exception variables and fields more consistently. For #43956. Change-Id: Iaa4656a89a3fca3129742165a448d385e55e4a98 Reviewed-on: https://go-review.googlesource.com/c/go/+/489436 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-02cmd/api: track deprecationsRuss Cox
Deprecating an API creates notices that go out to potentially millions of Go developers encouraging them to update their code. The choice to deprecate an API is as important as the choice to add a new API. We should track those and make them explicit. This will also ensure that deprecations go through proposal review. Change-Id: Ide9f60c32e5a88fb133e0dfedd984b8b0f70f510 Reviewed-on: https://go-review.googlesource.com/c/go/+/453259 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: David Chase <drchase@google.com>
2022-11-28cmd/api: rewrite as package testRuss Cox
No one ever runs 'go tool api', because the invocation has gotten unwieldy enough that it's not practical. And we don't support it as a standalone tool for other packages - it's not even in the distribution. Making it an ordinary package test lets us invoke it more easily from cmd/dist (as go test cmd/api -check) and avoids the increasingly baroque code in run.go to build a command line. Left in cmd/api even though it's no longer a command because (1) it uses a package from cmd/vendor and (2) it uses internal/testenv. Otherwise it could be misc/api. Fixes #56845. Change-Id: I00a13d9c19b1e259fa0e6bb93d1a4dca25f0e8c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/453258 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Russ Cox <rsc@golang.org>