aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cover
AgeCommit message (Collapse)Author
2026-02-13cmd/cover: exclude commented-out code from coverage instrumentationRudy Regazzoni
Add logic to exclude purely commented lines from coverage instrumentation. When instrumenting Go code for coverage, the cover tool now identifies and excludes lines that contain only comments from coverage blocks. This prevents commented-out code from being reported as "uncovered" in coverage reports, which can be misleading. The implementation adds a splitBlockByComments function that parses source code character by character to identify segments containing executable code versus segments containing only comments. The addCounters function now uses this to create coverage counters only for segments that contain actual executable code. The parser correctly handles: - Single-line comments (//) - Multi-line comments (/* */) - String literals containing comment-like sequences - Raw string literals with fake comments - Mixed lines with both code and comments This improves the accuracy of coverage reports by ensuring that commented-out code, TODOs, and documentation comments don't inflate the count of uncovered lines. Fixes #22545 Change-Id: Ib428e6569011abb5f315387e81547147a2dadd2b GitHub-Last-Rev: 915058146bb5f929f08d63ee191edebd51b2ab56 GitHub-Pull-Request: golang/go#76692 Reviewed-on: https://go-review.googlesource.com/c/go/+/726800 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-02-06cmd/link: align covctrs symbolKeith Randall
If we start the covctrs blob at an odd alignment, then covctrs will not be correctly aligned. Each individual entry is aligned properly, but the start marker may be before any padding inserted to enforce that alignment. Fixes #58936 Change-Id: I802fbe40eacfa5a3c8c4864e078b0e078da956d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/733740 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com>
2026-02-02cmd/cover, cmd/covdata: actually delete temp dirsIan Lance Taylor
The code was using defer in TestMain, but was also calling os.Exit, which meant that the deferred functions did not run. TestMain does not require calling os.Exit, so stop doing it. Change-Id: I25ca64c36acf65dae3dc3f46e5fa513b9460a8e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/740781 Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-09-03cmd: replace many sort.Interface with slices.Sort and SortFuncZxilly
with slices there's no need to implement sort.Interface Change-Id: I59167e78881cb1df89a71e33d738d6aeca7adb71 GitHub-Last-Rev: 507ba84453f7305b6b2bf6317292111c00c93ffe GitHub-Pull-Request: golang/go#68724 Reviewed-on: https://go-review.googlesource.com/c/go/+/602895 Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2024-09-03cmd: use testenv.Executable helperKir Kolyshkin
Change-Id: I25ac0e8d25d760bfde3bb7700f0feaa23f3e8ab1 Reviewed-on: https://go-review.googlesource.com/c/go/+/609302 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-21cmd/internal: separate counter package from telemetry packageMichael Matloob
Move the code that opens and increments counters out of the cmd/internal/telemetry package into cmd/internal/telemetry/counter. The telemetry package has dependencies on the upload code, which we do not want to pull into the rest of the go toolchain. For #68109 Change-Id: I463c106819b169177a783de4a7d93377e81f4e3e Reviewed-on: https://go-review.googlesource.com/c/go/+/593976 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
2024-06-13cmd/go: call telemetry.MaybeChild at start of go commandMichael Matloob
Call the new telemetry.MaybeChild function at the start of the go command so that the child process logic can be run immediately without running toolchain selection if this is the child process. The Start function in the telemetry shim package has been renamed to OpenCounters to make it clear that that's its only function. The StartWithUpload function in the telemetry shim package has been renamed to MaybeParent because that's its actual effective behavior in cmd/go, the only place it's called: it won't run as the child because MaybeChild has already been called and would have run as the child if the program was the telemetry child, and it won't open counters because telemetry.Start has been called. Checks are added that those functions are always called before so that the function name and comment are accurate. It might make sense to add a true telemetry.MaybeParent function that doesn't try to start the child or open counters to make things a little simpler. Change-Id: Ie81e2418af85cef18ec41f75db66365f6597b8b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/592535 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-14cmd: add telemetry for commands in cmdMichael Matloob
This change modifies the commands in cmd to open counter files, increment invocations counters and to increment counters for the names of the flags that were passed in. cmd/pprof and cmd/vet are both wrappers around tools defined in other modules which do their own flag processing so we can't directly increment flag counters right after flags are parsed. For those two commands we wait to increment counters until after the programs have returned. cmd/dist is built with the bootstrap go so it can't depend on telemetry yet. We can add telemetry support to it once 1.23 is the minimum bootstrap version. For #58894 Change-Id: Ic7f6009992465e55c56ad4dc6451bcb1ca51374a Reviewed-on: https://go-review.googlesource.com/c/go/+/585235 Reviewed-by: Sam Thanawalla <samthanawalla@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-15cmd/cover: fix typo in commentguoguangwu
Change-Id: I7507e6cff00d027fd7840e0661499efc63353f6e GitHub-Last-Rev: 81348ed39d055e445d943eedfe4b4db3a1fd73d8 GitHub-Pull-Request: golang/go#66820 Reviewed-on: https://go-review.googlesource.com/c/go/+/578441 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-03-25runtime: migrate internal/atomic to internal/runtimeAndy Pan
For #65355 Change-Id: I65dd090fb99de9b231af2112c5ccb0eb635db2be Reviewed-on: https://go-review.googlesource.com/c/go/+/560155 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ibrahim Bazoka <ibrahimbazoka729@gmail.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2023-10-03cmd: fix mismatched symbolscui fliter
Change-Id: I6365cdf22ad5e669908519d0ee8b78d76ae8f1b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/532075 Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-30internal,cmd/internal: relocate covcmd package from std to cmdThan McIntosh
Relocate the 'covcmd' package from .../internal/coverage to .../cmd/internal/cov, to reflect the fact that the definitions in this package are used only in cmd, not in std. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I65bcc34736d1d0a23134a6c91c17ff138cd45431 Reviewed-on: https://go-review.googlesource.com/c/go/+/526595 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-14cmd/cover: add new "emit meta file" mode for packages without testsThan McIntosh
Introduce a new mode of execution for instrumenting packages that have no test files. Instead of just skipping packages with no test files (during "go test -cover" runs), the go command will invoke cmd/cover on the package passing in an option in the config file indicating that it should emit a coverage meta-data file directly for the package (if the package has no functions, an empty file is emitted). Note that this CL doesn't actually wire up this functionality in the Go command, that will come in a later patch. Updates #27261. Updates #58770 Updates #24570. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I01e8a3edb62441698c7246596e4bacbd966591c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/495446 Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-08-14internal/coverage: separate out cmd defs to separate packageThan McIntosh
Relocate the definitions in cmddefs.go (used by the compiler and the cover tool) to a separate package "covcmd". No change in functionality, this is a pure refactoring, in preparation for a subsequent change that will require updating the imports for the package. Change-Id: Ic1d277c94d9a574de0a11ec5ed77e892302b9a47 Reviewed-on: https://go-review.googlesource.com/c/go/+/517696 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: David Chase <drchase@google.com>
2023-06-22cmd/{go,cover}: enable response file args for cmd/coverThan McIntosh
Change the cover command to accept arguments via response files, using the same mechanism employed for the compiler and the assembler. This is needed now that the cover tool accepts a list of all source files in a package, as opposed to just a single source file, and as a result can run into system-dependent command line length limits. Fixes #60785. Change-Id: I67dbc96ad9fc5c6f43d5c1e4e903e4b8589b154f Reviewed-on: https://go-review.googlesource.com/c/go/+/503735 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2023-06-07cmd/cover: error out if a requested source file contains a newlineBryan C. Mills
cmd/cover uses '//line' directives to map instrumented source files back to the original source file and line numbers. Line directives have no way to escape newline characters, so cmd/cover must not be used with source file paths that contain such characters. Updates #60167. Change-Id: I6dc039392d59fc3a5a6121ef6ca97b0ab0da5288 Reviewed-on: https://go-review.googlesource.com/c/go/+/501577 Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-30cmd/{cover,go}: revise fix for pkg init order change with -coverThan McIntosh
This patch contains a revised fix for issue #56293, switching to a scheme in which coverage counter variables and meta-data variables are written to a separate output file as opposed to being tacked onto the end of an existing rewritten source file. The advantage of writing counter vars to a separate file is that the Go command can then present that file as the first source file to the compiler when the package is built; this will ensure that counter variable are treated as lexically "before" any other variable that might call an instrumented function as part of its initializer. Updates #56293. Change-Id: Iccb8a6532b976d36ccbd5a2a339882d1f5d19477 Reviewed-on: https://go-review.googlesource.com/c/go/+/499215 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-08cmd/cover: add newline to fix -covermode=atomic build errorThan McIntosh
Fix a minor buglet in atomic mode fixup that would generate non-compilable code for a package containing only the "package X" clause with no trailing newline following the "X". Fixes #58370. Change-Id: I0d9bc4f2b687c6bd913595418f6db7dbe50cc5df Reviewed-on: https://go-review.googlesource.com/c/go/+/466115 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-13cmd/cover: remove go.mod from testdata subdirThan McIntosh
Remove a superfluous go.mod file in one of the testdata subdirs; test runs ok without it, no need for it to be there (can confuse tooling). Change-Id: I3c43dd8ca557fdd32ce2f84cdb2427326a2dd35e Reviewed-on: https://go-review.googlesource.com/c/go/+/461945 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-05cmd/cover: fix problems with "go test -covermode=atomic sync/atomic"Than McIntosh
This patch fixes an elderly bug with "go test -covermode=atomic sync/atomic". Change the cover tool to avoid adding an import of sync/atomic when processing "sync/atomic" itself in atomic mode; instead make direct calls to AddUint32/StoreUint32. In addition, change the go command to avoid injecting an artificial import of "sync/atomic" for sync/atomic itself. Fixes #57445. Change-Id: I8c8fbd0bcf26c8a8607d4806046f826296508c74 Reviewed-on: https://go-review.googlesource.com/c/go/+/459335 Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-08cmd/{go,cover,covdata}: fix 'package main' inconsistent handlingThan McIntosh
Fix a buglet in cmd/cover in how we handle package name/path for the "go build -o foo.exe *.go" and "go run *.go" cases. The go command assigns a dummy import path of "command-line-arguments" to the main package built in these cases; rather than expose this dummy to the user in coverage reports, the cover tool had a special case hack intended to rewrite such package paths to "main". The hack was too general, however, and was rewriting the import path of all packages with (p.name == "main") to an import path of "main". The hack also produced unexpected results for cases such as go test -cover foo.go foo_test.go This patch removes the hack entirely, leaving the package path for such cases as "command-line-arguments". Fixes #57169. Change-Id: Ib6071db5e3485da3b8c26e16ef57f6fa1712402c Reviewed-on: https://go-review.googlesource.com/c/go/+/456237 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-11-15cmd/cover: use testenv.Command instead of exec.CommandBryan C. Mills
testenv.Command sets a default timeout based on the test's deadline and sends SIGQUIT (where supported) in case of a hang. Change-Id: Ic19f8b020f6d410942bb2ece8a3b71607ee6488a Reviewed-on: https://go-review.googlesource.com/c/go/+/450695 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-01cmd/cover: fix buglet causing differences in -m outputThan McIntosh
Use a slightly different line number pragma when emitting instrumented code, so as to ensure that we don't get any changes in the "-gcflags=-m" output for coverage vs non-coverage. Fixes #56475. Change-Id: I3079171fdf83c0434ed6ea0ce3eb2797c2280c55 Reviewed-on: https://go-review.googlesource.com/c/go/+/446259 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-11-01cmd/{go,cover}: fix for -coverprofile path capture with local pkgThan McIntosh
When coverage testing a local package (defined by a relative import path such as "./foo/bar") the convention when "-coverprofile" is used has been to capture source files by full pathname, as opposed to recording the full import path or the invented import path ("command-line-arguments/") created by the go command in the case of building named Go files. Doing this makes it much easier to use collected profiles with "go tool -cover -html=<profile>". The support for this feature/convention wound up being inadvertantly dropped during the GOEXPERIMENT=coverageredesign implementation; this patch restores it. Fixes #56433. Change-Id: Ib9556fdc86011b00c155caa614ab23e5148f3eb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/445917 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-21cmd/cover: fix buglets in counter insertionThan McIntosh
This patch has a couple of minor fixes to new-style counter insertion (noticed these problems while working on the fix for issue 56370). First, make sure that the function registration sequence (writing of nctrs, pkgid, funcid to counter var prolog) comes prior to the first counter update (they were reversed up to this point, due to an artifact of the way cmd/internal/edit operates). Second, fix up "per function" counter insertion mode (an experimental feature disabled by default that adds just a single counter to each function as opposed to one per basic block), which was failing to insert the single counter in the right place. Change-Id: Icfb613ca385647f35c0e52da2da8edeb2a506ab7 Reviewed-on: https://go-review.googlesource.com/c/go/+/444835 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com>
2022-10-21cmd/cover: fix problem with race mode and inliningThan McIntosh
This patch fixes a problem in which we can get a data race on a coverage counter function registration sequence. The scenario is that package P contains a function F that is built with coverage, then F is inlined into some other package that isn't being instrumented. Within F's exported function body counter updates were being done with atomics, but the initial registration sequence was not, which had the potential to trigger a race. Fix: if race mode is enabled and we're using atomics for counter increments, also use atomics in the registration sequence. Fixes #56370. Change-Id: If274b61714b90275ff95fc6529239e9264b0ab0c Reviewed-on: https://go-review.googlesource.com/c/go/+/444617 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Than McIntosh <thanm@google.com>
2022-10-12cmd/{cover,covdata}: minor code cleanupsThan McIntosh
Delete some unused code, and fix a few warnings from staticcheck. Change-Id: I3d3a6f13dccffda060449948769c305d93a0389c Reviewed-on: https://go-review.googlesource.com/c/go/+/441936 Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-29cmd/cover: use io.SeekStart, io.SeekCurrentcuiweixie
Change-Id: Ie3b593f7f0c71334dc8c446d545bf441f2ae81f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/436695 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Than McIntosh <thanm@google.com>
2022-09-29cmd/cover: remove unnecessary fmt.Sprintfcuiweixie
Change-Id: I892f17a8a6464d53dbf330a41439a81cb8873262 Reviewed-on: https://go-review.googlesource.com/c/go/+/436654 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2022-09-29cmd: add skips as needed to get tests to pass on js/wasmBryan C. Mills
For #54219. Change-Id: I9767f46a5b44beeee62a3d53c4de4f6acb6b6e73 Reviewed-on: https://go-review.googlesource.com/c/go/+/436816 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-09-29cmd/{cover,go}: avoid use of os.PathListSeparator in cmd/cover flagThan McIntosh
Rework the mechanism for passing a list of output files from cmd/go to cmd/cover when running new-style package-scope coverage instrumentation (-pkgcfg mode). The old scheme passed a single string with all output files joined together with os.PathListSeparator, but this scheme is not viable on plan9, where strings containing the separator character are not permitted when running exec.Command(). Instead, switch cmd/cover to use an arguments file (a file containing a list of names) to specify names of instrumented output files. This fixes the cmd/cover test failures on the plan9 builders. Updates #51430. Change-Id: I919f5e0a79500e28648fb9177225a9b938e4fdee Reviewed-on: https://go-review.googlesource.com/c/go/+/436675 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Than McIntosh <thanm@google.com>
2022-09-29cmd{cover,covdata,go}: better coverage for tests that build toolsThan McIntosh
Some of the unit tests in Go's "cmd" tree wind up building a separate copy of the tool being tested, then exercise the freshly built tool as a way of doing regression tests. The intent is to make sure that "go test" is testing the current state of the source code, as opposed to whatever happened to be current when "go install <tool>" was last run. Doing things this way is unfriendly for coverage testing. If I run "go test -cover cmd/mumble", and the cmd/mumble test harness builds a fresh copy of mumble.exe, any runs of that new executable won't generate coverage data. This patch updates the test harnesses to use the unit test executable as a stand-in for the tool itself, so that if "go test -cover" is in effect, we get the effect of building the tool executable for coverage as well. Doing this brings up the overall test coverage number for cmd/cover quite dramatically: before change: $ go test -cover . ok cmd/cover 1.100s coverage: 1.5% of statements after change: $ go test -cover . ok cmd/cover 1.299s coverage: 84.2% of statements Getting this to work requires a small change in the Go command as well, to set GOCOVERDIR prior to executing a test binary. Updates #51430. Change-Id: Ifcf0ea85773b80fcda794aae3702403ec8e0b733 Reviewed-on: https://go-review.googlesource.com/c/go/+/404299 Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-28cmd/cover: add hybrid instrumentation modeThan McIntosh
Add a new mode of coverage instrumentation that works as a hybrid between purely tool-based and purely compiler-based. The cmd/cover tool still does source-to-source rewriting, but it also generates information to be used by the compiler to do things like marking meta-data vars as read-only. In hybrid mode, the cmd/cover tool is invoked not on a single source file but on all the files in a package, and is passed a config file containing the import path of the package in question, along with other parameters needed for the run. It writes a series of modified files and an output config file to be passed to the compiler when compiling the modified files. Not completely useful by itself, still needs a corresponding set of changes in the Go command and in the compiler. Updates #51430. Change-Id: I0fcbd93a9a8fc25064187b159152486a2549ea54 Reviewed-on: https://go-review.googlesource.com/c/go/+/395896 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-08cmd/cover: use strings.Buildercuiweixie
Change-Id: Ifb51cb4ed98a93742ce4b221137a0ad73b939b06 Reviewed-on: https://go-review.googlesource.com/c/go/+/428286 Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Than McIntosh <thanm@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-02all: use os/exec instead of internal/execabsRuss Cox
We added internal/execabs back in January 2021 in order to fix a security problem caused by os/exec's handling of the current directory. Now that os/exec has that code, internal/execabs is superfluous and can be deleted. This commit rewrites all the imports back to os/exec and deletes internal/execabs. For #43724. Change-Id: Ib9736baf978be2afd42a1225e2ab3fd5d33d19df Reviewed-on: https://go-review.googlesource.com/c/go/+/381375 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-11-04cmd/cover: use fmt.Print for newline-ending fixed stringZvonimir Pavlinovic
This redundancy is now caught by the improved printf vet checker (golang/go#30436). Updates #49322 Change-Id: Id450247adc6fa28a9244c019be3c1b52c2d17f49 Reviewed-on: https://go-review.googlesource.com/c/go/+/361263 Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Zvonimir Pavlinovic <zpavlinovic@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-10-28cmd/compile: resolve the TODO of processPragmasLeonard Wang
Change-Id: Id723ecc2480aea2d8acb4d3e05db4a6c8eef9cc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/333109 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Cherry Mui <cherryyz@google.com>
2021-03-25cmd/cover: use golang.org/x/tools/cover directlyTobias Klauser
As suggested by Bryan in CL 249759, remove the forwarding aliases in cmd/cover and use the symbols from golang.org/x/tools directly. cmd/cover is not an importable package, so it is fine to remove these exported symbols. Change-Id: I887c5e9349f2dbe4c90be57f708412b844e18081 Reviewed-on: https://go-review.googlesource.com/c/go/+/304690 Trust: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-15all: run gofmtPrajwal Koirala
Fixes #44980 Change-Id: Icef35319d1582d8367c8911e15d11b0224957327 GitHub-Last-Rev: 2113e97e837c1ef5de9ba6a7bd62db92e644c500 GitHub-Pull-Request: golang/go#45005 Reviewed-on: https://go-review.googlesource.com/c/go/+/301632 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-03-14cmd/cover: replace code using optimized golang.org/x/tools/coverKoichi Shiraishi
After CL 179377, this change deletes all the prior cmd/cover code and instead vendors and type aliases code using the significantly optimized golang.org/x/tools/cover, which sped up ParseProfiles by manually parsing profiles instead of a regex. The speed up was: name old time/op new time/op delta ParseLine-12 2.43µs ± 2% 0.05µs ± 8% -97.98% (p=0.000 n=10+9) name old speed new speed delta ParseLine-12 42.5MB/s ± 2% 2103.2MB/s ± 7% +4853.14% (p=0.000 n=10+9) Fixes #32211. Change-Id: Ie4e8be7502f25eb95fae7a9d8334fc97b045d53f Reviewed-on: https://go-review.googlesource.com/c/go/+/249759 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-01-21all: introduce and use internal/execabsRoland Shoemaker
Introduces a wrapper around os/exec, internal/execabs, for use in all commands. This wrapper prevents exec.LookPath and exec.Command from running executables in the current directory. All imports of os/exec in non-test files in cmd/ are replaced with imports of internal/execabs. This issue was reported by RyotaK. Fixes CVE-2021-3115 Fixes #43783 Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/955304 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Katie Hockman <katiehockman@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/284783 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Katie Hockman <katie@golang.org> Trust: Roland Shoemaker <roland@golang.org>
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17all: replace Replace(..., -1) with ReplaceAll(...)Polina Osadcha
Change-Id: I8f7cff7a83a9c50bfa3331e8b40e4a6c2e1c0eee Reviewed-on: https://go-review.googlesource.com/c/go/+/245198 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2020-04-30cmd/cover: include a package name in the HTML titleRob Pike
A recent change added a title to the HTML coverage report but neglected to include the package name. Add the package name here. It's a little trickier than you'd think because there may be multiple packages and we don't want to parse the files, so we just extract a directory name from the path of the first file. This will almost always be right, and has the advantage that it gives a better result for package main. There are rare cases it will get wrong, but that will be no hardship. If this turns out not to be good enough, we can refine it. Fixes #38609 Change-Id: I2201f6caef906e0b0258b90d7de518879041fe72 Reviewed-on: https://go-review.googlesource.com/c/go/+/230517 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-20cmd/cover: add <title> tag to <head> for coverage report HTML templateDavid Carter
Adds a missing <title> tag to the HTML template to make it more compliant as <title> tags are generally required for valid HTML documents. Change-Id: I1ab2a6ee221c8a79d3cc13d9ac6110f6f4963914 GitHub-Last-Rev: 6d519dc9dda01d142e7f367e43e13c37896cc0cf GitHub-Pull-Request: golang/go#38313 Reviewed-on: https://go-review.googlesource.com/c/go/+/227547 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-13cmd/cover: skip function declarations with blank nameszikaeroh
Function declarations with blank ("_") names do not introduce a binding, and therefore cannot be referenced or executed (in fact, they do not make it into the final compiled binary at all). As such, counters defined while annotating their bodies will always be zero. These types of functions are commonly used to create compile-time checks (e.g., stringer) which are not expected to be executed. Skip over these functions when annotating a file, preventing the unused counters from being generated and appearing as uncovered lines in coverage reports. Fixes #36264 Change-Id: I6b516cf43c430a6248d68d5f483a3902253fbdab Reviewed-on: https://go-review.googlesource.com/c/go/+/223117 Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22syscall: respect permission bits on file opening on WindowsJason A. Donenfeld
On Windows, os.Chmod and syscall.Chmod toggle the FILE_ATTRIBUTES_ READONLY flag depending on the permission bits. That's a bit odd but I guess some compromises were made at some point and this is what was chosen to map to a Unix concept that Windows doesn't really have in the same way. That's fine. However, the logic used in Chmod was forgotten from os.Open and syscall.Open, which then manifested itself in various places, most recently, go modules' read-only behavior. This makes syscall.Open consistent with syscall.Chmod and adds a test for the permission _behavior_ using ioutil. By testing the behavior instead of explicitly testing for the attribute bits we care about, we make sure this doesn't regress in unforeseen ways in the future, as well as ensuring the test works on platforms other than Windows. In the process, we fix some tests that never worked and relied on broken behavior, as well as tests that were disabled on Windows due to the broken behavior and had TODO notes. Fixes #35033 Change-Id: I6f7cf54517cbe5f6b1678d1c24f2ab337edcc7f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/202439 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>