golang.org/toolchain@v0.0.1-go1.9rc2.windows-amd64/src/cmd/go/go_windows_test.go (about)

     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
     6  
     7  import (
     8  	"internal/testenv"
     9  	"io/ioutil"
    10  	"os"
    11  	"os/exec"
    12  	"path/filepath"
    13  	"strings"
    14  	"testing"
    15  )
    16  
    17  func TestAbsolutePath(t *testing.T) {
    18  	tmp, err := ioutil.TempDir("", "TestAbsolutePath")
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	defer os.RemoveAll(tmp)
    23  
    24  	file := filepath.Join(tmp, "a.go")
    25  	err = ioutil.WriteFile(file, []byte{}, 0644)
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  	dir := filepath.Join(tmp, "dir")
    30  	err = os.Mkdir(dir, 0777)
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	wd, err := os.Getwd()
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	defer os.Chdir(wd)
    40  
    41  	// Chdir so current directory and a.go reside on the same drive.
    42  	err = os.Chdir(dir)
    43  	if err != nil {
    44  		t.Fatal(err)
    45  	}
    46  
    47  	noVolume := file[len(filepath.VolumeName(file)):]
    48  	wrongPath := filepath.Join(dir, noVolume)
    49  	output, err := exec.Command(testenv.GoToolPath(t), "build", noVolume).CombinedOutput()
    50  	if err == nil {
    51  		t.Fatal("build should fail")
    52  	}
    53  	if strings.Contains(string(output), wrongPath) {
    54  		t.Fatalf("wrong output found: %v %v", err, string(output))
    55  	}
    56  }