...

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

Documentation: cmd/go/testdata/script

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

View as plain text