...

Text file src/golang.org/x/exp/cmd/gorelease/testdata/README.md

Documentation: golang.org/x/exp/cmd/gorelease/testdata

     1This directory contains most tests for gorelease. Each test runs gorelease (the
     2`runRelease` function) with a given set of flags in a temporary directory
     3populated with files specified in the test itself or files from the module test
     4proxy. The output is compared against a golden `want` file specified in the
     5test.
     6
     7## Test flags
     8
     9A specific test may be run with a command like:
    10
    11    go test -run=TestRelease/basic/v0_patch_suggest
    12
    13where `basic/v0_patch_suggest` matches the file
    14`testdata/basic/v0_patch_suggest.test`.
    15
    16The `-u` flag adds or updates the `want` file in each test to match the output.
    17This is useful for fixing tests after an intended change in behavior.
    18
    19    go test -run=TestRelease/basic/v0_patch_suggest -u
    20
    21The `-testwork` flag instructs the test framework to leave the test's temporary
    22directory and module proxy in place after running the test. This is useful
    23for debugging.
    24
    25## Test format
    26
    27Tests are written in `.test` files in `testdata` subdirectories. Each `.test`
    28file is a valid txtar file (see `golang.org/x/tools/txtar`). The comment section
    29contains the test parameters, which are a series of `key=value` pairs. Blank
    30lines and comments starting with `#` are allowed in this section. Valid keys
    31are:
    32
    33* `mod`: sets the module path. Must be specified together with `version`. Copies
    34  the content of a module out of the test proxy into a temporary directory
    35  where `gorelease` is run.
    36* `version`: specified together with `mod`, it sets the version to retrieve from
    37  the test proxy. See more information below.
    38* `base`: the value of the `-base` flag passed to `gorelease`.
    39* `release`: the value of the `-version` flag passed to `gorelease`.
    40* `dir`: the directory where `gorelease` should be invoked. Useful when the test
    41  describes a whole repository, and `gorelease` should be invoked in a
    42  subdirectory.
    43* `error`: true if the test expects a hard error. False by default.
    44* `success`: true if the test expects a report to be printed with no errors
    45  or diagnostics. True by default.
    46* `skip`: non-empty if the test should be skipped. The value is a string passed
    47  to `t.Skip`.
    48* `proxyVersions`: empty if the test should include all `mod/` entries in the
    49  proxy, or else a comma-separated list of the modpath@version's it should
    50  include.
    51
    52Test archives have a file named `want`, containing the expected output of the
    53test. A test will fail if the actual output differs from `want`.
    54
    55If the `mod` and `version` parameters are not set, other files will be extracted
    56to the temporary directory where `gorelease` runs.
    57
    58## Populating module contents
    59
    60When building a test in `testdata/`, there are two ways to populate the module
    61directory being tested:
    62
    63### Option 1: inline
    64
    65You can inline files in the `.test` folder as described in
    66https://pkg.go.dev/golang.org/x/tools/txtar#hdr-Txtar_format. For example,
    67
    68```
    69-- some.file --
    70the contents
    71of the file
    72```
    73
    74### Option 2: specify an existing file
    75
    76Often, multiple tests want to share the same setup - the same files. So, users
    77can write these common files in `testdata/mod/`, and use one of these files as
    78the module directory contents.
    79
    80To specify a file in `testdata/mod/` to use as the module contents.
    81
    82## Module format
    83
    84Tests run with `GOPROXY` set to a local URL that points to a test proxy. The
    85test proxy serves modules described by `.txt` files in the `testdata/mod/`
    86subdirectory.
    87
    88Each module is a txtar archive named `$modpath_$version.txt` where `$modpath`
    89is the module path (with slashes replaced with underscores) and `$version` is
    90the version. If the archive contains a file named `.mod`, that will be used to
    91respond to `.mod` requests; otherwise, `go.mod` will be used (`.mod` is only
    92necessary for modules that lack `go.mod` files). If the archive contains a
    93file named `.info`, that will be used to respond to `.info` requests; otherwise,
    94`.info` is synthesized from the version. All other files in the archive are
    95packed into a `.zip` file to satisfy `.zip` requests.

View as plain text