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

     1  [short] skip 'builds and runs go programs'
     2  [!symlink] skip 'uses symlinks to construct a GOROOT'
     3  
     4  env NEWGOROOT=$WORK${/}goroot
     5  env TOOLDIR=$GOROOT/pkg/tool/${GOOS}_${GOARCH}
     6  # Use ${/} in paths we'll check for in stdout below, so they contain '\' on Windows
     7  env NEWTOOLDIR=$NEWGOROOT${/}pkg${/}tool${/}${GOOS}_${GOARCH}
     8  mkdir $NEWGOROOT $NEWGOROOT/bin $NEWTOOLDIR
     9  [symlink] symlink $NEWGOROOT/src -> $GOROOT/src
    10  [symlink] symlink $NEWGOROOT/pkg/include -> $GOROOT/pkg/include
    11  [symlink] symlink $NEWGOROOT/bin/go -> $GOROOT/bin/go
    12  [symlink] symlink $NEWTOOLDIR/compile$GOEXE -> $TOOLDIR/compile$GOEXE
    13  [symlink] symlink $NEWTOOLDIR/cgo$GOEXE -> $TOOLDIR/cgo$GOEXE
    14  [symlink] symlink $NEWTOOLDIR/link$GOEXE -> $TOOLDIR/link$GOEXE
    15  [symlink] symlink $NEWTOOLDIR/asm$GOEXE -> $TOOLDIR/asm$GOEXE
    16  [symlink] symlink $NEWTOOLDIR/pack$GOEXE -> $TOOLDIR/pack$GOEXE
    17  env GOROOT=$NEWGOROOT
    18  env TOOLDIR=$NEWTOOLDIR
    19  
    20  # GOROOT without test2json tool builds and runs it as needed
    21  go env GOROOT
    22  ! exists $TOOLDIR/test2json
    23  go tool test2json
    24  stdout '{"Action":"start"}'
    25  ! exists $TOOLDIR/test2json$GOEXE
    26  go tool -n test2json
    27  ! stdout $NEWTOOLDIR${/}test2json$GOEXE
    28  
    29  # GOROOT with test2json uses the test2json in the GOROOT
    30  go install cmd/test2json
    31  exists $TOOLDIR/test2json$GOEXE
    32  go tool test2json
    33  stdout '{"Action":"start"}'
    34  go tool -n test2json
    35  stdout $NEWTOOLDIR${/}test2json$GOEXE
    36  
    37  # Tool still runs properly even with wrong GOOS/GOARCH
    38  # Remove test2json from tooldir
    39  rm $TOOLDIR/test2json$GOEXE
    40  go tool -n test2json
    41  ! stdout $NEWTOOLDIR${/}test2json$GOEXE
    42  # Set GOOS/GOARCH to different values than host GOOS/GOARCH.
    43  env GOOS=windows
    44  [GOOS:windows] env GOOS=linux
    45  env GOARCH=arm64
    46  [GOARCH:arm64] env GOARCH=amd64
    47  # Control case: go run shouldn't work because it respects
    48  # GOOS/GOARCH, and we can't execute non-native binary.
    49  ! go run cmd/test2json -exec=''
    50  # But go tool should because it doesn't respect GOOS/GOARCH.
    51  go tool test2json
    52  stdout '{"Action":"start"}'
    53  

View as plain text