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

     1  # Check that files and their imports are not included in 'go list' output
     2  # when they are excluded by build constraints.
     3  
     4  # Linux and cgo files should be included when building in that configuration.
     5  env GOOS=linux
     6  env GOARCH=amd64
     7  env CGO_ENABLED=1
     8  go list -f '{{range .GoFiles}}{{.}} {{end}}'
     9  stdout '^cgotag.go empty.go suffix_linux.go tag.go $'
    10  go list -f '{{range .CgoFiles}}{{.}} {{end}}'
    11  stdout '^cgoimport.go $'
    12  go list -f '{{range .Imports}}{{.}} {{end}}'
    13  stdout '^C cgoimport cgotag suffix tag $'
    14  
    15  # Disabling cgo should exclude cgo files and their imports.
    16  env CGO_ENABLED=0
    17  go list -f '{{range .GoFiles}}{{.}} {{end}}'
    18  stdout 'empty.go suffix_linux.go tag.go'
    19  go list -f '{{range .CgoFiles}}{{.}} {{end}}'
    20  ! stdout .
    21  go list -f '{{range .Imports}}{{.}} {{end}}'
    22  stdout '^suffix tag $'
    23  
    24  # Changing OS should exclude linux sources.
    25  env GOOS=darwin
    26  go list -f '{{range .GoFiles}}{{.}} {{end}}'
    27  stdout '^empty.go $'
    28  go list -f '{{range .Imports}}{{.}} {{end}}'
    29  stdout '^$'
    30  
    31  # Enabling a tag should include files that require it.
    32  go list -tags=extra -f '{{range .GoFiles}}{{.}} {{end}}'
    33  stdout '^empty.go extra.go $'
    34  go list -tags=extra -f '{{range .Imports}}{{.}} {{end}}'
    35  stdout '^extra $'
    36  
    37  # Packages that require a tag should not be listed unless the tag is on.
    38  ! go list ./tagonly
    39  go list -tags=extra ./tagonly
    40  stdout m/tagonly
    41  
    42  -- go.mod --
    43  module m
    44  
    45  go 1.13
    46  
    47  -- empty.go --
    48  package p
    49  
    50  -- extra.go --
    51  // +build extra
    52  
    53  package p
    54  
    55  import _ "extra"
    56  
    57  -- suffix_linux.go --
    58  package p
    59  
    60  import _ "suffix"
    61  
    62  -- tag.go --
    63  // +build linux
    64  
    65  package p
    66  
    67  import _ "tag"
    68  
    69  -- cgotag.go --
    70  // +build cgo
    71  
    72  package p
    73  
    74  import _ "cgotag"
    75  
    76  -- cgoimport.go --
    77  package p
    78  
    79  import "C"
    80  
    81  import _ "cgoimport"
    82  
    83  -- tagonly/tagonly.go --
    84  // +build extra
    85  
    86  package tagonly
    87  

View as plain text