...

Source file src/cmd/go/go_windows_test.go

Documentation: cmd/go

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main_test
     6  
     7  import (
     8  	"internal/testenv"
     9  	"os"
    10  	"path/filepath"
    11  	"strings"
    12  	"testing"
    13  
    14  	"cmd/go/internal/robustio"
    15  )
    16  
    17  func TestAbsolutePath(t *testing.T) {
    18  	tg := testgo(t)
    19  	defer tg.cleanup()
    20  	tg.parallel()
    21  
    22  	tmp, err := os.MkdirTemp("", "TestAbsolutePath")
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  	defer robustio.RemoveAll(tmp)
    27  
    28  	file := filepath.Join(tmp, "a.go")
    29  	err = os.WriteFile(file, []byte{}, 0644)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	dir := filepath.Join(tmp, "dir")
    34  	err = os.Mkdir(dir, 0777)
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  
    39  	noVolume := file[len(filepath.VolumeName(file)):]
    40  	wrongPath := filepath.Join(dir, noVolume)
    41  	cmd := testenv.Command(t, tg.goTool(), "build", noVolume)
    42  	cmd.Dir = dir
    43  	output, err := cmd.CombinedOutput()
    44  	if err == nil {
    45  		t.Fatal("build should fail")
    46  	}
    47  	if strings.Contains(string(output), wrongPath) {
    48  		t.Fatalf("wrong output found: %v %v", err, string(output))
    49  	}
    50  }
    51  

View as plain text