...

Text file src/cmd/go/testdata/script/generate_invalid.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 for directory with no go files
     9! go generate ./nogo
    10! stdout 'Fail'
    11stderr 'no Go files'
    12
    13# Test go  generate for module which doesn't exist should fail
    14! go generate foo.bar/nothing
    15stderr 'no required module provides package foo.bar/nothing'
    16
    17# Test go generate for package where all .go files are excluded by build
    18# constraints
    19go generate -v ./excluded
    20! stdout 'Fail'
    21! stderr 'go' # -v shouldn't list any files
    22
    23# Test go generate for "package" with no package clause in any file
    24go generate ./nopkg
    25stdout 'Success a'
    26! stdout 'Fail'
    27
    28# Test go generate for package with inconsistent package clauses
    29# $GOPACKAGE should depend on each file's package clause
    30go generate ./inconsistent
    31stdout 'Success a'
    32stdout 'Success b'
    33stdout -count=2 'Success c'
    34! stdout 'Fail'
    35
    36# Test go generate for syntax errors before and after package clauses
    37go generate ./syntax
    38stdout 'Success a'
    39stdout 'Success b'
    40! stdout 'Fail'
    41
    42# Test go generate for files importing non-existent packages
    43go generate ./importerr
    44stdout 'Success a'
    45stdout 'Success b'
    46stdout 'Success c'
    47
    48-- echo.go --
    49package main
    50
    51import (
    52	"fmt"
    53	"os"
    54	"strings"
    55)
    56
    57func main() {
    58	fmt.Println(strings.Join(os.Args[1:], " "))
    59	fmt.Println()
    60}
    61
    62-- go.mod --
    63module m
    64
    65go 1.16
    66-- nogo/foo.txt --
    67Text file in a directory without go files.
    68Go generate should ignore this directory.
    69//go:generate echo Fail nogo
    70
    71-- excluded/a.go --
    72// Include a build tag that go generate should exclude.
    73// Go generate should ignore this file.
    74
    75// +build a
    76
    77//go:generate echo Fail a
    78
    79package excluded
    80
    81-- excluded/b.go --
    82// Include a build tag that go generate should exclude.
    83// Go generate should ignore this file.
    84
    85//go:generate echo Fail b
    86
    87// +build b
    88
    89package excluded
    90
    91
    92-- nopkg/a.go --
    93// Go file with package clause after comment.
    94// Go generate should process this file.
    95
    96/* Pre-comment */ package nopkg
    97//go:generate echo Success a
    98
    99-- nopkg/b.go --
   100// Go file with commented package clause.
   101// Go generate should ignore this file.
   102
   103//package nopkg
   104
   105//go:generate echo Fail b
   106
   107-- nopkg/c.go --
   108// Go file with package clause inside multiline comment.
   109// Go generate should ignore this file.
   110
   111/*
   112package nopkg
   113*/
   114
   115//go:generate echo Fail c
   116
   117-- nopkg/d.go --
   118// Go file with package clause inside raw string literal.
   119// Go generate should ignore this file.
   120
   121const foo = `
   122package nopkg
   123`
   124//go:generate echo Fail d
   125
   126-- nopkg/e.go --
   127// Go file without package clause.
   128// Go generate should ignore this file.
   129
   130//go:generate echo Fail e
   131
   132-- inconsistent/a.go --
   133// Valid go file with inconsistent package name.
   134// Go generate should process this file with GOPACKAGE=a
   135
   136package a
   137//go:generate echo Success $GOPACKAGE
   138
   139-- inconsistent/b.go --
   140// Valid go file with inconsistent package name.
   141// Go generate should process this file with GOPACKAGE=b
   142
   143//go:generate echo Success $GOPACKAGE
   144package b
   145
   146-- inconsistent/c.go --
   147// Go file with two package clauses.
   148// Go generate should process this file with GOPACKAGE=c
   149
   150//go:generate echo Success $GOPACKAGE
   151package c
   152// Invalid package clause, should be ignored:
   153package cinvalid
   154//go:generate echo Success $GOPACKAGE
   155
   156-- inconsistent/d.go --
   157// Go file with invalid package name.
   158// Go generate should ignore this file.
   159
   160package +d+
   161//go:generate echo Fail $GOPACKAGE
   162
   163-- syntax/a.go --
   164// Go file with syntax error after package clause.
   165// Go generate should process this file.
   166
   167package syntax
   168123
   169//go:generate echo Success a
   170
   171-- syntax/b.go --
   172// Go file with syntax error after package clause.
   173// Go generate should process this file.
   174
   175package syntax; 123
   176//go:generate echo Success b
   177
   178-- syntax/c.go --
   179// Go file with syntax error before package clause.
   180// Go generate should ignore this file.
   181
   182foo
   183package syntax
   184//go:generate echo Fail c
   185
   186-- importerr/a.go --
   187// Go file which imports non-existing package.
   188// Go generate should process this file.
   189
   190package importerr
   191//go:generate echo Success a
   192import "foo"
   193
   194-- importerr/b.go --
   195// Go file which imports non-existing package.
   196// Go generate should process this file.
   197
   198//go:generate echo Success b
   199package importerr
   200import "bar"
   201
   202-- importerr/c.go --
   203// Go file which imports non-existing package.
   204// Go generate should process this file.
   205
   206package importerr
   207import "moo"
   208//go:generate echo Success c

View as plain text