Go test Command

From NovaOrdis Knowledge Base
Revision as of 23:02, 8 January 2024 by Ovidiu (talk | contribs) (→‎Caching)
Jump to navigation Jump to search

Internal

Overview

The test command runs tests. The shared flags described here apply:

Shared Flags

For more details on testing, in general, see:

Go Testing

go test Execution Modes

The go test runs in two modes: local directory mode and package list mode.

Local Directory Mode

go test runs in local directory mode when it is invoked with no package argument. In this mode, go test compiles the package sources and tests found in the current directory, and then runs the resulting test binary. Caching is disabled. After the package test finishes (what if there are multiple packages?), the runtime print a summary line with the test status ('ok', 'FAIL', package name and elapsed time).

Package List Mode

go test runs in package list mode when go test is invoked with explicit package arguments (ex: go test math), with the ./... argument or even with .. In this mode the tool compiles and tests each of the packages listed on the command line. If the package test passes, the tool prints only the final 'ok' summary line. If it fails, the test prints a full test output. Successful package test results are cached to avoid unnecessary repeated running of the test.

Caching

The rule for a cache hit is that TODO.

Options

-args

-c

-exec xprog

-json

-o file