Black Lives Matter. Support the Equal Justice Initiative.

Text file src/cmd/go/testdata/script/generate.txt

Documentation: cmd/go/testdata/script

     1  [short] skip
     2  
     3  # Install an echo command because Windows doesn't have it.
     4  env GOBIN=$WORK/tmp/bin
     5  go install echo.go
     6  env PATH=$GOBIN${:}$PATH
     7  
     8  # Test go generate handles a simple command
     9  go generate ./generate/simple.go
    10  stdout 'Success'
    11  
    12  # Test go generate handles a command alias
    13  go generate './generate/alias.go'
    14  stdout 'Now is the time for all good men'
    15  
    16  # Test go generate's variable substitution
    17  go generate './generate/substitution.go'
    18  stdout $GOARCH' substitution.go:7 pabc xyzp/substitution.go/123'
    19  
    20  # Test go generate's run flag
    21  go generate -run y.s './generate/flag.go'
    22  stdout 'yes' # flag.go should select yes
    23  ! stdout 'no' # flag.go should not select no
    24  
    25  # Test go generate provides the right "$GOPACKAGE" name in an x_test
    26  go generate './generate/env_test.go'
    27  stdout 'main_test'
    28  
    29  # Test go generate provides the right "$PWD"
    30  go generate './generate/env_pwd.go'
    31  stdout $WORK'[/\\]gopath[/\\]src[/\\]generate'
    32  
    33  -- echo.go --
    34  package main
    35  
    36  import (
    37  	"fmt"
    38  	"os"
    39  	"strings"
    40  )
    41  
    42  func main() {
    43  	fmt.Println(strings.Join(os.Args[1:], " "))
    44  	fmt.Println()
    45  }
    46  -- generate/simple.go --
    47  // Copyright 2014 The Go Authors. All rights reserved.
    48  // Use of this source code is governed by a BSD-style
    49  // license that can be found in the LICENSE file.
    50  
    51  // Simple test for go generate.
    52  
    53  // We include a build tag that go generate should ignore.
    54  
    55  // +build ignore
    56  
    57  //go:generate echo Success
    58  
    59  package p
    60  -- generate/alias.go --
    61  // Copyright 2014 The Go Authors. All rights reserved.
    62  // Use of this source code is governed by a BSD-style
    63  // license that can be found in the LICENSE file.
    64  
    65  // Test that go generate handles command aliases.
    66  
    67  //go:generate -command run echo Now is the time
    68  //go:generate run for all good men
    69  
    70  package p
    71  -- generate/substitution.go --
    72  // Copyright 2014 The Go Authors. All rights reserved.
    73  // Use of this source code is governed by a BSD-style
    74  // license that can be found in the LICENSE file.
    75  
    76  // Test go generate variable substitution.
    77  
    78  //go:generate echo $GOARCH $GOFILE:$GOLINE ${GOPACKAGE}abc xyz$GOPACKAGE/$GOFILE/123
    79  
    80  package p
    81  -- generate/flag.go --
    82  // Copyright 2015 The Go Authors. All rights reserved.
    83  // Use of this source code is governed by a BSD-style
    84  // license that can be found in the LICENSE file.
    85  
    86  // Test -run flag
    87  
    88  //go:generate echo oh yes my man
    89  //go:generate echo no, no, a thousand times no
    90  
    91  package p
    92  -- generate/env_test.go --
    93  package main_test
    94  
    95  //go:generate echo $GOPACKAGE
    96  -- generate/env_pwd.go --
    97  package p
    98  
    99  //go:generate echo $PWD
   100  

View as plain text