...

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

View as plain text