test: improve finding goroot

This commit is contained in:
Reinaldy Rafli 2021-10-27 23:50:22 +07:00
parent 8df9913bb7
commit 198cc25b37
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
1 changed files with 3 additions and 9 deletions

View File

@ -3,8 +3,7 @@ package decrr_test
import ( import (
"errors" "errors"
"os" "os"
"os/exec" "runtime"
"strings"
"testing" "testing"
"github.com/aldy505/decrr" "github.com/aldy505/decrr"
@ -15,16 +14,11 @@ func TestWrap(t *testing.T) {
w := decrr.Wrap(x) w := decrr.Wrap(x)
wd, _ := os.Getwd() wd, _ := os.Getwd()
cmd, err := exec.Command("bash", "-c", "go env | grep GOROOT").CombinedOutput() gt := runtime.GOROOT()
if err != nil {
t.Error(err)
}
gt := strings.Replace(strings.Replace(strings.Replace(string(cmd), "GOROOT=", "", 1), "\"", "", 2), "\n", "", -1)
var expected string var expected string
expected += "why does a chicken cross the road?\n\n" expected += "why does a chicken cross the road?\n\n"
expected += "github.com/aldy505/decrr_test.TestWrap " + wd + "/decrr_test.go:15\n" expected += "github.com/aldy505/decrr_test.TestWrap " + wd + "/decrr_test.go:14\n"
expected += "testing.tRunner " + gt + "/src/testing/testing.go:1259\n" expected += "testing.tRunner " + gt + "/src/testing/testing.go:1259\n"
expected += "runtime.goexit " + gt + "/src/runtime/asm_amd64.s:1581" expected += "runtime.goexit " + gt + "/src/runtime/asm_amd64.s:1581"