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

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

View as plain text