...

Source file src/github.com/rogpeppe/go-internal/cmd/testscript/help.go

Documentation: github.com/rogpeppe/go-internal/cmd/testscript

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  )
     7  
     8  func mainUsage(f io.Writer) {
     9  	fmt.Fprint(f, mainHelp)
    10  }
    11  
    12  var mainHelp = `
    13  The testscript command runs github.com/rogpeppe/go-internal/testscript scripts
    14  in a fresh temporary work directory tree.
    15  
    16  Usage:
    17      testscript [-v] [-e VAR[=value]]... [-u] [-continue] [-work] files...
    18  
    19  The testscript command is designed to make it easy to create self-contained
    20  reproductions of command sequences.
    21  
    22  Each file is opened as a script and run as described in the documentation for
    23  github.com/rogpeppe/go-internal/testscript. The special filename "-" is
    24  interpreted as the standard input.
    25  
    26  As a special case, supporting files/directories in the .gomodproxy subdirectory
    27  will be served via a github.com/rogpeppe/go-internal/goproxytest server which
    28  is available to each script via the GOPROXY environment variable. The contents
    29  of the .gomodproxy subdirectory are not available to the script except via the
    30  proxy server. See the documentation for
    31  github.com/rogpeppe/go-internal/goproxytest for details on the format of these
    32  files/directories.
    33  
    34  Environment variables can be passed through to each script with the -e flag,
    35  where VAR is the name of the variable. Variables override testscript-defined
    36  values, with the exception of WORK which cannot be overridden. The -e flag can
    37  appear multiple times to specify multiple variables.
    38  
    39  The -u flag specifies that if a cmp command within a testscript fails and its
    40  second argument refers to a file inside the testscript file, the command will
    41  succeed and the testscript file will be updated to reflect the actual content.
    42  As such, this is the cmd/testcript equivalent of
    43  testscript.Params.UpdateScripts.
    44  
    45  The -continue flag specifies that if an error occurs, the script will continue running.
    46  All errors will be printed and the exit status will be false.
    47  
    48  The -work flag prints the temporary work directory path before running each
    49  script, and does not remove that directory when testscript exits.
    50  
    51  Examples
    52  ========
    53  
    54  The following example, fruit.txtar, shows a simple reproduction that includes
    55  .gomodproxy supporting files:
    56  
    57      go get -m fruit.com
    58      go list fruit.com/...
    59      stdout 'fruit.com/fruit'
    60  
    61      -- go.mod --
    62      module mod
    63  
    64      -- .gomodproxy/fruit.com_v1.0.0/.mod --
    65      module fruit.com
    66  
    67      -- .gomodproxy/fruit.com_v1.0.0/.info --
    68      {"Version":"v1.0.0","Time":"2018-10-22T18:45:39Z"}
    69  
    70      -- .gomodproxy/fruit.com_v1.0.0/fruit/fruit.go --
    71      package fruit
    72  
    73      const Name = "Apple"
    74  
    75  Running testscript -v fruit.txtar we get:
    76  
    77      ...
    78      > go get -m fruit.com
    79      [stderr]
    80      go: finding fruit.com v1.0.0
    81  
    82      > go list fruit.com/...
    83      [stdout]
    84      fruit.com/fruit
    85  
    86      [stderr]
    87      go: downloading fruit.com v1.0.0
    88  
    89      > stdout 'fruit.com/fruit'
    90      PASS
    91  
    92  
    93  The following example, goimports.txtar, shows a simple reproduction involving
    94  goimports:
    95  
    96      go install golang.org/x/tools/cmd/goimports
    97  
    98      # check goimports help information
    99      exec goimports -d main.go
   100      stdout 'import "math"'
   101  
   102      -- go.mod --
   103      module mod
   104  
   105      require golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372
   106  
   107      -- main.go --
   108      package mod
   109  
   110      const Pi = math.Pi
   111  
   112  Running testscript -v goimports.txtar we get:
   113  
   114      ...
   115      > go install golang.org/x/tools/cmd/goimports
   116      [stderr]
   117      go: finding golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372
   118      go: downloading golang.org/x/tools v0.0.0-20181221235234-d00ac6d27372
   119  
   120      # check goimports help information (0.015s)
   121      > exec goimports -d main.go
   122      [stdout]
   123      diff -u main.go.orig main.go
   124      --- main.go.orig        2019-01-08 16:03:35.861907738 +0000
   125      +++ main.go     2019-01-08 16:03:35.861907738 +0000
   126      @@ -1,3 +1,5 @@
   127       package mod
   128  
   129      +import "math"
   130      +
   131       const Pi = math.Pi
   132      > stdout 'import "math"'
   133      PASS
   134  `[1:]
   135  

View as plain text