go go_windows_test 源码

  • 2022-07-15
  • 浏览 (966)

golang go_windows_test 代码

文件路径:/src/cmd/go/go_windows_test.go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main_test

import (
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"

	"cmd/go/internal/robustio"
)

func TestAbsolutePath(t *testing.T) {
	tg := testgo(t)
	defer tg.cleanup()
	tg.parallel()

	tmp, err := os.MkdirTemp("", "TestAbsolutePath")
	if err != nil {
		t.Fatal(err)
	}
	defer robustio.RemoveAll(tmp)

	file := filepath.Join(tmp, "a.go")
	err = os.WriteFile(file, []byte{}, 0644)
	if err != nil {
		t.Fatal(err)
	}
	dir := filepath.Join(tmp, "dir")
	err = os.Mkdir(dir, 0777)
	if err != nil {
		t.Fatal(err)
	}

	noVolume := file[len(filepath.VolumeName(file)):]
	wrongPath := filepath.Join(dir, noVolume)
	cmd := exec.Command(tg.goTool(), "build", noVolume)
	cmd.Dir = dir
	output, err := cmd.CombinedOutput()
	if err == nil {
		t.Fatal("build should fail")
	}
	if strings.Contains(string(output), wrongPath) {
		t.Fatalf("wrong output found: %v %v", err, string(output))
	}
}

相关信息

go 源码目录

相关文章

go alldocs 源码

go export_test 源码

go go11 源码

go go_boring_test 源码

go go_test 源码

go go_unix_test 源码

go help_test 源码

go init_test 源码

go main 源码

go note_test 源码

0  赞