...

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

Documentation: cmd/go/testdata/script

     1# The gotypesalias GODEBUG setting was introduced with Go 1.22 and removed
     2# with Go 1.27 but the GODEBUG behavior of the tool chain is independent of
     3# the module version; only the tool version matters (go.dev/issue/76163).
     4cp go.mod.20 go.mod
     5
     6# Go 1.20 must accept the removed GODEBUG gotypesalias with default value
     7go build -n godebugok.go
     8! stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
     9
    10# This also applies to go vet
    11go vet godebugok.go
    12! stderr .
    13
    14# Go 1.20 must not accept the removed GODEBUG gotypesalias with old value
    15! go build -n godebugold.go
    16stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    17
    18! go vet godebugold.go
    19stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    20
    21# If the GODEBUG setting is valid in the .mod file the build succeeds.
    22cp go.mod.20.godebugok go.mod
    23go build -n main.go
    24! stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    25
    26# In this case, setting an invalid value in the .go file leads to build failure.
    27! go build -n godebugold.go
    28stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    29
    30# If the GODEBUG setting is invalid in the .mod file the build fails.
    31cp go.mod.20.godebugold go.mod
    32! go build -n main.go
    33stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    34
    35# In this case, setting a valid value in the .go file does not remedy the failure.
    36! go build -n godebugok.go
    37stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    38
    39[short] skip
    40
    41# Using a removed GODEBUG with old value in the environment causes panic at startup.
    42cp go.mod.20 go.mod
    43env GODEBUG=gotypesalias=0
    44! go run printgodebug.go
    45stderr 'removed GODEBUG "gotypesalias" set to old value "0"'
    46
    47# Using a removed GODEBUG with default value in the environment is ok.
    48env GODEBUG=gotypesalias=1
    49go run printgodebug.go
    50stdout gotypesalias=1
    51
    52# Setting a removed GODEBUG with old value in the environment during runtime is not guarded against.
    53go run setgodebug.go
    54stdout gotypesalias=0
    55
    56-- go.mod.20 --
    57go 1.20
    58module m
    59
    60-- go.mod.20.godebugok --
    61go 1.20
    62module m
    63godebug gotypesalias=1
    64
    65-- go.mod.20.godebugold --
    66go 1.20
    67module m
    68godebug gotypesalias=0
    69
    70-- main.go --
    71package main
    72func main() {}
    73
    74-- godebugok.go --
    75//go:debug gotypesalias=1
    76
    77package main
    78func main() {}
    79
    80-- godebugold.go --
    81//go:debug gotypesalias=0
    82
    83package main
    84func main() {}
    85
    86-- printgodebug.go --
    87package main
    88
    89import "fmt"
    90import "os"
    91
    92func main() {
    93        fmt.Println(os.Getenv("GODEBUG"))
    94}
    95
    96-- setgodebug.go --
    97package main
    98
    99import "fmt"
   100import "os"
   101
   102func main() {
   103        os.Setenv("GODEBUG", "gotypesalias=0")
   104        fmt.Println(os.Getenv("GODEBUG"))
   105}

View as plain text