小编Sri*_*sam的帖子

TestMain - 没有要运行的测试

我正在编写一个包,它编译 C 源文件并将输出写入另一个文件。我正在为这个包编写测试,我需要创建一个临时目录来写入输出文件。我正在使用TestMain函数来执行此操作。由于某种原因,当我刚刚运行测试时,我总是收到警告“没有要运行的测试” TestMain。我尝试调试该TestMain函数,可以看到临时目录确实已创建。当我手动创建testoutput目录时,所有测试都通过。

我正在从testdata目录加载两个 C 源文件,其中之一是故意错误的。

海湾合作委员会.go:

package gcc

import (
    "os/exec"
)

func Compile(inPath, outPath string) error {
    cmd := exec.Command("gcc", inPath, "-o", outPath)
    return cmd.Run()
}
Run Code Online (Sandbox Code Playgroud)

gcc_test.go:

package gcc

import (
    "os"
    "path/filepath"
    "testing"
)

func TestOuputFileCreated(t *testing.T) {
    var inFile = filepath.Join("testdata", "correct.c")
    var outFile = filepath.Join("testoutput", "correct_out")

    if err := Compile(inFile, outFile); err != nil {
        t.Errorf("Expected err to be nil, got %s", err.Error())
    }

    if …
Run Code Online (Sandbox Code Playgroud)

testing go

3
推荐指数
1
解决办法
9953
查看次数

标签 统计

go ×1

testing ×1